OpenMP Directives: Synchronization Constructs: ORDERED Directive
Purpose:
-
The ORDERED directive specifies that iterations of the enclosed loop will be executed in the same order as if they were executed on a serial processor.
-
Threads will need to wait before executing their chunk of iterations if previous iterations haven’t completed yet.
-
Used within a DO / for loop with an ORDERED clause.
-
The ORDERED directive provides a way to “fine tune” where ordering is to be applied within a loop. Otherwise, it is not required.
Format:
Fortran
!$OMP DO ORDERED [clauses...] (loop region) !$OMP ORDERED (block) !$OMP END ORDERED (end of loop region) !$OMP END DO
C/C++
#pragma omp for ordered [clauses...] (loop region) #pragma omp ordered newline structured_block (endo of loop region)
Restrictions:
- An ORDERED directive can only appear in the dynamic extent of the following directives:
- DO or PARALLEL DO (Fortran)
- for or parallel for (C/C++)
-
Only one thread is allowed in an ordered section at any time.
-
It is illegal to branch into or out of an ORDERED block.
-
An iteration of a loop must not execute the same ORDERED directive more than once, and it must not execute more than one ORDERED directive.
- A loop which contains an ORDERED directive, must be a loop with an ORDERED clause.




