skip to Main Content

I wrote a program in Fortran that uses RANDOM_NUMBER() and was compiled with gfortran, but I noticed that the generated random numbers are inconsistent between versions. If RANDOM_SEED() is not used to seed the random number generator, then both, gfortran 4.4.7 (default in Centos 6) and gfortran 4.8.5 (default in Centos 7) produce the same sequence of random numbers. It surprises me because the default seed in gfortran 4.4.7 is 8 integers long while the default seed in gfortran 4.8.5 is 12 integers long and the numbers are completely different, but still the random number sequence is the same. On the other hand gfortran 7.3.1 (included in the devtoolset7 package in Centos 7) produces a different sequence of random numbers on every run unless it is initialized with RANDOM_SEED(). However the seed in this version consist of 33 integer numbers and therefore the seeds of the older versions will not work.

For reproducibility I need to reproduce exactly the same random number sequence on every run regardless of the gfortran version. I would like to know if there is a way to translate the default seed among different gfortran versions or if there is any other way to get the same random number sequence with any gfortran version.

2

Answers


  1. No, for GFortran 7 the PRNG algorithm was changed to a completely different kind of algorithm. There’s basically no way to get an identical stream of random numbers for GFortran <7 and >= 7.

    If you need exact reproducibilty across different GFortran version you need to use another PRNG implementation.

    Login or Signup to reply.
  2. Janneb is correct.

    If you need consistency between compiler versions, and perhaps even compilers (ifort, pgfortran), you should use something other than the built-in tool. I am personally aware of SPRNG (http://www.sprng.org/), and there are presumably many other similar tools.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search