Monday, January 29, 2024

[bpkzwput] parnextprime

parallel version of nextprime in Pari/GP, demonstrating that functions like return and break can be used in the sequential block of an infinite parfor.  (does the runtime system kill speculatively initiated threads?  it probably has to.)

parnextprime(start) = parfor(n=start, +oo, ispseudoprime(n), r, if(r,return(n)))

? #
timer = 1 (on)

? parnextprime(2^5011)-2^5011
cpu time = 3min, 21,456 ms, real time = 17,149 ms.
32405

? nextprime(2^5011)-2^5011
cpu time = 1min, 49,876 ms, real time = 1min, 49,885 ms.
32405

future work: more experiments with the sequential block.

previous pedagogical post on Pari/GP parallel processing.

No comments :