public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/54406] New: random_number() sometimes returns duplicate values when called from parallel threads
@ 2012-08-29 12:36 bugzilla.tmschr at wronghead dot com
  2012-08-29 12:40 ` [Bug fortran/54406] " bugzilla.tmschr at wronghead dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: bugzilla.tmschr at wronghead dot com @ 2012-08-29 12:36 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: bugzilla.tmschr@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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/54406] random_number() sometimes returns duplicate values when called from parallel threads
  2012-08-29 12:36 [Bug fortran/54406] New: random_number() sometimes returns duplicate values when called from parallel threads bugzilla.tmschr at wronghead dot com
@ 2012-08-29 12:40 ` bugzilla.tmschr at wronghead dot com
  2012-08-29 13:16 ` burnus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: bugzilla.tmschr at wronghead dot com @ 2012-08-29 12:40 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/54406] random_number() sometimes returns duplicate values when called from parallel threads
  2012-08-29 12:36 [Bug fortran/54406] New: random_number() sometimes returns duplicate values when called from parallel threads bugzilla.tmschr at wronghead dot com
  2012-08-29 12:40 ` [Bug fortran/54406] " bugzilla.tmschr at wronghead dot com
@ 2012-08-29 13:16 ` burnus at gcc dot gnu.org
  2012-08-29 13:56 ` bugzilla.tmschr at wronghead dot com
  2012-08-29 14:20 ` burnus at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-08-29 13:16 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54406

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-08-29 13:16:36 UTC ---
How about replacing
  !$OMP parallel do schedule(dynamic)
by
  !$OMP parallel do schedule(dynamic) private(r)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/54406] random_number() sometimes returns duplicate values when called from parallel threads
  2012-08-29 12:36 [Bug fortran/54406] New: random_number() sometimes returns duplicate values when called from parallel threads bugzilla.tmschr at wronghead dot com
  2012-08-29 12:40 ` [Bug fortran/54406] " bugzilla.tmschr at wronghead dot com
  2012-08-29 13:16 ` burnus at gcc dot gnu.org
@ 2012-08-29 13:56 ` bugzilla.tmschr at wronghead dot com
  2012-08-29 14:20 ` burnus at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: bugzilla.tmschr at wronghead dot com @ 2012-08-29 13:56 UTC (permalink / raw)
  To: gcc-bugs

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... :(


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/54406] random_number() sometimes returns duplicate values when called from parallel threads
  2012-08-29 12:36 [Bug fortran/54406] New: random_number() sometimes returns duplicate values when called from parallel threads bugzilla.tmschr at wronghead dot com
                   ` (2 preceding siblings ...)
  2012-08-29 13:56 ` bugzilla.tmschr at wronghead dot com
@ 2012-08-29 14:20 ` burnus at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-08-29 14:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54406

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-08-29 14:19:49 UTC ---
Close as INVALID.

Good luck finding the issue with your big program!


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-08-29 14:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-29 12:36 [Bug fortran/54406] New: random_number() sometimes returns duplicate values when called from parallel threads bugzilla.tmschr at wronghead dot com
2012-08-29 12:40 ` [Bug fortran/54406] " bugzilla.tmschr at wronghead dot com
2012-08-29 13:16 ` burnus at gcc dot gnu.org
2012-08-29 13:56 ` bugzilla.tmschr at wronghead dot com
2012-08-29 14:20 ` burnus at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).