MATLAB Answers

Has Matlab changed the random number generators used in the parallel toolbox in the latest 2019a distribution?

25 views (last 30 days)
In comparing results obtained from stochastic code it is important to have reproducible results. I have code that always gave reproducible results in previous versions of the parallel toolbox, by means of a distributed reproducible RNG seed. This worked in multiple tests, on multiple computers, with different OS and multiple Matlab versions. Currently, when testing using the 2019a distribution, results have become irreproducible, and different to previous versions.
Does anyone know what has changed here? Is it the RNG that's changed? Is there a way to get reproducible RNs between the different Matlab generations? Or is this a lost cause, and Mathworks is just changing the code randomly, without warning - as seems to be the case?
  1 Comment
Edric Ellis
Edric Ellis on 29 Mar 2019
As @Stephan pointed out, the default random number generator for parallel pools did indeed change for R2019a. Can I ask whether you're seeing non-reproducible results in 19a - i.e. despite your setting of the RNG state, things vary from run to run inside 19a? Do you have any simple code that you can share that would demonstrate the problem? For example, I ran the code from this doc page, and got identical numerical results in 18b and 19a.

Sign in to comment.

Accepted Answer

Peter Drummond
Peter Drummond on 30 Mar 2019
Dear Stephan and Edric,
Thanks for the very informative feedback. To explain the problem, I do automated acceptance testing on code that relies on reproducibility of results. The numerics are expected to be the same no matter which OS, version of Matlab or number of processes. This is the only practical way to pick up what might be subtle errors in the code.
If the default parallel RNG is changed, then test results change in the current simulation code, depending on the Matlab version. This could cause problems with users testing distributed code to be certain it is running correctly and is not corrupted. Results obtained on earlier versions of Matlab won't be the same on later versions.
It seems like there could be a way to solve this through specifying the RNG, but this will require testing with different versions, to make sure changes don't break code run on old Matlab releases. Incidentally, my code is often run by other people, who may not have access to all Matlab versions - and in some cases they may only have Octave.
This is an issue with third world researchers. I have a university license, but not everyone has this. Some researchers prefer to tolerate longer run-times, if they can use older Matlab or open source.
The help is much appreciated -
Peter.

More Answers (1)

Stephan
Stephan on 28 Mar 2019
Edited: Stephan on 28 Mar 2019
Hi,
in the release notes you find the following section:
Default random number generator changed for parallel contexts
Behavior change
Starting in R2019a, the default random number generator for parallel computations is changed to Threefry. This change applies to calculations on parallel workers, GPU arrays, distributed arrays, and tall arrays. This generator offers performance enhancements for parallel calculations over the previous default. In releases up to and including R2018b, the default random number generator for parallel computations is CombRecursive.
With a different default generator, MATLAB generates different random number sequences by default in the context of parallel computations. However, the statistics of these calculations remain unaffected. Therefore, you might want to update any code that relies on the specific random numbers being generated, but most calculations on the random numbers are unaffected.
To set the generator to the settings used by default in R2018b and earlier on parallel workers, GPU arrays, and tall arrays, use the following commands.
Calculations on parallel workers and distributed arrays:
spmd
stream = RandStream.create("CombRecursive", "NumStreams", 2^32,...
"StreamIndices", 2*labindex);
RandStream.setGlobalStream(stream);
end
Calculations on GPU arrays:
gpurng(0,"CombRecursive")
Calculations on tall arrays:
tallrng(0,"CombRecursive")
Best regards
Stephan

Community Treasure Hunt

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

Start Hunting!

Translated by