help with memory usage

Digital Parasite digital.parasite at
Wed Mar 11 14:47:21 CET 2009

On Wed, Mar 11, 2009 at 12:31 AM, Christ Schlacta <aarcane at> wrote:
> I'm just an old man with a bit of enthusiasm for prime numbers, so
> I've given myself a few simple goals:
> 1) use all available CPU power to generate prime numbers
> 2) find the largest prime number I can and hope it's a new record

I would say #2 is no so simple.  Do you know what the largest known
prime is?  You can find the list here:

Currently the largest known prime has 12.7 million digits.  You don't
mention what method you are using to verify the numbers are prime but
if it is the GMP built-in function mpz_probab_prime_p or mpz_nextprime
that is only a probabilistic primality test and does not guarantee the
number is prime.

> 3) be able to view the largest prime I've found, the last number I've
> tested, and the whole list of primes any time I want.

The first two items of #3 make sense to keep in memory of your running
program, but there is no need to keep the entire list of primes you
have ever found in memory.  It would make more sense to keep a list of
primes in a file. That way you can open the file and look at them any
time you want and you don't run into memory problems.

So every time your program found a prime, it would output the prime to
your file and only keep the largest one you have found and last number
tested in memory.


More information about the gmp-discuss mailing list