hermann on Wed, 20 Mar 2024 02:13:13 +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 01:53, hermann@stamm-wilbrandt.de wrote:
...
I am doing it not right just now:

? c=0;parforprime(p=3,4636016641,isProth(p),C,if(C,c+=1));c
  ***   at top-level: c=0;parforprime(p=3,4636016641,isProth(p),C,if
  ***                     ^------------------------------------------
  *** parforprime: mt: please use export(isProth).
  ***   Break loop: type 'break' to go back to GP prompt
break>


? export(isProth)
? c=0;parforprime(p=3,4636016641,isProth(p),C,if(C,c+=1));c
  ***   at top-level: c=0;parforprime(p=3,4636016641,isProth(p),C,if
  ***                     ^------------------------------------------
  *** parforprime: mt: attempt to change exported variable 'v'.
  ***   Break loop: type 'break' to go back to GP prompt
break>

I figured out that variable v has to be local with "my(...)".

? isProth(p)=my(v=valuation(p-1,2));p>>v<2^v;
? export(isProth)
?

I tested the first 3,000 Proth primes:

? c=0;forprime(p=3,323092481,if(isProth(p),c+=1));c
3000
? ##
  ***   last result: cpu time 5,545 ms, real time 5,545 ms.
? c=0;parforprime(p=3,323092481,isProth(p),C,if(C,c+=1));c
3000
? ##
  ***   last result: cpu time 29,142 ms, real time 18,457 ms.
?

1) Why is sequential computation more than 5× faster than parallel? Synchronization?


2) Why does gp run with only 336% CPU and not wih more than 1500% or 3100% ?

top - 02:07:15 up 6 days, 14:38, 2 users, load average: 0.54, 0.86, 0.52
Tasks: 457 total,   2 running, 455 sleeping,   0 stopped,   0 zombie
%Cpu(s): 3.9 us, 5.0 sy, 0.0 ni, 91.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 31190.9 total, 28409.6 free, 593.4 used, 2187.9 buff/cache MiB Swap: 2048.0 total, 1808.3 free, 239.7 used. 30101.4 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 54630 hermann 20 0 955.0g 25064 6400 R 336.0 0.1 13:12.04 gp
...


Regards,

Hermann.