[Patch, fortran] PR 50690 Disable common function elimination in WORKSHAREs
Jakub Jelinek
jakub@redhat.com
Sun Dec 4 13:28:00 GMT 2011
On Sun, Dec 04, 2011 at 02:07:49PM +0100, Thomas Koenig wrote:
> I worked out a patch which does this. However, in testing it, I came
> across some very strange behavior (even without my patch):
>
> With the program
>
> program foo
> implicit none
> integer, parameter :: n = 100000000
> real, parameter :: eps = 3e-7
> integer :: i,j
> real :: A(n), B(5), C(n)
> real :: tmp
> B(1) = 3.344
> tmp = B(1)
> do i=1,10
> call random_number(a)
> c = a
> !$omp parallel default(shared)
> A(:) = A(:)*cos(B(1))+A(:)*cos(B(1))
> !$omp end parallel
The above contains data races, so anything can happen.
As A is shared, you can't write into all elements of
that array in all threads at once.
Either only one thread can write it ($omp critical,
$omp master, $omp single), or different threads need to write
different elements.
Jakub
More information about the Fortran
mailing list