问题
In a single for loop, I use a single random seed to generate all the "random numbers". They are very random as I take one from the stream at a time, without any gap.
However, in parfor, each worker uses a different random seed, therefore, the numbers obtained may have interference with each other. Therefore, they are not really random as they do not come from a single seed.
Also, for my case, I do not know how many random numbers each worker needs beforehand. How can I solve this problem?
回答1:
In parfor, the workers use different streams from a random number generator that is specifically designed to be used in parallel. Therefore, you can rely on the random numbers generated inside parfor having reasonable statistical qualities. More here: http://www.mathworks.com/help/distcomp/control-random-number-streams.html
来源:https://stackoverflow.com/questions/40190243/matlab-generating-random-numbers-in-parfor-or-parallel-computing