Bug 42602 - [4.5 Regression] libgomp.fortran/recursion1.f90 aborted at random
Summary: [4.5 Regression] libgomp.fortran/recursion1.f90 aborted at random
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgomp (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords:
Depends on: 42517
Blocks:
  Show dependency treegraph
 
Reported: 2010-01-04 04:35 UTC by H.J. Lu
Modified: 2010-01-04 22:37 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-01-04 08:02:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2010-01-04 04:35:57 UTC
libgomp.fortran/recursion1.f90 aborted at random on Linux/Core i7.
There are

---
implicit none
integer :: i,s

s=0
!$omp parallel do private(i) shared(s)
do i=1,10
  call sub(i)
end do
!$omp end parallel do
if (s/=55) call abort()

contains

  subroutine sub (n)
    integer :: n
    s = s + n
    print '(A,i3)',"loop =",n
  end subroutine

end
---

's' isn't always 55. It has the value of the last running thread.
Does OpenMP guarantees that 's' will be 55?
Comment 1 Jakub Jelinek 2010-01-04 08:02:31 UTC
There is no such guarantee, the testcase contains data race.
It can increment a shared variable in multiple threads using non-atomic instructions.  One fix would be to use
!$omp atomic
  s = s + n
instead of just
  s = s + n
Or put s = s + n into !$omp single, or use some other kind of locking.
Comment 2 H.J. Lu 2010-01-04 14:22:03 UTC
A patch is posted at

http://gcc.gnu.org/ml/gcc-patches/2010-01/msg00141.html
Comment 3 hjl@gcc.gnu.org 2010-01-04 14:28:42 UTC
Subject: Bug 42602

Author: hjl
Date: Mon Jan  4 14:28:30 2010
New Revision: 155615

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155615
Log:
Make 's' atomic

2010-01-04  H.J. Lu  <hongjiu.lu@intel.com>

	PR libgomp/42602
	* libgomp.fortran/recursion1.f90 (sub): Make 's' atomic.

Modified:
    trunk/libgomp/ChangeLog
    trunk/libgomp/testsuite/libgomp.fortran/recursion1.f90

Comment 4 H.J. Lu 2010-01-04 18:39:18 UTC
Now I got

At line 14 of file /export/gnu/import/svn/gcc-test/src-trunk/libgomp/testsuite/libgomp.fortran/recursion1.f90
Fortran runtime error: Recursive call to nonrecursive procedure 'sub'
Comment 5 H.J. Lu 2010-01-04 22:37:22 UTC
(In reply to comment #4)
> Now I got
> 
> At line 14 of file
> /export/gnu/import/svn/gcc-test/src-trunk/libgomp/testsuite/libgomp.fortran/recursion1.f90
> Fortran runtime error: Recursive call to nonrecursive procedure 'sub'
> 

This is PR 42517. A patch is posted at

http://gcc.gnu.org/ml/gcc-patches/2010-01/msg00187.html