rng shuffle in parallel computing

31 visualizaciones (últimos 30 días)
Laurie König
Laurie König el 31 de Mayo de 2021
Comentada: Laurie König el 1 de Jun. de 2021
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

Respuesta aceptada

Steven Lord
Steven Lord el 31 de Mayo de 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.
  1 comentario
Laurie König
Laurie König el 1 de Jun. de 2021
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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by