These test cases illustrate that gfortran ignores the COLLAPSE(M) clause on an !$OMP DO when the value given is not a constant (or declared as a variable having the parameter attribute. Other compilers supporting OpenMP API 3.0 raise an error when the primary test case is compiled.
The expected output should be an error similar to that raised by either the Intel or PGI compilers. > cat ISU3102.f90 ! collapse not having a constant value program test use omp_lib implicit none integer :: j,k integer :: m = 2 ! integer,parameter :: m = 2 !$omp parallel num_threads(2) private(j,k) !$omp do collapse(m) schedule (static,1) do k = 1,2 do j = 1,6 print *, k, j, omp_get_thread_num() enddo enddo !$omp end do !$omp end parallel end > diff ISU3102.f90 ISU3102p.f90 6,7c6,7 < integer :: m = 2 < ! integer,parameter :: m = 2 --- > ! integer :: m = 2 > integer,parameter :: m = 2 > diff ISU3102.f90 ISU3102noc.f90 9c9 < !$omp do collapse(m) schedule (static,1) --- > !$omp do schedule (static,1) BAD - The collapse clause is ignored rather than having an error detected: > setenv OMP_NUM_THREADS 2 > gfortran -o x -fopenmp ISU3102.f90 > ./x | sort 1 1 0 1 2 0 1 3 0 1 4 0 1 5 0 1 6 0 2 1 1 2 2 1 2 3 1 2 4 1 2 5 1 2 6 1 Expected output when value m has parameter attribute (constant): > gfortran -o xp -fopenmp ISU3102p.f90 > ./xp | sort 1 1 0 1 2 1 1 3 0 1 4 1 1 5 0 1 6 1 2 1 0 2 2 1 2 3 0 2 4 1 2 5 0 2 6 1 Output when no collapse clause is present: > ./xnoc | sort 1 1 0 1 2 0 1 3 0 1 4 0 1 5 0 1 6 0 2 1 1 2 2 1 2 3 1 2 4 1 2 5 1 2 6 1 Ifort (intel) raises an error: > ifort -openmp -o ix ISU3102.f90 -liomp5 ISU3102.f90(9): error #8167: COLLAPSE operand must be an integer expression !$omp do collapse(m) schedule (static,1) ---------^ compilation aborted for ISU3102.f90 (code 1) PGI raises an error: > pgf90 -mp -o px ISU3102.f90 PGF90-S-0155-The COLLAPSE expression must be a positive integer constant (ISU3102.f90: 9) 0 inform, 0 warnings, 1 severes, 0 fatal for test ifort (intel) o.k. with a value that is a parameter: > ifort -openmp -o ixp ISU3102p.f90 -liomp5 ISU3102p.f90(9): (col. 7) remark: OpenMP DEFINED LOOP WAS PARALLELIZED. ISU3102p.f90(8): (col. 7) remark: OpenMP DEFINED REGION WAS PARALLELIZED. PGI o.k. with a value that is a parameter: > pgf90 -mp -o pxp ISU3102p.f90 -- Summary: !$omp collapse(m) with non-constant m should give error Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: longb at cray dot com GCC build triplet: x86_64-suse-linux GCC host triplet: x86_64-suse-linux GCC target triplet: x86_64-suse-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40878