[patch, Fortran] Fix PR 50690
Thomas Koenig
tkoenig@netcologne.de
Sun Nov 6 17:44:00 GMT 2011
Hi Tobias,
I'm just back from holiday, which it took me a bit longer to reply.
> Actually, the test case is *not* OK.
>
> If one compiles the original test case of the PR (or your
> workshare2.f90) with "-O" and looks at "-fdump-tree-original", one finds:
>
> #pragma omp parallel default(shared)
> {
> {
> real(kind=4) __var_1;
> {
> #pragma omp single
> {
> __var_1 = __builtin_cosf (b[0])
> }
> ...
> #pragma omp for schedule(static) nowait
> for (S.1 = 1; S.1 <= 5; S.1 = S.1 + 1)
> {
> a[S.1 + -1] = a[S.1 + -1] * D.1730 + a[S.1 + -1] *
> D.1731;
>
> Thus, __var_1 is a thread-local variable; however, COS() is not executed
> in all threads but only in one due to the omp single: "The single
> construct specifies that the associated structured block is executed by
> only one of the threads in the team" (2.5.3 single Construct, OpenMP 3.1).
>
> Jakub remarks that omp single is what we expand to omp workshare if it
> is not simple enough for us.
I modified the test case as below
! { dg-do run }
! { dg-options "-ffrontend-optimize" }
! PR 50690 - this used to ICE because workshare could not handle
! BLOCKs.
program foo
implicit none
integer, parameter :: n = 100000000
real, parameter :: eps = 3e-7
integer :: i
real :: A(n), B(5), C(n)
B(1) = 3.344
do i=1,10
call random_number(a)
c = a
!$omp parallel default(shared)
!$omp workshare
A(:) = A(:)*cos(B(1))+A(:)*cos(B(1))
!$omp end workshare nowait
!$omp end parallel ! sync is implied here
end do
c = c*cos(b(1)) + c*cos(b(1))
if (any(abs(a-c) > eps)) call abort
end program foo
and did indeed see an abort.
With the patch below (based on an earlier patch, fiddling with the OMP
clauses), the test case above passes, although the tree dump shows the
same issue that you referred to.
What would be the best strategy now? Jakub, could you check the patch
for correctness? Should I combine the workshare-6.diff approach
(modifying the BLOCKs) with this one? This will certainly make the
patch more compilcated, but is doable.
Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: workshare-3a.diff
Type: text/x-patch
Size: 3168 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20111106/dac1200f/attachment.bin>
More information about the Fortran
mailing list