http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54406
Bug #: 54406 Summary: random_number() sometimes returns duplicate values when called from parallel threads Classification: Unclassified Product: gcc Version: 4.7.1 Status: UNCONFIRMED Severity: major Priority: P3 Component: fortran AssignedTo: unassig...@gcc.gnu.org ReportedBy: bugzilla.tms...@wronghead.com When called from an OMP parallel section (e.g. $OMP parallel do), the random_number() intrinsic occasionally returns the same value twice in succession. I've attached a simple test program, to be compiled with: gfortran -fopenmp rnd.f08 Some quick statistics showed that the effect is less when: - directly using random_number() in the main loop, - using a static schedule, and/or - omitting the (useless) inner loop. The effect vanishes when using 'print*,fct()' directly, i.e. omitting storage or the return value in variable r. For BASH users, there's a simple and obvious script to get some statistics on the number of duplicated values: while true; do echo "100000-`./a.out|uniq|wc -l`" | bc; done I quote from "Using GNU Fortran": "Please note, this RNG is thread safe if used within OpenMP directives, i.e., its state will be consistent while called from multiple threads. However, the KISS generator does not create random numbers in parallel from multiple sources, but in sequence from a single source. If an OpenMP-enabled application heavily relies on random numbers, one should consider employing a dedicated parallel random number generator instead." While I understand that the period is finite, it says that "The overall period exceeds 2^123", i.e. ca. 1.06E37. Thus, to my understanding, duplication of values should never happen even when considering all the caveats mentioned.