If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Seive of Atkin

First, use proper indentations withing the code snippet. Otherwise it is almost impossible to read/understand it.
Second, what is this code for and why do you want to enhance it?
Third, to make code "bug free" you have to design it good enough, then to debug and test it good enough.
To make it efficient enough you first have to find out what part(s) of it take(s) to longest time(s).

Re: Seive of Atkin

There are other compile time problems apart from the one highlighted by Paul in post #4. Also, if you correct the compile problems there is then a run-time error of an unknown exception produced for the provided limit. From where did you obtain this **** code?

Like its gotta be bug free

It's definitely not!

What is your requirement for prime numbers - as this topic has been covered several times on these forums.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: Seive of Atkin

I don't know how fast this Sieve Of Atkin program is supposed to be for generating prime numbers, but on my 2.4Ghz system my program generates prime numbers up to 10000000 in just under 5 seconds with a further 7 seconds to write all 664579 primes to a file.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: Seive of Atkin

Originally Posted by rockx

so 2kaud, does ur program calculate prime numbers which has over 500 digits? i mean the really large ones?

if so, could you please share the code

No it doesn't. Neither does the program you posted in post #1. The limit of the posted program is the size of the arrays that can be created on the stack (although the program could be changed to create them on the heap which would then have a maximum limit of the size of an unsigned int - but the posted program doesn't work properly anyhow). My prime program has the same limitation - max 4294967295.

It would probably be possible to use type _UI64 (max 18446744073709551615) or possibly even type _UI128. But these wouldn't provide you with your requirement to calculate prime numbers which have over 500 digits.

If you want to do things like this, you really, really need to use a proper large number library (and not my simple proof of concept one from an earlier post).

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: Seive of Atkin

That line that is colored in red is not legal C++ syntax. That code fails to compile using Visual Studio, and basically any ANSI C++ compiler.

It is legal for some C compilers.

Originally Posted by 2kaud

I don't know how fast this Sieve Of Atkin program is supposed to be for generating prime numbers, but on my 2.4Ghz system my program generates prime numbers up to 10000000 in just under 5 seconds with a further 7 seconds to write all 664579 primes to a file.

Actually, 5 seconds for the first 10mil primes is "slow" ;-)

THe benefit of the Atkin sieve breaks down as soon as you have to deal with numbers that no longer fit into your integer types and you need to work with bigints.

Then again, you typically tend to fall into a memory issue well before that point.

Primes larger than about 2^30 on a 32bit system (and larger than about 2^38 on 64bit) will need a different approach than simple sieves entirely to still be fast enough.

I have a prime routine that finds all primes up to 2^40 (1 terabyte) on Win32, not using disk storage (other than OS swapping) and does so in just under 2 hours on my "old" box. (Xeon E5430 at 2.66Ghz). that's technically 15 times faster than the 1-10mil in 5sec, although granted, it doesn't progress linearly.

I'm assuming this routine can do about 2^50 before it runs out of memory (never bothered running it that long, 2^50 is 10000 times more than 2^40 so extrapolating linearly that would take 2000 hours, although realistically probably closer to 800ish). a Win64 with 32Gb version should be able to do up to 2^120 (if you want to grow a sizeable beard in the process)

Note that even 2^120 would still "only" be a 36 digit number. I'm not sure how primes are efficiently calculated for those 500+ digit numbers.

Re: Seive of Atkin

Originally Posted by rockx

calculate prime numbers which has over 500 digits? i mean the really large ones?

Why do you want to calculate prime numbers this large? Do you want to know if a particular number is prime or do you want to generate a large number which is prime? Generating a large number which is prime is different to calculating primes up to a specified limit.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: Seive of Atkin

I simply want to calculate large prime numbers. The current world record sits at around 17.4 million digits. So using C++ i would like to device something which could get to at least the equivalent of that

Re: Seive of Atkin

Originally Posted by rockx

I simply want to calculate large prime numbers. The current world record sits at around 17.4 million digits. So using C++ i would like to device something which could get to at least the equivalent of that

Realistically, if your approach is to find code on the internet then post on a forum asking how to improve it, you're not likely to break any world records. You should probably take the time to learn the language first.

Re: Seive of Atkin

Originally Posted by rockx

I simply want to calculate large prime numbers. The current world record sits at around 17.4 million digits. So using C++ i would like to device something which could get to at least the equivalent of that

How many decades do you have in which to do this and to how many super-computers do you have access?

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: Seive of Atkin

There is another methodology to efficiently verify that a certain number is a prime or not.

And there is yet another methodology to just generate a potential large prime.

The current world record generated the prime very fast, actually verifying it is in fact prime was what took time. Note that most of these generated primes are one of many special forms of primes, the typical ones are mersenne primes (2n-1). the 17million digit one you speak of is one of these mersenne primes (257885161-1).

I can generate a 2n-1 very fast (it's just a series of n 1 bits), verifying it's a prime would take me some time

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.