In a parallelised computation, I would like each kernel separately to break out of ParallelDo
when it has finished going through the loop once. For a single kernel this works with Break[]
. For example
Do[Print[i]; Break[], {i, 1, 100}]
Gives output
1
But if I try the same thing on ParallelDo
(I have two kernels),
ParallelDo[Print[i]; Break[], {i, 1, 100}]
I get the strange output
1 (Kernel 2)
14 (Kernel 1)
27 (Kernel 2)
40 (Kernel 1)
53 (Kernel 2)
65 (Kernel 1)
77 (Kernel 2)
89 (Kernel 1)
while I would have expected just two outputs. It's essential that the two kernels break out separately, because my actual computation involves a random element such that running through the loop different times can take way more or less time. Thank you