Fortran Restrictions on the do Construct
3.6. Fortran Restrictions on the do Construct#
If an end do directive follows a do-construct in which several DO statements share a DO termination statement, then a do directive can only be specified for the outermost of these DO statements. The following example contains correct usages of loop constructs:
!!%compiler: gfortran
!!%cflags: -fopenmp
! name: fort_do.1
! type: F-fixed
SUBROUTINE WORK(I, J)
INTEGER I,J
END SUBROUTINE WORK
SUBROUTINE DO_GOOD()
INTEGER I, J
REAL A(1000)
DO 100 I = 1,10
!$OMP DO
DO 100 J = 1,10
CALL WORK(I,J)
100 CONTINUE ! !$OMP ENDDO implied here
!$OMP DO
DO 200 J = 1,10
200 A(I) = I + 1
!$OMP ENDDO
!$OMP DO
DO 300 I = 1,10
DO 300 J = 1,10
CALL WORK(I,J)
300 CONTINUE
!$OMP ENDDO
END SUBROUTINE DO_GOOD
The following example is non-conforming because the matching do directive for the end do does not precede the outermost loop:
!!%compiler: gfortran
!!%cflags: -fopenmp
! name: fort_do.2
! type: F-fixed
SUBROUTINE WORK(I, J)
INTEGER I,J
END SUBROUTINE WORK
SUBROUTINE DO_WRONG
INTEGER I, J
DO 100 I = 1,10
!$OMP DO
DO 100 J = 1,10
CALL WORK(I,J)
100 CONTINUE
!$OMP ENDDO
END SUBROUTINE DO_WRONG