HOME
| OPENMP API Specification: Version 5.1 November 2020

2.3.4  Metadirectives

Summary A metadirective is a directive that can specify multiple directive variants of which one may be conditionally selected to replace the metadirective based on the enclosing OpenMP context.

Syntax

SVG-Viewer needed.

The syntax of a metadirective is as follows:  

 
#pragma omp metadirective [clause[ [,] clause] ... ] new-line  

or  

 
#pragma omp begin metadirective [clause[ [,] clause] ... ] new-line 
    stmt(s) 
#pragma omp end metadirective  

where clause is one of the following:  

 
when(context-selector-specification: [directive-variant]) 
default([directive-variant])  

SVG-Viewer needed.

SVG-Viewer needed.

The syntax of a metadirective is as follows:  

 
!$omp metadirective [clause[ [,] clause] ... ]  

or  

 
!$omp begin metadirective [clause[ [,] clause] ... ] 
    stmt(s) 
!$omp end metadirective  

where clause is one of the following:  

 
when(context-selector-specification: [directive-variant]) 
default([directive-variant])  

SVG-Viewer needed.

In the when clause, context-selector-specification specifies a context selector (see Section 2.3.2).

In the when and default clauses, directive-variant has the following form and specifies a directive variant that specifies an OpenMP directive with clauses that apply to it.  

 
 directive-name [clause[ [,] clause] ... ]  

Description A metadirective is replaced by a nothing directive or one of the directive variants specified by the when clauses or the default clause.

If no default clause is specified the effect is as if a default clause without an associated directive variant was specified.

The default clause is treated as a when clause with the specified directive variant, if any, and an always compatible static context selector that has a score lower than the scores associated with any other clause.

If a when clause does not explicitly specify a directive variant it implicitly specifies a nothing directive as the directive variant.

The OpenMP context for a given metadirective is defined according to Section 2.3.1.

The directive variant specified by a when clause is a candidate to replace the metadirective if the static part of the corresponding context selector is compatible with the OpenMP context according to the matching rules defined in Section 2.3.3.

Replacement candidates are ordered according to the following rules in decreasing precedence:

The list of dynamic replacement candidates is the prefix of the sorted list of replacement candidates up to and including the first candidate for which the corresponding when clause has a static context selector.

The first dynamic replacement candidate for which the corresponding when clause has a compatible context selector, according to the matching rules defined in Section 2.3.3, replaces the metadirective.

Expressions that appear in the context selector of a when clause are evaluated if no prior dynamic replacement candidate has a compatible context selector, and the number of times each expression is evaluated is implementation defined. All variables referenced by these expressions are considered to be referenced by the metadirective.

A directive variant that is associated with a when clause may only affect the program if the directive variant is a dynamic replacement candidate.

The begin metadirective directive behaves identically to the metadirective directive, except that the directive syntax for the specified directive variants other than the nothing directive must accept a paired end directive. For any directive variant that is selected to replace the begin metadirective directive, the end metadirective directive will be implicitly replaced by its paired end directive to demarcate the statements that are affected by or are associated with the directive variant. If the nothing directive is selected to replace the begin metadirective directive, its paired end metadirective directive is ignored.

Restrictions Restrictions to metadirectives are as follows: