Hello,
we have an old Fortran library that we are trying to make multithreaded. This library routine is called from an OpenMP loop, and apart from a few function arguments it’s using variables declared inside of this function as such:
SUBROUTINE BESSEL (Z,J0,J0P,IE)
IMPLICIT NONE
…
INTEGER::M(101),K,I,IB,IZ,MIZ,IE,INIT
…
DO I=1,101
TEST=1.
DO K=1,24
INIT=K
TEST=-TESTIA1(K)
IF (TEST.LT.1.E-6) THEN
EXIT
ENDIF
END DO
M(I)=INIT
END DO
Now, the bizzare thing that was happening with all the compilers that I have tried (PGI, Intel, GNU) was that the “INIT” variable would not always get the right “K” value when running multiple threads, looking like a race condition.
I was scratching my head about this since I figure that all the variables declared inside of a function called from an OMP parallel section should be private.
Now, even more strangely, the student I work with just randomly added
!$ompthreadprivate(INIT)
to the function and the race condition is gone.
I did not know that one can even declare threadprivate on a function (non-global) variable.
I would appreciate if you could comment on all this, since this is quite confusing to me.
Thanks,
MC