OpenMP Directive Syntax
2. OpenMP Directive Syntax#
OpenMP directives use base-language mechanisms to specify OpenMP program behavior. In C code, the directives are formed exclusively with pragmas, whereas in C++ code, directives are formed from either pragmas or attributes. Fortran directives are formed with comments in free form and fixed form sources (codes). All of these mechanisms allow the compilation to ignore the OpenMP directives if OpenMP is not supported or enabled.
The OpenMP directive is a combination of the base-language mechanism and a directive-specification , as shown below. The directive-specification consists of the directive-name which may seldomly have arguments, followed by optional clauses . Full details of the syntax can be found in the OpenMP Specification. Illustrations of the syntax is given in the examples.
The formats for combining a base-language mechanism and a directive-specification are:
C/C++ pragmas
#pragma omp directive-specification
C++ attributes
[[omp :: directive(
directive-specification
)]]
[[using omp : directive( directive-specification )]]
Fortran comments
!$omp directive-specification
where c$omp and *$omp may be used in Fortran fixed form sources.
Most OpenMP directives accept clauses that alter the semantics of the directive in some way, and some directives also accept parenthesized arguments that follow the directive name. A clause may just be a keyword (e.g., untied) or it may also accept argument lists (e.g., shared(x,y,z)) and/or optional modifiers (e.g., tofrom in map(tofrom: x,y,z)). Clause modifiers may be “simple” or “complex” – a complex modifier consists of a keyword followed by one or more parameters, bracketed by parentheses, while a simple modifier does not. An example of a complex modifier is the iterator modifier, as in map(iterator(i=0:n),tofrom: p[i]), or the step modifier, as in linear(x: ref, step(4)). In the preceding examples, tofrom and ref are simple modifiers.