atcollab / at

Accelerator Toolbox
Apache License 2.0
48 stars 31 forks source link

Correct random generators for MPI #737

Closed lfarv closed 6 months ago

lfarv commented 7 months ago

Following a user's report on the use of random generators with MPI, this PR corrects 2 points:

  1. The reset_rng(rank=0, seed=n) function, used for seeding the generators, behaved oddly and was not clearly documented. Up to now, the function needed to provide explicitly the MPI process rank to initialise correctly the process-specific generator (the so-called "thread" generator). Forgetting this resulted in all threads using the same random stream. Now by default, reset_rng now uses the actual rank, so that the rank argument can be omitted. The documentation is improved.
  2. The Gaussian generator used static variables to store values between successive calls. This could introduce correlations between the "common" and "thread" random streams. Static variables are now eliminated.