[Bug fortran/54406] New: random_number() sometimes returns duplicate values when called from parallel threads

2012-08-29 Thread bugzilla.tmschr at wronghead dot com
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 "10-`./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.


[Bug fortran/54406] random_number() sometimes returns duplicate values when called from parallel threads

2012-08-29 Thread bugzilla.tmschr at wronghead dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54406

--- Comment #1 from bugzilla.tmschr at wronghead dot com 2012-08-29 12:39:55 
UTC ---
Created attachment 28099
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28099
Test to check for duplicate random numbers

Changing variable M may in-/decrease the effect. On my machine, the program -
as is - put out about 10 out of 100,000 duplicate values on average.


[Bug fortran/54406] random_number() sometimes returns duplicate values when called from parallel threads

2012-08-29 Thread bugzilla.tmschr at wronghead dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54406

--- Comment #3 from bugzilla.tmschr at wronghead dot com 2012-08-29 13:55:46 
UTC ---
Sorry for this report!!!1!!eleven! You're right, that fixes it. The fault is
clearly not with the random_number instrinsic.

I've been searching for a bug in a large program for days now and obviously was
a bit too desperate to find an easy explanation. I'm getting more and more
confident the bug is in myself... :(