- In C/C++, OpenMP directives are speciﬁed by using the
#pragmamechanism provided by the C and C++ standards.
- OpenMP directives for C/C++ are speciﬁed with
#pragmadirectives. The syntax of an OpenMP directive is as follows:
Each directive starts with
#pragma omp directive-name [clause[ [,] clause] ... ] new-line
#pragma omp. The remainder of the directive follows the conventions of the C and C++ standards for compiler directives. In particular, white space can be used before and after the
#, and sometimes white space must be used to separate the words in a directive. Some OpenMP directives may be composed of consecutive
#pragmadirectives if speciﬁed in their syntax.
- Preprocessing tokens following
#pragma ompare subject to macro replacement.
- Directives are case-sensitive. Each of the expressions used in the OpenMP syntax inside of the clauses must be a valid assignment-expression of the base language unless otherwise speciﬁed.
- Directives may not appear in
constexprfunctions or in constant expressions. Variadic parameter packs cannot be expanded into a directive or its clauses except as part of an expression argument to be evaluated by the base language, such as into a function call inside an
- Only one directive-name can be speciﬁed per directive (note that this includes combined directives). The order in which clauses appear on directives is not signiﬁcant. Clauses on directives may be repeated as needed, subject to the restrictions listed in the description of each clause.
- Some clauses accept a list, an extended-list, or a locator-list.
- A list consists of a comma-separated collection of one or more list items. A list item is a variable or an array section.
- An extended-list consists of a comma-separated collection of one or more extended list items. An extended list item is a list item or a function name.
- A locator-list consists of a comma-separated collection of one or more locator list items. A locator list item is any lvalue expression, including variables, or an array section.
- Some executable directives include a structured block. A structured block:
- may contain inﬁnite loops where the point of exit is never reached;
- may halt due to an IEEE exception;
- may contain calls to
abort()or functions with a
_Noreturnspeciﬁer (in C) or a
noreturnattribute (in C/C++);
- may be an expression statement, iteration statement, selection statement, or try block, provided that the corresponding compound statement obtained by enclosing it in
}would be a structured block.
- Stand-alone directives do not have any associated executable user code. Instead, they represent executable statements that typically do not have succinct equivalent statements in the base language. There are some restrictions on the placement of a stand-alone directive within a program. A stand-alone directive may be placed only at a point where a base language executable statement is allowed. A stand-alone directive may not be used in place of the statement following an
- In implementations that support a preprocessor, the
_OPENMPmacro name is deﬁned to have the decimal value
mmare the year and month designations of the version of the OpenMP API that the implementation supports. If a
#undefpreprocessing directive in user code deﬁnes or undeﬁnes the
_OPENMPmacro name, the behavior is unspeciﬁed.