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

[email protected] Wed, 07 Jan 2026 22:57:40 +0100
Newsgroups gmane.comp.mathematics.pari.user
Message-ID <[email protected]>
On 2026-01-07 22:14, Bill Allombert wrote:
> On Wed, Jan 07, 2026 at 08:31:31PM +0100, [email protected] 
> wrote:
>> ...
>> result is poor, although only 20% isprime() tests are done, parforstep
>> overhead is unacceptable:
>> 
>> hermann@7950x:~$ numactl -C 0-15 gp -q
>> ? #
>>    timer = 1 (on)
>> ? parsum(k=1,10^9,isprime(k^2+(k+1)^2))
>> cpu time = 6min, 49,486 ms, real time = 25,606 ms.
>> 68588950
>> ? c=0;parforstep(k=5,10^9,5,isprime(k^2+(k+1)^2),r,c+=r);c
>> cpu time = 5min, 40,308 ms, real time = 2min, 39,913 ms.
>> 22858489
> 
> I suggest:
> 
> ? parsum(k=1,10^9\5,isprime((5*k)^2+((5*k)+1)^2))
> %7 = 22858489
>   cpu time 3min, 52,056 ms, real time 14,522 ms.
> 
> Cheers,
> Bill.
> 
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
?

Regards,

Hermann.