HOME
| OPENMP API Specification: Version 5.0 November 2018

2.9.3  SIMD Directives

2.9.3.1 simd Construct

SummaryThe simd construct can be applied to a loop to indicate that the loop can be transformed into a SIMD loop (that is, multiple iterations of the loop can be executed concurrently using SIMD instructions).

Syntax

The syntax of the simd construct is as follows:

SVG-Viewer needed.

 

 
#pragma omp simd [clause[ [,] clause] ... ] new-line 
   for-loops  

where clause is one of the following:  

 
if([simd :] scalar-expression) 
safelen(length) 
simdlen(length) 
linear(list[ : linear-step]) 
aligned(list[ : alignment]) 
nontemporal(list) 
private(list) 
lastprivate([ lastprivate-modifier:] list) 
reduction([ reduction-modifier,]reduction-identifier : list) 
collapse(n) 
order(concurrent)  

The simd directive places restrictions on the structure of the associated for-loops. Specifically, all associated for-loops must have canonical loop form (Section 2.9.1 on page 271).

SVG-Viewer needed.

SVG-Viewer needed.

 

 
!$omp simd [clause[ [,] clause ... ] 
   do-loops 
[!$omp end simd]  

where clause is one of the following:  

 
if([simd :] scalar-logical-expression) 
safelen(length) 
simdlen(length) 
linear(list[ : linear-step]) 
aligned(list[ : alignment]) 
nontemporal(list) 
private(list) 
lastprivate([ lastprivate-modifier:] list) 
reduction([ reduction-modifier,]reduction-identifier : list) 
collapse(n) 
order(concurrent)  

If an end simd directive is not specified, an end simd directive is assumed at the end of the do-loops.

The simd directive places restrictions on the structure of all associated do-loops. Specifically, all associated do-loops must have canonical loop form (see Section 2.9.1 on page 271).

SVG-Viewer needed.

BindingA simd region binds to the current task region. The binding thread set of the simd region is the current team.

DescriptionThe simd construct enables the execution of multiple iterations of the associated loops concurrently by means of SIMD instructions. The collapse clause may be used to specify how many loops are associated with the construct. The parameter of the collapse clause must be a constant positive integer expression. If no collapse clause is present, the only loop that is associated with the simd construct is the one that immediately follows the directive.

If more than one loop is associated with the simd construct, then the iterations of all associated loops are collapsed into one larger iteration space that is then executed with SIMD instructions. The sequential execution of the iterations in all associated loops determines the order of the iterations in the collapsed iteration space.

If more than one loop is associated with the simd construct then the number of times that any intervening code between any two associated loops will be executed is unspecified but will be at least once per iteration of the loop enclosing the intervening code and at most once per iteration of the innermost loop associated with the construct. If the iteration count of any loop that is associated with the simd construct is zero and that loop does not enclose the intervening code, the behavior is unspecified.

The integer type (or kind, for Fortran) used to compute the iteration count for the collapsed loop is implementation defined.

A SIMD loop has logical iterations numbered 0,1,...,N-1 where N is the number of loop iterations, and the logical numbering denotes the sequence in which the iterations would be executed if the associated loop(s) were executed with no SIMD instructions. At the beginning of each logical iteration, the loop iteration variable of each associated loop has the value that it would have if the set of the associated loop(s) were executed sequentially. The number of iterations that are executed concurrently at any given time is implementation defined. Each concurrent iteration will be executed by a different SIMD lane. Each set of concurrent iterations is a SIMD chunk. Lexical forward dependencies in the iterations of the original loop must be preserved within each SIMD chunk.

The safelen clause specifies that no two concurrent iterations within a SIMD chunk can have a distance in the logical iteration space that is greater than or equal to the value given in the clause. The parameter of the safelen clause must be a constant positive integer expression. The simdlen clause specifies the preferred number of iterations to be executed concurrently unless an if clause is present and evaluates to false, in which case the preferred number of iterations to be executed concurrently is one. The parameter of the simdlen clause must be a constant positive integer expression.

SVG-Viewer needed.

The aligned clause declares that the object to which each list item points is aligned to the number of bytes expressed in the optional parameter of the aligned clause.

SVG-Viewer needed.

SVG-Viewer needed.

The aligned clause declares that the location of each list item is aligned to the number of bytes expressed in the optional parameter of the aligned clause.

SVG-Viewer needed.

The optional parameter of the aligned clause, alignment, must be a constant positive integer expression. If no optional parameter is specified, implementation-defined default alignments for SIMD instructions on the target platforms are assumed.

The nontemporal clause specifies that accesses to the storage locations to which the list items refer have low temporal locality across the iterations in which those storage locations are accessed.

Restrictions

Cross References

2.9.3.2 Worksharing-Loop SIMD Construct

SummaryThe worksharing-loop SIMD construct specifies that the iterations of one or more associated loops will be distributed across threads that already exist in the team and that the iterations executed by each thread can also be executed concurrently using SIMD instructions. The worksharing-loop SIMD construct is a composite construct.

Syntax

SVG-Viewer needed.

 

 
#pragma omp for simd [clause[ [,] clause] ... ] new-line 
   for-loops  

where clause can be any of the clauses accepted by the for or simd directives with identical meanings and restrictions.

SVG-Viewer needed.

SVG-Viewer needed.

 

 
!$omp do simd [clause[ [,] clause] ... ] 
   do-loops 
[!$omp end do simd [nowait] ]  

where clause can be any of the clauses accepted by the simd or do directives, with identical meanings and restrictions.

If an end do simd directive is not specified, an end do simd directive is assumed at the end of the do-loops.

SVG-Viewer needed.

DescriptionThe worksharing-loop SIMD construct will first distribute the iterations of the associated loop(s) across the implicit tasks of the parallel region in a manner consistent with any clauses that apply to the worksharing-loop construct. The resulting chunks of iterations will then be converted to a SIMD loop in a manner consistent with any clauses that apply to the simd construct.

Execution Model EventsThis composite construct generates the same events as the worksharing-loop construct.

Tool CallbacksThis composite construct dispatches the same callbacks as the worksharing-loop construct.

RestrictionsAll restrictions to the worksharing-loop construct and the simd construct apply to the worksharing-loop SIMD construct. In addition, the following restrictions apply:

Cross References

2.9.3.3 declare simd Directive

SummaryThe declare simd directive can be applied to a function (C, C++ and Fortran) or a subroutine (Fortran) to enable the creation of one or more versions that can process multiple arguments using SIMD instructions from a single invocation in a SIMD loop. The declare simd directive is a declarative directive. There may be multiple declare simd directives for a function (C, C++, Fortran) or subroutine (Fortran).

Syntax

The syntax of the declare simd directive is as follows:

SVG-Viewer needed.

 

 
#pragma omp declare simd [clause[ [,] clause] ... ] new-line 
[#pragma omp declare simd [clause[ [,] clause] ... ] new-line] 
[ ... ] 
   function definition or declaration  

where clause is one of the following:  

 
simdlen(length) 
linear(linear-list[ : linear-step]) 
aligned(argument-list[ : alignment]) 
uniform(argument-list) 
inbranch 
notinbranch  

SVG-Viewer needed.

SVG-Viewer needed.

 

 
!$omp declare simd [(proc-name)] [clause[ [,] clause] ... ]  

where clause is one of the following:  

 
simdlen(length) 
linear(linear-list[ : linear-step]) 
aligned(argument-list[ : alignment]) 
uniform(argument-list) 
inbranch 
notinbranch  

SVG-Viewer needed.

Description

SVG-Viewer needed.

The use of one or more declare simd directives immediately prior to a function declaration or definition enables the creation of corresponding SIMD versions of the associated function that can be used to process multiple arguments from a single invocation in a SIMD loop concurrently.

The expressions appearing in the clauses of each directive are evaluated in the scope of the arguments of the function declaration or definition.

SVG-Viewer needed.

SVG-Viewer needed.

The use of one or more declare simd directives for a specified subroutine or function enables the creation of corresponding SIMD versions of the subroutine or function that can be used to process multiple arguments from a single invocation in a SIMD loop concurrently.

SVG-Viewer needed.

If a SIMD version is created, the number of concurrent arguments for the function is determined by the simdlen clause. If the simdlen clause is used its value corresponds to the number of concurrent arguments of the function. The parameter of the simdlen clause must be a constant positive integer expression. Otherwise, the number of concurrent arguments for the function is implementation defined.

SVG-Viewer needed.

The special this pointer can be used as if it was one of the arguments to the function in any of the linear, aligned, or uniform clauses.

SVG-Viewer needed.

The uniform clause declares one or more arguments to have an invariant value for all concurrent invocations of the function in the execution of a single SIMD loop.

SVG-Viewer needed.

The aligned clause declares that the object to which each list item points is aligned to the number of bytes expressed in the optional parameter of the aligned clause.

SVG-Viewer needed.

SVG-Viewer needed.

The aligned clause declares that the target of each list item is aligned to the number of bytes expressed in the optional parameter of the aligned clause.

SVG-Viewer needed.

The optional parameter of the aligned clause, alignment, must be a constant positive integer expression. If no optional parameter is specified, implementation-defined default alignments for SIMD instructions on the target platforms are assumed.

The inbranch clause specifies that the SIMD version of the function will always be called from inside a conditional statement of a SIMD loop. The notinbranch clause specifies that the SIMD version of the function will never be called from inside a conditional statement of a SIMD loop. If neither clause is specified, then the SIMD version of the function may or may not be called from inside a conditional statement of a SIMD loop.

Restrictions

Cross References