I am using Pari/GP to test (pseudo)primality of a sequence of numbers f(n)
, where f(n)
is some function. I have parallelized the code as
test(a) = parfor(n = 1, +oo, if(ispseudoprime(f(n)), print("PRIME "n));)
This works very well but I would also like to know which number is being tested. I can of course just add print(n)
after the if
. The problem is that ispseudoprime(a(n))
can take quite some time for n
while being very fast for n+1
. Since the computation is parallel, the output would quickly becomes a mess: I would see the list of numbers that have been tested, but I have no indication of what number is being tested at a given moment (the idea is that if the program is spending a lot of time on a number it is more and more likely to be prime, so I would like to know it).
Is there a simple way of doing this? Thank you!
I solved (in a very dirty way probably) like this
test(a) = parfor(n = 1, +oo, write("started",n); if(ispseudoprime(f(n)), print("PRIME "n)); write("done",n))
Then grep -v -f done started
gives what I want.