https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63938
Bug ID: 63938
Summary: OpenMP atomic update does not protect access to
automatic array
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: paul.k.romano at gmail dot com
It appears that performing !$omp atomic update on an automatic array does not
protect access to the array. As an example, consider the following program:
program atomic
integer :: i, x(1)
x(1) = 0
!$omp parallel do
do i = 1, 1000
!$omp atomic
x(1) = x(1) + 1
end do
!$omp end parallel do
print *, x
end program atomic
Compiling and running this program should result in the value 1000. Instead, it
results in an unpredictable value for x, indicating there is a race condition.
If you change x to a scalar or an allocatable array, it works fine and reports
the value 1000. Equivalent code in C does not produce a race condition. The
code gives the correct value when compiled with the Intel fortran compiler.
Information on my build of gcc:
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --disable-multilib
Thread model: posix