| hermann on Tue, 10 Feb 2026 14:18:10 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: Is short-circuit evaluation possible with parfor() ? |
On 2026-02-10 10:26, Ruud H.G. van Tol wrote:
Hello Hermann, I expect it to be related to your nbthreads setting. Mine is at 10. I hardly ever go over 12, to avoid overhead.
That is the reason why nbthreads is 16 on my 16C/32T AMD 7950X system. And why nbthreads is 192 on my 192C/384T 8-socket server. One gp thread per really existing core.
I was forced to use that by GP, but now learned that your "my(...)" is OK as well.I don't call export(), as I think that for this case it is superfluous.
return() works as documented, but 1994 was a bad input to measure.
1995 is good, because the 445th prime tested aborts.
So my first script without early abort takes 32 seconds real time:
hermann@x3950-X6:~$ gp
...
GP/PARI CALCULATOR Version 2.17.3 (released)
...
threading engine: pthread, nbthreads = 192
...
? isok2(n) =
{s=0;p=prime(n+1)#;export(s,p);parfor(i=2,n+1,ispseudoprime(1+p/prime(i)),r,s+=r);s==0};
? # timer = 1 (on) ? isok2(1995) cpu time = 1h, 37min, 20,393 ms, real time = 31,751 ms. %2 = 0 ?Now with return real time gets reduced to 17 seconds (and CPU time down to 50min from 1:37h)!
? isok3(n) = {my(p=prime(n+1)#);parfor(i=2,n+1,ispseudoprime(1+p/prime(i)),r,if(r,return(0)););1};
? isok3(1995) cpu time = 50min, 22,570 ms, real time = 17,110 ms. %4 = 0 ?Btw, GP ispseudoprime() is good for a few 1000 decimal digit computations:
? #digits(1995#) 836 ?For bigger numbers I let GP do the parallel orchestration and let it call out to pfgw64 that is based on gwnum lib that does big number computations superfast (on Intel/AMD CPUs only). For numbers with less than 800,000 decimal digits gwnum does not use multithreading, and so running 192× pfgw64 in paralel is good on the 8-socket server.
For n=20489 I started "nohup ./doitpar" with this script: hermann@x3950-X6:~/pfgw/distribution$ cat doitpar #!/bin/bash time numactl -C 0-191 gp -q < relaxed.par.gp hermann@x3950-X6:~/pfgw/distribution$ With this GP script: hermann@x3950-X6:~/pfgw/distribution$ cat relaxed.par.gp n=20489;export(n);parfor(i=2,n+1,if(0==system("./pfgw64 -tm -q\""prime(n+1)"#/"prime(i)"+1\" -Cquiet 2>/dev/null >/dev/null"),print("\nfound: "i"\n");return(0),print(i);system("date");));
hermann@x3950-X6:~/pfgw/distribution$ The whole computation completed in 5:44h real time (45.6d cpu time): hermann@x3950-X6:~/pfgw/distribution$ tail -5 nohup.out.343m Sat Feb 7 11:56:15 PM CET 2026 real 343m16.938s user 65710m17.430s sys 50m52.422s hermann@x3950-X6:~/pfgw/distribution$20489 does not belong to A391020 because three primes p with (20489+1)#/p+1 were found:
hermann@x3950-X6:~/pfgw/distribution$ grep found nohup.out.343m found: 3765 found: 12120 found: 13351 hermann@x3950-X6:~/pfgw/distribution$Those are the indices reported, for the lowest here is pfgw64 prime proof — the first prime with 100K decimal digits I found and proved prime:
? prime(20489+1) 230597 ? prime(3765) 35339 ? #digits(prime(20489+1)#/prime(3765)) 100010 ? hermann@7950x:~/pfgw/distribution$ time ./pfgw64 -tm -q"230597#/35339+1" PFGW Version 4.1.3.64BIT.20240114.x86_Dev [GWNUM 30.19] Primality testing 230597#/35339+1 [N-1, Brillhart-Lehmer-Selfridge] Running N-1 test using base 2 Calling Brillhart-Lehmer-Selfridge with factored part 33.33% 230597#/35339+1 is prime! (289.7452s+0.0279s) real 4m49,793s user 4m50,125s sys 0m0,055s hermann@7950x:~/pfgw/distribution$ Proving BIG numbers prime can earn you 150,000 USD price money ;-) https://www.eff.org/awards/coop Regards, Hermann.