20100410, 15:59  #56  
"Ben"
Feb 2007
3,343 Posts 
Quote:
As you've seen, pointers are used abundantly and I employ all sorts of C hacks like casting void pointers and adding pointer values. Not sure if equivalent code is possible in VB. It may have been easier to package the existing C code as a .dll library for use in a VB program. 

20100410, 16:25  #57  
Mar 2010
Brick, NJ
67 Posts 
Quote:
YOUR SIEVE IS A BEAST I NOMINATE THE NAME THE SIEVE OF BUHROW COM Interop on windows is quite a drag on performance. I current use a LIBGMP wrapper and just for i=0 to 100000000 takes several minutes. Actually comparing c/c++/vb performance is quite comparable when dealing with 32 bit words. 16 and 64 may be slightly slower and perhaps the bounds checking performed under the hood would be another performance hit, but nothing compared to the cost of com calls. Hopefully someone with VS will take a look and give it a shot. I can upload and entire project file. It would simply be a matter of stepping though each program. I mean their almost exact line for line. FYI, tiny_soe works perfect but then again that is a pretty simple implementation. spSOE fails, first reporting 121 as prime. 

20100410, 17:19  #58 
Aug 2006
2·2,969 Posts 

20100410, 18:34  #59 
"Ben"
Feb 2007
3,343 Posts 
I'm flattered , but at the end of the day its just another sieve of Eratosthenes. The best that can be said about it is that it uses some optimizations that perhaps haven't been implemented before. Even so, in all but very special cases it isn't even the fastest SOE... ecprime fills those shoes.

20100410, 19:43  #60 
Mar 2010
Brick, NJ
67 Posts 
While it may be entirely more effecient for larger input and the theory behind it can be quite complex, it is indeed a relatively simple modification compared to the one implement in Yafu.
Compare this mutlithreaded sieve to the code in the previous thread Code:
Private Shared Sub ParralleSieve(x as Integer) Dim xx = x * x For y As Integer = 1 To sqrt Dim yy = y * y Dim n = 4 * xx + yy If n <= max AndAlso (n Mod 12 = 1 OrElse n Mod 12 = 5) Then isPrime(n) = Not isPrime(n) End If n = 3 * xx + yy If n <= max AndAlso n Mod 12 = 7 Then isPrime(n) = Not isPrime(n) End If n = 3 * xx  yy If x > y AndAlso n <= max AndAlso n Mod 12 = 11 Then isPrime(n) = Not isPrime(n) End If Next End Sub Private Shared Function SieveOfAtkins(ByVal max As Integer) As List(Of Integer) Dim isPrime = New BitArray(CInt(max) + 1, False) Dim sqrt = CInt(Math.Sqrt(max)) Parallel.[For](1, sqrt, AddressOf ParrallelSieve) Dim primes = New List(Of Integer)() For n As Integer = 5 To sqrt If isPrime(n) Then primes.Add(n) Dim nn As Integer = n * n Dim k As Integer = nn While k <= max isPrime(k) = False k += nn End While End If Next For n As Integer = sqrt + 1 To max If isPrime(n) Then primes.Add(n) End If Next Return primes End Function Last fiddled with by alexhiggins732 on 20100410 at 19:44 Reason: add code block 
20100410, 20:19  #61  
Aug 2006
2·2,969 Posts 
Quote:
Quote:
The second is not difficult, but the first one takes real magic. By omitting that part you do a great disservice to the inventors of the sieve, Bernstein and Atkin. But if you think that implementation tricks are what make the algorithm, then you should see Bernstein's implementation. Also: the name is Atkin, not Atkins. 

20100410, 21:07  #62 
Mar 2010
Brick, NJ
43_{16} Posts 
I concur, it is indeed a great sieve indeed and there are many implementations of it out there. For those interested here is the theory behind it and other sieves.
http://cr.yp.to/papers/primesieves.pdf 
20100410, 21:38  #63 
Dec 2008
830_{10} Posts 

20100412, 00:55  #64 
"Ben"
Feb 2007
3,343 Posts 
I've now completed the sum of each sequence (primes, prime squares, and prime cubes) up to 1e14, and found the 12th member of the cube sequence:
Code:
**** 1000000000000 divides prime cube sum up to 33777547344991, sum is 10532010356822624092227361649102207021134000000000000 **** 
20100412, 15:02  #65 
"Richard B. Woods"
Aug 2002
Wisconsin USA
2^{2}×3×599 Posts 

20100412, 16:38  #66 
"Lucan"
Dec 2006
England
6,451 Posts 
I thought a calory was 4.2 Joule, but nutritionists use
the term to refer to a kilocalory. I don't think there are different types for different foods. Even the "type of energy" it measures is the same for everything. David 
Thread Tools  
Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Regarding Squares  a1call  Miscellaneous Math  42  20170203 01:29 
Basic Number Theory 12: sums of two squares  Nick  Number Theory Discussion Group  0  20161211 11:30 
Integers = sums of 2s and 3s.  3.14159  Miscellaneous Math  12  20100721 11:47 
Sums of three squares  CRGreathouse  Math  6  20091106 19:20 
squares or not squares  m_f_h  Puzzles  45  20070615 17:46 