hermann on Wed, 20 Mar 2024 14:23:53 +0100


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

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


On 2024-03-20 11:26, Bill Allombert wrote:

The function isProth is too fast compared to the overhead of parallelism. As you see, PARI only manage to schedule 3.36 job on average before the first
one complete, so most of the time is spent scheduling jobs.

Ok.

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?
I run 2.15.4 and get error for your code:

? 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
}
  ***   unexpected ';': ...23092481),cc+=isProth(p));cc,C,c+=C);c
  ***                                               ^-------------
?



The best value of nbt will depend on your system.

My sysmtem value waits to see what can be done ...

? print(default(nbthreads))
32
?


Regards,

Hermann.