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)
IF (TEST.LT.1.E-6) THEN
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
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.