Due to an apparent
gfortran compiler bug, care must be exercised with OpenMP directives’ placement. For example,
program foo implicit none !$ integer :: IAM, NPROCS !$ integer OMP_GET_NUM_THREADS, OMP_GET_THREAD_NUM, OMP_IN_PARALLEL !$OMP PARALLEL DEFAULT(none) PRIVATE(IAM, NPROCS) !$ IAM = OMP_GET_THREAD_NUM() !$ NPROCS = OMP_GET_NUM_THREADS() !$ print *, 'I AM processor ',IAM, ' (of ', NPROCS, ')' !$ print *, 'Am I in a parallel region (T)? ', OMP_IN_PARALLEL() !$OMP END PARALLEL end program foo
In this example, since the OpenMP key word PARALLEL starts two spaces to the right of
!$OMP, the GNU
gfortran compiler fails to recognize this to be an OpenMP directive !
Here is what happens when the above FORTRAN code is compiled with
katana:~ % gfortran -fopenmp -o foo foo.f90 In file foo.f90:5 !$OMP PARALLEL DEFAULT(none) PRIVATE(IAM, NPROCS) 1 Error: Unclassifiable OpenMP directive at (1) In file foo.f90:10 !$OMP END PARALLEL 1 Error: Unexpected !$OMP END PARALLEL statement at (1)
The above problem is restricted to
gfortran. There is no similar problems for the GNU C compiler OpenMP directives (i.e., #pramas).
This behavior is observed with our current version (4.1.1) of gfortran. This bug is presumably fixed in a newer release.