How to control the random number generation when using a parfor loop
이전 댓글 표시
When I want to repeat my code with the same results, I fix the seed in the beginning of the code. Say: rng(100) I can then generate a random vector: say R = rand(100,1). The result is the same every time I run the code.
Now, instead of generating a random vector of dimension 100 at once, I would like to parallelize my code using parfor and 5 workers. Each worker should work with a subvector: Worker one should work with R(1:20) (it has to generate it first since I do not want to save the whole thing before starting parfor), worker two works with R(21:40).. worker 5 works with R(81:100).
How to control the generation of these subvectors inside each parfor loop, such that the resulting vector R is the same as If I generated it by the command
rng(100)
R = rand(100,1)?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!