10.5. Fortran Restrictions on shared and private Clauses with Common Blocks#

When a named common block is specified in a private, firstprivate, or lastprivate clause of a construct, none of its members may be declared in another data-sharing attribute clause on that construct. The following examples illustrate this point.

The following example is conforming:

!!%compiler: gfortran
!!%cflags: -fopenmp

! name: fort_sp_common.1
! type: F-fixed
      SUBROUTINE COMMON_GOOD()
        COMMON /C/ X,Y
        REAL X, Y

!$OMP   PARALLEL PRIVATE (/C/)
          ! do work here
!$OMP   END PARALLEL
!$OMP   PARALLEL SHARED (X,Y)
          ! do work here
!$OMP   END PARALLEL
      END SUBROUTINE COMMON_GOOD

The following example is also conforming:

!!%compiler: gfortran
!!%cflags: -fopenmp

! name: fort_sp_common.2
! type: F-fixed
      SUBROUTINE COMMON_GOOD2()
        COMMON /C/ X,Y
        REAL X, Y
        INTEGER I
!$OMP   PARALLEL
!$OMP     DO PRIVATE(/C/)
          DO I=1,1000
            ! do work here
          ENDDO
!$OMP     END DO
!$OMP     DO PRIVATE(X)
          DO I=1,1000
            ! do work here
          ENDDO
!$OMP     END DO
!$OMP   END PARALLEL
      END SUBROUTINE COMMON_GOOD2

The following example is conforming:

!!%compiler: gfortran
!!%cflags: -fopenmp

! name: fort_sp_common.3
! type: F-fixed
      SUBROUTINE COMMON_GOOD3()
        COMMON /C/ X,Y
!$OMP   PARALLEL PRIVATE (/C/)
          ! do work here
!$OMP   END PARALLEL
!$OMP   PARALLEL SHARED (/C/)
          ! do work here
!$OMP   END PARALLEL
      END SUBROUTINE COMMON_GOOD3

The following example is non-conforming because x is a constituent element of c:

!!%compiler: gfortran
!!%cflags: -fopenmp

! name: fort_sp_common.4
! type: F-fixed
      SUBROUTINE COMMON_WRONG()
        COMMON /C/ X,Y
! Incorrect because X is a constituent element of C
!$OMP   PARALLEL PRIVATE(/C/), SHARED(X)
          ! do work here
!$OMP   END PARALLEL
      END SUBROUTINE COMMON_WRONG

The following example is non-conforming because a common block may not be declared both shared and private:

!!%compiler: gfortran
!!%cflags: -fopenmp

! name: fort_sp_common.5
! type: F-fixed
      SUBROUTINE COMMON_WRONG2()
        COMMON /C/ X,Y
! Incorrect: common block C cannot be declared both
! shared and private
!$OMP   PARALLEL PRIVATE (/C/), SHARED(/C/)
          ! do work here
!$OMP   END PARALLEL

      END SUBROUTINE COMMON_WRONG2