필터 지우기
필터 지우기

rng shuffle in parallel computing

조회 수: 8 (최근 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개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by