HOME
| OPENMP API Specification: Version 5.0 November 2018

2.3.5  declare variant Directive

SummaryThe declare variant directive declares a specialized variant of a base function and specifies the context in which that specialized variant is used. The declare variant directive is a declarative directive.

Syntax

SVG-Viewer needed.

The syntax of the declare variant directive is as follows:  

 
#pragma omp declare variant(variant-func-id) clause new-line 
[#pragma omp declare variant(variant-func-id) clause new-line] 
[ ... ] 
   function definition or declaration  

where clause is one of the following:  

 
match(context-selector-specification)  

and where variant-func-id is the name of a function variant that is either a base language identifier or, for C++, a template-id.

SVG-Viewer needed.

SVG-Viewer needed.

The syntax of the declare variant directive is as follows:  

 
!$omp declare variant([base-proc-name:]variant-proc-name) clause  

where clause is one of the following:  

 
match(context-selector-specification)  

and where variant-proc-name is the name of a function variant that is a base language identifier.

SVG-Viewer needed.

DescriptionThe declare variant directive declares the base function to have the specified function variant. The context selector in the match clause is associated with the variant. The OpenMP context for a call to a given base function is defined according to Section 2.3.1. If the context selector that is associated with a declared function variant is compatible with the OpenMP context of a call to a base function according to the matching rules defined in Section 2.3.3 then a call to the variant is a candidate to replace the base function call. For any call to the base function for which candidate variants exist, the variant with the highest score is selected from all compatible variants. If multiple variants have the highest score, the selected variant is implementation defined. If a compatible variant exists, the call to the base function is replaced with a call to the selected variant. If no compatible variants exist then the call to the base function is not changed.

Different declare variant directives may be specified for different declarations of the same base function.

Any differences that the specific OpenMP context requires in the prototype of the variant from the base function prototype are implementation defined.

SVG-Viewer needed.

The function variant is determined by base language standard name lookup rules ([basic.lookup]) of variant-func-id with arguments that correspond to the argument types in the base function declaration.

The variant-func-id and any expressions inside of the match clause are interpreted as if they appeared at the scope of the trailing return type of the base function.

SVG-Viewer needed.

RestrictionsRestrictions to the declare variant directive are as follows:

Cross References