MATLAB: Generating random numbers in parfor or parallel computing

a 夏天 提交于 2020-01-15 10:02:41

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!