MATLAB:在parfor或并行计算中生成随机数 [英] MATLAB: Generating random numbers in parfor or parallel computing

查看:459
本文介绍了MATLAB:在parfor或并行计算中生成随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个for循环中,我使用一个随机种子来生成所有随机数".它们是非常随机的,因为我一次从流中取出一个,没有任何间隙.

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.

但是,在parfor中,每个工作人员使用不同的随机种子,因此,获得的数字可能会相互干扰.因此,它们并不是真正随机的,因为它们不是来自单个种子.

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?

推荐答案

parfor中,工作人员使用来自专门设计为并行使用的随机数生成器的不同流.因此,您可以依靠parfor内部产生的具有合理统计质量的随机数.此处更多信息: http://www.mathworks.com/help/distcomp/control-random-number-streams.html

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

这篇关于MATLAB:在parfor或并行计算中生成随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆