ORDERED (TU*X only)

OpenMP Parallel Compiler Directive: Specifies a block of code to be executed in the order in which iterations would be executed in sequential execution.

Syntax

c$OMP ORDERED
     block
c$OMP ORDERED


c
Is one of the following: C (or c), !, or * (see Syntax Rules for Parallel Directives).


block
Is a structured block (section) of statements or constructs. You cannot branch into or out of the block.

Rules and Behavior

An ORDERED directive can appear only in the dynamic extent of a DO or PARALLEL DO directive. The DO directive to which the ordered section binds must have the ORDERED clause specified.

An iteration of a loop using a DO directive must not execute the same ORDERED directive more than once, and it must not execute more than one ORDERED directive.

One thread is allowed in an ordered section at a time. Threads are allowed to enter in the order of the loop iterations. No thread can enter an ordered section until it can be guaranteed that all previous iterations have completed or will never execute an ordered section. This sequentializes and orders code within ordered sections while allowing code outside the section to run in parallel.

Ordered sections that bind to different DO directives are independent of each other.

See Also: Parallel Directives for Tru64 UNIX Systems, OpenMP Fortran API Compiler Directives (TU*X only), Compaq Fortran Parallel Compiler Directives (TU*X only)

Examples

Ordered sections are useful for sequentially ordering the output from work that is done in parallel. Assuming that a reentrant I/O library exists, the following program prints out the indexes in sequential order:

  c$OMP DO ORDERED SCHEDULE(DYNAMIC)
        DO I=LB,UB,ST
          CALL WORK(I)
        END DO
        ...
        SUBROUTINE WORK(K)
  c$OMP ORDERED
        WRITE(*,*) K
  c$OMP END ORDERED