Bill Allombert on Wed, 20 Mar 2024 15:05:46 +0100


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

Re: How to efficiently count Proth primes with GP parfor?


On Wed, Mar 20, 2024 at 02:23:49PM +0100, hermann@stamm-wilbrandt.de wrote:
> > You need to do work by batch.
> > 
> > isProth(p)=my(v=valuation(p-1,2));p>>v<2^v;
> > export(isProth);
> > {
> >   my(nbt=default(nbthreads));
> >   my(c=0,B=323092481\nbt);
> >   parforstep(i=1,323092481,B,
> >     my(cc=0);
> >     forprime(p=i,min(i+B-1,323092481),cc+=isProth(p));cc
> >   ,C,c+=C);c
> > }
> > %3 = 3000
> > ? ##
> >   ***   last result: cpu time 17,843 ms, real time 1,070 ms.
> > 
> > (with 20 cores).
> > 
> Which GP version do you run?
The GIT version!

For 2.15.4 you need to replace parforstep by parfor,
for example
{
  my(nbt=default(nbthreads));
  my(c=0,B=323092481\nbt);
  parfor(ii=0,(323092481+B-1)\B,
    my(cc=0,i=ii*B+1);
    forprime(p=i,min(i+B-1,323092481),cc+=isProth(p));cc
  ,C,c+=C);c
}

Cheers,
Bill.