| CF90TM Commands and Directives Reference Manual | ||
|---|---|---|
| Prev Section | Chapter 4. OpenMP Fortran API Directives (UNICOS Systems Only) | Next Section |
Some directives are bound to other directives. A binding specifies the way in which one directive is related to another. For instance, a directive is bound to a second directive if it can appear in the dynamic extent of that second directive. The following rules apply with respect to the dynamic binding of directives:
The DO, SECTIONS, SINGLE, MASTER, and BARRIER directives bind to the dynamically enclosing PARALLEL directive, if one exists.
The ORDERED directive binds to the dynamically enclosing DO directive.
The ATOMIC directive enforces exclusive access with respect to ATOMIC directives in all threads, not just the current team.
The CRITICAL directive enforces exclusive access with respect to CRITICAL directives in all threads, not just the current team.
A directive can never bind to any directive outside the closest enclosing PARALLEL.
Example 1. The directive binding rules call for a BARRIER directive to bind to the closest enclosing PARALLEL directive.
In the following example, the call from MAIN to SUB2 is valid because the BARRIER (in SUB3) binds to the PARALLEL region in SUB2. The call from MAIN to SUB1 is valid because the BARRIER binds to the PARALLEL region in subroutine SUB2.
PROGRAM MAIN
CALL SUB1(2)
CALL SUB2(2)
END
SUBROUTINE SUB1(N)
!$OMP PARALLEL PRIVATE(I) SHARED(N)
!$OMP DO
DO I = 1, N
CALL SUB2(I)
END DO
!$OMP END PARALLEL
END
SUBROUTINE SUB2(K)
!$OMP PARALLEL SHARED(K)
CALL SUB3(K)
!$OMP END PARALLEL
END
SUBROUTINE SUB3(N)
CALL WORK(N)
!$OMP BARRIER
CALL WORK(N)
END |
Example 2. The following program shows inner and outer DO directives that bind to different PARALLEL regions:
!$OMP PARALLEL DEFAULT(SHARED)
!$OMP DO
DO I = 1, N
!$OMP PARALLEL SHARED(I,N)
!$OMP DO
DO J = 1, N
CALL WORK(I,J)
END DO
!$OMP END PARALLEL
END DO
!$OMP END PARALLEL |
A following variation of the preceding example also shows correct binding:
!$OMP PARALLEL DEFAULT(SHARED)
!$OMP DO
DO I = 1, N
CALL SOME_WORK(I,N)
END DO
!$OMP END PARALLEL
SUBROUTINE SOME_WORK(I,N)
!$OMP PARALLEL DEFAULT(SHARED)
!$OMP DO
DO J = 1, N
CALL WORK(I,J)
END DO
!$OMP END PARALLEL
RETURN
END |
| Prev Section | Table of Contents | Title Page | Next Section |
| Data Environment Constructs | Up one level | Directive Nesting |