public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/40190]  New: DATE_AND_TIME returns GMT hour sometimes with OpenMP
@ 2009-05-18 19:52 longb at cray dot com
  2009-05-18 21:12 ` [Bug fortran/40190] " burnus at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: longb at cray dot com @ 2009-05-18 19:52 UTC (permalink / raw)
  To: gcc-bugs

Test case:
program testhour
use omp_lib
integer :: h(1000), h1(1000), bins(0:23), v(8)

call omp_set_num_threads(4)

print *, "Running on",omp_get_max_threads(),"threads
and",omp_get_num_procs(),"procs."

!$omp parallel do schedule(STATIC,250)
do i=1,1000
   call date_and_time(values=v)
   h(i) = v(5)
end do
!$omp end parallel do

   print *, "date_and_time hour:"
   bins = 0
   do i=1,1000
      bins(h(i)) = bins(h(i)) + 1
   end do
   do i=0,23
      if (bins(i) > 0) print *, "For",bins(i),"calls, hour =",i
   end do


end program testhour

Compile with -fopenmp, and run on 4 threads:

> aprun -n1 -d4 ./dattest
 Running on           4 threads and           1 procs.
 date_and_time hour:
 For         707 calls, hour =          13
 For         293 calls, hour =          18
Application 2721423 resources: utime 0, stime 0


This was run in US Central Daylight time zone.  Most of the time, the correct
hour (13) was returned, but a sizable number of times, the hour correct for GMT
was returned instead. It looks like the conversion from GMT to the local time
zone sometimes fails when the routine is concurrently called from more that one
thread.

I wrote a similar program that called the system localtime() routine instead,
as well as localtime_r(), and both consistently returned the correct hour.

The same code compiled with either the Cray or PGI compiler consistently
returns the same hour for every iteration.


-- 
           Summary: DATE_AND_TIME returns GMT hour sometimes with OpenMP
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: longb at cray dot com
  GCC host triplet: Linux, x86-64
GCC target triplet: Linux, x86-64 (quad-core Opteron)


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


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

* [Bug fortran/40190] DATE_AND_TIME returns GMT hour sometimes with OpenMP
  2009-05-18 19:52 [Bug fortran/40190] New: DATE_AND_TIME returns GMT hour sometimes with OpenMP longb at cray dot com
@ 2009-05-18 21:12 ` burnus at gcc dot gnu dot org
  2009-05-18 22:11 ` [Bug libfortran/40190] " hjl dot tools at gmail dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-05-18 21:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2009-05-18 21:12 -------
Confirm. I looked at the source code, but I don't see why it can happen, but it
does.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2009-05-18 21:12:45
               date|                            |


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


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

* [Bug libfortran/40190] DATE_AND_TIME returns GMT hour sometimes with OpenMP
  2009-05-18 19:52 [Bug fortran/40190] New: DATE_AND_TIME returns GMT hour sometimes with OpenMP longb at cray dot com
  2009-05-18 21:12 ` [Bug fortran/40190] " burnus at gcc dot gnu dot org
@ 2009-05-18 22:11 ` hjl dot tools at gmail dot com
  2009-05-19  6:42 ` jb at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: hjl dot tools at gmail dot com @ 2009-05-18 22:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from hjl dot tools at gmail dot com  2009-05-18 22:11 -------
date_and_time isn't thread-safe. It should use gmtime_r and
localtime_r if they are available.


-- 

hjl dot tools at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|fortran                     |libfortran


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


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

* [Bug libfortran/40190] DATE_AND_TIME returns GMT hour sometimes with OpenMP
  2009-05-18 19:52 [Bug fortran/40190] New: DATE_AND_TIME returns GMT hour sometimes with OpenMP longb at cray dot com
  2009-05-18 21:12 ` [Bug fortran/40190] " burnus at gcc dot gnu dot org
  2009-05-18 22:11 ` [Bug libfortran/40190] " hjl dot tools at gmail dot com
@ 2009-05-19  6:42 ` jb at gcc dot gnu dot org
  2009-05-19  9:11 ` dfranke at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jb at gcc dot gnu dot org @ 2009-05-19  6:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jb at gcc dot gnu dot org  2009-05-19 06:42 -------
Assigning to myself.

HJL is right, we should use the _r functions if available, if not we must
protect the calls with a mutex.


-- 

jb at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jb at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2009-05-18 21:12:45         |2009-05-19 06:42:22
               date|                            |


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


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

* [Bug libfortran/40190] DATE_AND_TIME returns GMT hour sometimes with OpenMP
  2009-05-18 19:52 [Bug fortran/40190] New: DATE_AND_TIME returns GMT hour sometimes with OpenMP longb at cray dot com
                   ` (2 preceding siblings ...)
  2009-05-19  6:42 ` jb at gcc dot gnu dot org
@ 2009-05-19  9:11 ` dfranke at gcc dot gnu dot org
  2009-05-19 17:48 ` hjl dot tools at gmail dot com
  2009-05-29 21:04 ` jb at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2009-05-19  9:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from dfranke at gcc dot gnu dot org  2009-05-19 09:11 -------
(In reply to comment #3)
> HJL is right, we should use the _r functions if available, if not we must
> protect the calls with a mutex.

Janne, if mutexes are added, could you also add a note to the docs of that
these function(s) may be a serialization point in OMP applications? Something
similar to RANDOM_NUMBER:

"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."

Thanks.

     Daniel


-- 


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


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

* [Bug libfortran/40190] DATE_AND_TIME returns GMT hour sometimes with OpenMP
  2009-05-18 19:52 [Bug fortran/40190] New: DATE_AND_TIME returns GMT hour sometimes with OpenMP longb at cray dot com
                   ` (3 preceding siblings ...)
  2009-05-19  9:11 ` dfranke at gcc dot gnu dot org
@ 2009-05-19 17:48 ` hjl dot tools at gmail dot com
  2009-05-29 21:04 ` jb at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: hjl dot tools at gmail dot com @ 2009-05-19 17:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from hjl dot tools at gmail dot com  2009-05-19 17:47 -------
*** Bug 40201 has been marked as a duplicate of this bug. ***


-- 


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


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

* [Bug libfortran/40190] DATE_AND_TIME returns GMT hour sometimes with OpenMP
  2009-05-18 19:52 [Bug fortran/40190] New: DATE_AND_TIME returns GMT hour sometimes with OpenMP longb at cray dot com
                   ` (4 preceding siblings ...)
  2009-05-19 17:48 ` hjl dot tools at gmail dot com
@ 2009-05-29 21:04 ` jb at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jb at gcc dot gnu dot org @ 2009-05-29 21:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jb at gcc dot gnu dot org  2009-05-29 21:04 -------
Fixed on trunk as of r147985, closing as fixed.


-- 

jb at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2009-05-29 21:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-18 19:52 [Bug fortran/40190] New: DATE_AND_TIME returns GMT hour sometimes with OpenMP longb at cray dot com
2009-05-18 21:12 ` [Bug fortran/40190] " burnus at gcc dot gnu dot org
2009-05-18 22:11 ` [Bug libfortran/40190] " hjl dot tools at gmail dot com
2009-05-19  6:42 ` jb at gcc dot gnu dot org
2009-05-19  9:11 ` dfranke at gcc dot gnu dot org
2009-05-19 17:48 ` hjl dot tools at gmail dot com
2009-05-29 21:04 ` jb at gcc dot gnu dot 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).