InverseLight/ValoMC

Correlation in RNG

hanninenn opened this issue · 1 comments

If seed for RNG is not given manually, simulations started at the same second will give identical result. Further, there seems to be correlation between simulations which are started within a couple of seconds.

PRNG initialisation uses time(), which has granularity of a second. A better way would be to use random_device (available since C++11).

Correlation between runs started a couple of seconds apart seems to be a bug: on line 1518 in MC2D.cpp and 1641 in MC3D.hpp variable totalthreads is always 1 in non-MPI runs. Because of this, if two OpenMP runs are started a few seconds apart, some threads in the second run will use the same PRNG seeds as some threads in the first run. This could be fixed by setting totalthreads correctly (to nthreads) in non-MPI runs. Alternatively, if the PRNG initialisation is done with some better method than time(), this problem is also fixed automatically.