rng shuffle in parallel computing
14 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I am running a code on our parallel computing cluster which depends on some subfunction (select.m) and includes a for loop with 20 iterations, where select is called in every iteration. Select depends on a random number. I don`t want to use the same random number in every iteration and have therefore included rng('shuffle') on top of select.m. I have also saved the random numbers generated. If I include rng ('shuffle') I get different numbers (exactly what I want), if I don`t I only get two different "random" numbers. The Matlab help however says: When parallel processing, rng('shuffle') should not be used to set the random number stream on different workers to ensure independent streams since it seeds the random number generator based on the current time.
Honestly, I don`t quite understand what`s the problem with that. Secondly. I also ran every iteration in a real parallel way (calling the script 20 times). However, when I only use the default settings, I get the same "random" number here everytime.
My questions would be: What`s the problem with rng ('shuffle') in my first and second approach and what else could I do to get random numbers in both scenarios?
Best,
Laurie
0 个评论
采纳的回答
Steven Lord
2021-5-31
Have you ever seen a movie where the bad guys say "Synchronize your watches" so they will all act at exactly the same time? That is what could happen if you use rng shuffle on multiple workers at once. They each note the time and use that to initialize the random number generators. What if they all note the time at exactly the same time? You get the same numbers on each worker.
Consider creating a RandStream with multiple streams and using a different stream on each worker. See this documentation page for a discussion of some of the techniques involved in using multiple streams.
更多回答(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!