hermann on Wed, 07 Jan 2026 23:08:22 +0100


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

Re: parforstep() available, but parsumstep() is missing


On 2026-01-07 22:57, hermann@stamm-wilbrandt.de wrote:
Thank you Bill — as always you show how to do things correctly.

But I committed a fallacy. While I did prevent 40% of isprime() calls,
those did not take much time (likely because of small divisor testing
upfront in isprime()). So the runtime does not get reduced by 40%, in
reality it is only a minimal improvement by 1.374s. But it is nice to
have learned how to do the rewrite, for other applications a similar
rewrite might reduce runtime significantly.

? parsum(k=1,10^9,isprime(k^2+(k+1)^2))
cpu time = 6min, 46,742 ms, real time = 25,438 ms.
68588950
? 1 \
+ parsum(k=1,10^9\5,isprime((5*k+0)^2+(5*k+1)^2)) \
+ parsum(k=0,10^9\5-1,isprime((5*k+2)^2+(5*k+3)^2)) \
+ parsum(k=0,10^9\5-1,isprime((5*k+4)^2+(5*k+5)^2))
cpu time = 6min, 24,658 ms, real time = 24,064 ms.
68588950
?

Small update, above is doing three parsum()s. I tried to do all in one parsum(), and that indeed reduced runtime by another 1.778s:

? 1 + parsum(k=0,10^9\5-1, \
 isprime((5*k+0)^2+(5*k+1)^2) \
+isprime((5*k+2)^2+(5*k+3)^2) \
+isprime((5*k+4)^2+(5*k+5)^2) )
cpu time = 5min, 56,359 ms, real time = 22,286 ms.
68588950
?

Regards,

Hermann.