Parallel Random Number Generator
조회 수: 5 (최근 30일)
이전 댓글 표시
I would like to run simulations requiring random numbers on each worker. First, I create a random stream of numbers on each worker:
parpool
spmd
s = RandStream.create(’mrg32k3a’,’NumStreams’,numlabs,’StreamIndices’,labindex);
RandStream.setGlobalStream(s);
end
Then, I perform the simulations:
spmd
output = some_function(input); %%%this function uses rand() and randn();
end
Am I correctly using RandStream to ensure statistically independent random numbers across workers? Can I combine the two spmd commands?
댓글 수: 0
채택된 답변
Edric Ellis
2015년 6월 30일
Yes, I believe your code is correct, and is basically the same initialization that is already carried out by Parallel Computing Toolbox.
You can safely merge the two spmd blocks.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!