OpenMP Directives: Directive Scoping

Do we do this now…or do it later? Oh well, let’s get it over with early…

Static (Lexical) Extent:

The code textually enclosed between the beginning and the end of a structured block following a directive.

The static extent of a directives does not span multiple routines or code files.

Orphaned Directive:

An OpenMP directive that appears independently from another enclosing directive is said to be an orphaned directive. It exists outside of another directive’s static (lexical) extent.

An orphaned directive can span routines and possibly code files.

Dynamic Extent:

The dynamic extent of a directive includes both its static (lexical) extent and the extents of its orphaned directives.

Example:

PROGRAM TEST
    ...
!$OMP PARALLEL
    ...
!$OMP DO
    DO I=...
        ...
        CALL SUB1
        ...
    ENDDO
    ...
    CALL SUB2
    ...
!$OMP END PARALLEL
    SUBROUTINE SUB1
    ...
!$OMP CRITICAL
    ...
!$OMP END CRITICAL
    END

    SUBROUTINE SUB2
    ...
!$OMP SECTIONS
    ...
!$OMP END SECTIONS
    ...
    END
STATIC EXTENT
The DO directive occurs within an enclosing parallel region
ORPHANED DIRECTIVES
The CRITICAL and SECTIONS directives occur outside an enclosing parallel region
DYNAMIC EXTENT
The CRITICAL and SECTIONS directives occur within the dynamic extent of the DO and PARALLEL directives.

Why Is This Important?

OpenMP specifies a number of scoping rules on how directives may associate (bind) and nest within each other.

Illegal and/or incorrect programs may result if the OpenMP binding and nesting rules are ignored.

See Directive Binding and Nesting Rules for specific details.