![]() |
|
|
#56 | |
|
"Ben"
Feb 2007
3×1,171 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. |
|
|
|
|
|
|
#57 | |
|
Mar 2010
Brick, NJ
67 Posts |
Quote:
YOUR SIEVE IS A BEAST I NOMINATE THE NAME THE SIEVE OF BUHROWCOM 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. |
|
|
|
|
|
|
#58 |
|
Aug 2006
3·1,993 Posts |
|
|
|
|
|
|
#59 | |
|
"Ben"
Feb 2007
3×1,171 Posts |
Quote:
, 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.
|
|
|
|
|
|
|
#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 mutli-threaded 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 2010-04-10 at 19:44 Reason: add code block |
|
|
|
|
|
#61 | ||
|
Aug 2006
3·1,993 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. |
||
|
|
|
|
|
#62 |
|
Mar 2010
Brick, NJ
67 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 |
|
|
|
|
|
#63 |
|
Dec 2008
15018 Posts |
|
|
|
|
|
|
#64 |
|
"Ben"
Feb 2007
3·1,171 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 **** |
|
|
|
|
|
#65 |
|
"Richard B. Woods"
Aug 2002
Wisconsin USA
170148 Posts |
|
|
|
|
|
|
#66 |
|
"Lucan"
Dec 2006
England
2×3×13×83 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 |
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Regarding Squares | a1call | Miscellaneous Math | 42 | 2017-02-03 01:29 |
| Basic Number Theory 12: sums of two squares | Nick | Number Theory Discussion Group | 0 | 2016-12-11 11:30 |
| Integers = sums of 2s and 3s. | 3.14159 | Miscellaneous Math | 12 | 2010-07-21 11:47 |
| Sums of three squares | CRGreathouse | Math | 6 | 2009-11-06 19:20 |
| squares or not squares | m_f_h | Puzzles | 45 | 2007-06-15 17:46 |