Parallel Random Number Generator

5 ビュー (過去 30 日間)
Anna
Anna 2015 年 6 月 29 日
回答済み: Edric Ellis 2015 年 6 月 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?

採用された回答

Edric Ellis
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 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by