HOME
| OPENMP API Specification: "Version 5.2 -- GIT rev 95b2e3a44"

3.1  Directive Format

This section defines several categories of directives and constructs. OpenMP directives are specified with a directive-specification. A directive-specification consists of the directive-specifier and any clauses that may optionally be associated with the OpenMP directive:  

 
directive-specifier [[,] clause[ [,] clause] ... ]  

The directive-specifier is:  

 
directive-name  

or for argument-modified directives:  

 
directive-name[(directive-arguments)]  
White space in a directive-name is not optional.

Some OpenMP directives specify a paired end directive, where the directive-name of the paired end directives is:

The directive-specification of a paired end directive may include one or more optional end-clause:  

 
directive-specifier [[,] end-clause[ [,] end-clause]...]  

where end-clause has the end-clause property, which explicitly allows it on a paired end directive.

An OpenMP directive may be specified as a pragma directive:
 
#pragma omp directive-specification new-line  

or a pragma operator:  

 
_Pragma("omp directive-specification")  

The use of omp as the first preprocessing token of a pragma directive is reserved for OpenMP directives that are defined in this specification. The use of ompx as the first preprocessing token of a pragma directive is reserved for implementation-defined extensions to the OpenMP directives.

In this directive, directive-name is depobj, directive-arguments is o. directive-specifier is depobj(o) and directive-specification is depobj(o) depend(inout: d).
 
#pragma omp depobj(o) depend(inout: d)  

White space can be used before and after the #. Preprocessing tokens in directive-specification of #pragma and _Pragma pragmas are subject to macro expansion.

In C++11 and higher, an OpenMP directive may be specified as a C++ attribute specifier:
 
[[ omp :: directive-attr ]]  

or  

 
[[ using omp : directive-attr ]]  

where directive-attr is  

 
directive( directive-specification )  

or  

 
sequence( [omp::]directive-attr [[, [omp::]directive-attr] ... ] )  

Multiple attributes on the same statement are allowed. Attribute directives that apply to the same statement are unordered unless the sequence attribute is specified, in which case the right-to-left ordering applies. The omp:: namespace qualifier within a sequence attribute is optional. The application of multiple attributes in a sequence attribute is ordered as if each directive had been specified as a pragma directive on subsequent lines.

This example shows the expected transformation:
 
[[ omp::sequence(directive(parallel), directive(for)) ]] 
for(...) {} 
// becomes 
#pragma omp parallel 
#pragma omp for 
for(...) {}  

The use of omp as the attribute namespace of an attribute specifier, or as the optional namespace qualifier within a sequence attribute, is reserved for OpenMP directives that are defined in this specification. The use of ompx as the attribute namespace of an attribute specifier, or as the optional namespace qualifier within a sequence attribute, is reserved for implementation-defined extensions to the OpenMP directives.

The pragma and attribute forms are interchangeable for any OpenMP directive. Some OpenMP directives may be composed of consecutive attribute specifiers if specified in their syntax. Any two consecutive attribute specifiers may be reordered or expressed as a single attribute specifier, as permitted by the base language, without changing the behavior of the OpenMP directive.

Directives are case-sensitive. Each expression used in the OpenMP syntax inside of a clause must be a valid assignment-expression of the base language unless otherwise specified.
Directives may not appear in constexpr functions or in constant expressions.
An OpenMP directive for Fortran is specified with a stylized comment as follows:
 
sentinel directive-specification  

All OpenMP compiler directives must begin with a directive sentinel. The format of a sentinel differs between fixed form and free form source files, as described in Section 3.1.1 and Section 3.1.2. In order to simplify the presentation, free form is used for the syntax of OpenMP directives for Fortran throughout this document, except as noted.

Directives are case insensitive. Directives cannot be embedded within continued statements, and statements cannot be embedded within directives. Each expression used in the OpenMP syntax inside of a clause must be a valid expression of the base language unless otherwise specified.

A directive may be categorized as one of the following:

Base language code can be associated with directives. The directive’s association can be categorized as:

A directive and its associated base language code constitute a syntactic formation that follows the syntax given below. The end-directive in a specified formation refers to the paired end directive for the directive. An OpenMP construct is a formation for which the directive is executable.

Directives with an association of none are not associated with any base language code. The resulting formation therefore has the following syntax:  

 
directive  

Formations that result from a block-associated directive have the following syntax:

 
directive 
  structured-block  
 
directive 
  structured-block 
[end-directive]  

If structured-block is a loosely structured block, end-directive is required. If structured-block is a strictly structured block, end-directive is optional. An end-directive that immediately follows a directive and its associated strictly structured block is always paired with that directive.

Loop-associated directives are block-associated directives for which the associated structured-block is loop-nest, a canonical loop nest.

For a loop-associated directive, the paired end directive is optional.
Formations that result from a declaration-associated directive have the following syntax:
 
declaration-associated-specification  

where declaration-associated-specification is either:  

 
directive 
  function-definition-or-declaration  

or:  

 
directive 
declaration-associated-specification  

In all cases the directive is associated with the function-definition-or-declaration.

The formation that results from a declaration-associated directive in Fortran has the same syntax as the formation for a directive with an association of none.

If a directive appears in the specification part of a module then the behavior is as if that directive appears after any references to that module.

The formation that results from a delimited directive has the following syntax:  

 
directive 
  base-language-code 
end-directive  

Separating directives may be used to separate a structured-block into multiple structured-block-sequences.

Separating directives and the containing structured block have the following syntax:  

 
structured-block-sequence 
directive 
structured-block-sequence 
[directive 
structured-block-sequence ...]  

wrapped in a single compound statement for C/C++ or optionally wrapped in a single BLOCK construct for Fortran.

Restrictions

Restrictions to directive format are as follows: