I'm asking your help with an OpenMP related parallelization problem. The following code is considered:
PROGRAM testfpr IMPLICIT NONE INTEGER :: i, j i = 1 j = 2 CALL sub1( i, j ) END PROGRAM testfpr SUBROUTINE sub1( a, b ) IMPLICIT NONE INTEGER, INTENT(IN) :: a, b INTEGER :: k !$OMP PARALLEL DEFAULT(PRIVATE) & !$OMP FIRSTPRIVATE(a,b) !$OMP DO DO k = 1, 100 !PRINT *,a,b CALL sub2( a, b ) ENDDO ! k !$OMP ENDDO !$OMP END PARALLEL END SUBROUTINE sub1 SUBROUTINE sub2( c, d ) IMPLICIT NONE INTEGER, INTENT(IN) :: c, d INTEGER, DIMENSION(1:10), PARAMETER :: aa = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 /) PRINT *, c, d PRINT *, aa(c), aa(d) END SUBROUTINE sub2
Compiling with ifort -O0 -g -openmp -check all testfpr.f90 and running it on two threads does not print anything. If running it on a single thread it crashes. However, if the PRINT statement in subroutine sub1 is uncommented, it's working and printing the expected values from SUBROUTINE sub2. A more complicated real life code shows similar behaviour. The compiler is v13.1.3, running on a Linux cluster 2.6.32-431.11.2.el6.x86_64.
After experimenting somewhat with the code above, I believe that the problem is related to the FIRSTPRIVATE clause. If the variable on which the clause is imposed is not directly used in the PARALLEL section, but it is passed to a subroutine, then something is going wrong and the value of the original variable is not copied to the thread-local instance of the variable. However, there may be some other problems as well, since sometimes SUBROUTINE sub2 seems not to be called at all. Furthermore, if the !$OMP PARALLEL directive is unified with the !$OMP DO directive into a single one, it is working well. The same problem does not show up with a GNU compiler (4.6.4).
Am I doing something wrong, or is this a bug somewhere?
Thank you for your help,