Hi,
I originally posted this in the forum on OpenMP’s website, but they said to try to post it here. The original question is here: http://openmp.org/forum/viewtopic.php?f=3&t=215.
I am trying to compile this with the PGI Fortran compiler version 6.1 on a 64 bit system. But it seems that it has some problems with OpenMP.
The code is shown below, and to get a full description of the problem, please see the above link…
Amax = 0.0_dbl
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(j,alpha,beta,nu,A,priv_max,priv_numax)
priv_max = 0.0_dbl
!$OMP DO
do j = 1,Nspec
nu = nu_min+dF*(j-1)
! Calculate amplitude:
call CalcAlphaBeta(t,f,w,nu,alpha,beta)
A = sqrt(alpha**2 + beta**2)
if (A > priv_max) then
priv_max = A
priv_numax = nu
endif
enddo
!$OMP END DO NOWAIT
!$OMP FLUSH
if (priv_max > Amax) then
!$OMP CRITICAL
if (priv_max > Amax) then
print *, priv_max
Amax = priv_max
!$OMP FLUSH
numax = priv_numax
endif
!$OMP END CRITICAL
endif
!$OMP END PARALLEL
! If this line is included it works?! WHY?!
! print *, 'Result: ', Amax
Please help… I will be really grateful!
Best regards,
/Rasmus
Hi Rasmus,
What happens if you remove the outer if statement for “priv_max > Amax” or place it under the critical section? Having Amax outside of the critical section is most likely cause of the error.
No, that doesn’t help… Same thing…
/Rasmus
Ok. I’ll need to be able to compile the source and run the exe to determine what’s happening. Can you send and example to PGI customer support (trs@pgroup,com) along with instructions and ask them to forward it to me?
Thanks,
Mat
I have now sent you the source code.
Hope you can find the error…
/Rasmus
Hi Rasmus,
The issue here is that the compiler’s dead store elimination optimization is removing the store to Amax (“Amax = priv_max”) since Amax is not used later in the subroutine. (This also explains why the program works as expected when you add the print statement), While fine in a serial context, this optimization is not correct in a parallel context. Hence, I’ve filed a technical problem report (TPR#15143) and sent it to our engineers.
To work around the issue, please compile this file at “-O1” instead of “-O3” since dead store elimination occurs at “-O2”. Of course, your print statement works as well.
We appreciate you bring this problem to our attention and we should be able to have a fix soon.
Mange tak,
Mat
Great! Thanks a million! I really appreciate that you could take the time to help me, and it seems that it was beneficial for both of us. :-)
Thumbs up to you and the rest of the PGI-boys!
Best regards,
Rasmus
PS: Selv tak, du var en stor hjælp!
Hi Rasmus,
TPR#15143 has been fixed in PGI 7.2-5.
Thanks,
Mat