Jean-Luc Arnaud on Tue, 06 Feb 2024 00:49:21 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: nonprime(n)


Le 05/02/2024 à 18:47, Bill Allombert a écrit :
On Mon, Feb 05, 2024 at 06:41:35PM +0100, Jean-Luc Arnaud wrote:
Le 03/02/2024 à 18:33, Ruud H.G. van Tol a écrit :
for(n=1,2^18, prime(n));
Hi Ruud,

What kind of PC or Mac Monster do you own, which is able to calculate:

     ? for(n=1,2^18, prime(n));
     cpu time = 1,516 ms, real time = 1,521 ms.

in 1.5 s, where my iMac does it in ... close to 4min? 😭😭

     cpu time = 3min, 38,881 ms, real time = 3min, 56,939 ms.
The trick is to start GP with -p257M so you already have the
prime number availabkle

%gp -q -p 257M
? for(n=1,2^18, prime(n));
? ##
   ***   last result: cpu time 1,198 ms, real time 1,198 ms.

Cheers,
Bill.

Ok, with -q -p257M, I got:

    ? for(n=1,2^18, prime(n));
    cpu time = 1,157 ms, real time = 1,158 ms.

    ? for(n=1,2^18, nonprime(n));
    cpu time = 1,792 ms, real time = 1,794 ms.


    ? for(n=1,2^19, prime(n));
    cpu time = 6,690 ms, real time = 6,695 ms.

    ? for(n=1,2^19, nonprime(n));
    cpu time = 4,087 ms, real time = 4,090 ms.


Note that parfor works, too, without -q -p257M:

    ? parfor(n=1,2^19, prime(n));
    cpu time = 38min, 46,353 ms, real time = 2min, 27,849 ms.

    ? export(nonprime);parfor(n=1,2^19, nonprime(n));
    cpu time = 8,607 ms, real time = 1,009 ms.


and with -q -p257M:

    ? parfor(n=1,2^19, prime(n));
    cpu time = 12,721 ms, real time = 1,290 ms.

    ? export(nonprime);parfor(n=1,2^19, nonprime(n));
    cpu time = 8,653 ms, real time = 1,011 ms.


In addition, gp -q -p257M needs almost 1 GB RAM, whereas gp needs 7.2 MB.

If of any interest...

Jean-Luc