rng shuffle in parallel computing
12 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Steven Lord
on 31 May 2021
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.
More Answers (0)
See Also
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!