amrex icon indicating copy to clipboard operation
amrex copied to clipboard

Thread safety of random numbers

Open markkrumholz opened this issue 5 years ago • 1 comments

I am trying to figure out if the AMReX_RandomEngine and AMReX_Random classes are thread-safe -- that is, if I'm running on MPI + openMP parallel (non-GPU) program, and I have multiple threads making calls to amrex::Random() on each MPI rank, can I be assured that the random numbers returned on different threads will be uncorrelated and independent? The documentation and the header file comments are unfortunately silent on thread-safety as far as I can tell. From reading the source code I think it should be thread-safe, but I wanted to confirm that before I go ahead and develop my application around that assumption. Please let me know, and, for future reference, it would be good if the documentation (or at least the header files) stated specifically whether the random number code is thread-safe. Thanks.

markkrumholz avatar Dec 14 '20 05:12 markkrumholz

Hi Mark,

Yes, amrex::Random() is thread safe. When OpenMP is on, each thread will have its own dedicated generator that is totally independent of the others.

atmyers avatar Dec 14 '20 06:12 atmyers