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.
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:
A
candidate
is
before
another
one
if
the
score
associated
with
the
context
selector
of
the
corresponding
when
clause
is
higher.
A
candidate
that
was
explicitly
specified
is
before
one
that
was
implicitly
specified.
Candidates
are
ordered
according
to
the
order
in
which
they
lexically
appear
on
the
metadirective.
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 beginmetadirective 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 enddirective. For any directive variant that is selected to replace the beginmetadirective
directive, the endmetadirective directive will be implicitly replaced by its paired enddirective to
demarcate the statements that are affected by or are associated with the directive variant. If the nothing
directive is selected to replace the beginmetadirective directive, its paired endmetadirective
directive is ignored.
Restrictions
Restrictions to metadirectives are as follows:
The directive variant appearing in a when or default clause must not specify a metadirective,
beginmetadirective, or endmetadirective directive.
∙ The directive variant that appears in a when or default clause must not specify a
begindeclarevariant or enddeclarevariant.
The context selector that appears in a when clause must not specify any properties for the simd
selector.
Replacement of the metadirective with the directive variant associated with any of the dynamic
replacement candidates must result in a conforming OpenMP program.
Insertion of user code at the location of a metadirective must be allowed if the first dynamic replacement
candidate does not have a static context selector.
All items must be executable directives if the first dynamic replacement candidate does not have a static
context selector.
Any directive variant that is specified by a when or default clause on a beginmetadirective
directive must be an OpenMP directive that has a paired enddirective or must be the nothing
directive, and the beginmetadirective directive must have a paired endmetadirective
directive.
The default clause may appear at most once on a metadirective.