Describe the bug
When compiled with MPI, channelflow's randomReal(Real a, Real b) produces a cyclic sequence of numbers with period 12.
Without MPI, the sequence is pseudorandom as expected.
The code for randomReal() in mathdefs.h seems pretty suspect. Every call to this function resets the drand48 seed. Is the call to srand48 supposed to be inside an else following the if (&initialized)?
inline Real randomReal(Real a, Real b) {
#ifdef HAVE_MPI
int taskid = 0;
int initialized = 0;
MPI_Initialized(&initialized);
if (initialized)
MPI_Comm_rank(MPI_COMM_WORLD, &taskid);
srand48((long int)(taskid + 1) * 1000 * drand48());
return a + (b - a) * drand48();
#else
return a + (b - a) * drand48();
#endif
}
Actual Result
Here's a sequence of 40 calls to randomReal() with and without MPI (the latter done by inlining the non-MPI code in the loop, rather than recompiling channelflow without MPI). I added // cycle comments to mark where the cycle starts and when it recurs.
Describe the bug When compiled with MPI, channelflow's
randomReal(Real a, Real b)
produces a cyclic sequence of numbers with period 12. Without MPI, the sequence is pseudorandom as expected.The code for
randomReal()
in mathdefs.h seems pretty suspect. Every call to this function resets the drand48 seed. Is the call tosrand48
supposed to be inside anelse
following theif (&initialized)
?Actual Result Here's a sequence of 40 calls to
randomReal()
with and without MPI (the latter done by inlining the non-MPI code in the loop, rather than recompiling channelflow without MPI). I added// cycle
comments to mark where the cycle starts and when it recurs.Steps to reproduce the issue
The code that produces the above output
Information on your system
Channlelfow compiled and run on openSUSE LEAP 15.0 on an Intel x86-64 architecture with g++-7.3.1 and CMAKE comfiguration
Additional context
Add any other context about the problem here.