rng shuffle in parallel computing

14 ビュー (過去 30 日間)
Laurie König
Laurie König 2021 年 5 月 31 日
コメント済み: Laurie König 2021 年 6 月 1 日
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

採用された回答

Steven Lord
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.
  1 件のコメント
Laurie König
Laurie König 2021 年 6 月 1 日
Thanks for your help! When I only use the default setting in a for loop on the server, I get one random number x for the first for loop iteration, then all zeros for all other iteration, followed by the exact same number x for the last iteration. Just out of interest--why is that happening?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Find more on Creating and Concatenating Matrices 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!

Translated by