I try to use reap and sow to accumulated values during a calculation. It is recommended because it is said to be faster than AppenTo.
However, I would like to utilize all my cpu cores by using parallelsubmit on various reap expressions with nested for and sow. It seems that this does not work properly. Please take a look at the following example:
end = 5
Reap[
For[t = 0, t < end, t++,
Sow[t]
]
]
WaitAll[%]
returns:
{Null, {{0, 1, 2, 3, 4}}} → Good
end = 5
ParallelSubmit[
Reap[
For[t = 0, t < end, t++,
Sow[t]
]
]
]
WaitAll[%]
returns:
{Null, {}} → Bad
However, if I replace the end variable with its value like so:
Probably, the time required to do all the parallel staff (kernels communication and other) is greater then plain sequential computation time.
The benefit from parallel computations can be seen, for example, for ParallelTable[] when it’s arg takes some decent time to be evaluated for a single iteration: