#pragma omp declare simd

Purpose

The omp declare simd directive is applied to a function to create one or more versions for being called in a SIMD loop.

Syntax

Read syntax diagramSkip visual syntax diagram
   .---------------------------------------------------.   
   |                                    .-+---+------. |   
   |                                    | '-,-'      | |   
   V  (1)                               V            | |   
>>---------#--pragma--omp declare simd----+--------+-+-+-------><
                                          '-clause-'       

Notes:
  1. Multiple omp declare simd directives are delimited by line feeds.
Read syntax diagramSkip visual syntax diagram
>>-function_definition_or_declaration--------------------------><

Parameters

clause is any of the following clauses:
aligned(list[:alignment])
Declares that the object to which argument in list points is byte aligned according to the number of bytes expressed by alignment. alignment must be a constant positive integer expression. A list item cannot appear in more than one aligned clause.
inbranch 1
Specifies that the SIMD version of the function is always called from inside a conditional statement of a SIMD loop.
notinbranch 1
Specifies that the SIMD version of the function is never called from inside a conditional statement of a SIMD loop.
linear(list[:linear-step]) 2
Declares the data variables in list to be private to each SIMD lane and to have a linear relationship with the iteration space 3 of a loop. linear-step must be a constant integer expression or an integer parameter that is specified in a uniform clause on the directive.
simdlen(length)
Specifies the preferred number of concurrent arguments for the function, that is, the number of iterations that are desired for each SIMD chunk. The number of concurrent arguments for the SIMD version of a function that is created through the omp declare simd directive is implementation defined. length must be a constant positive integer expression.
You can specify at most one simdlen clause on an omp declare simd directive.
uniform(list) 2
Declares each argument in list to have an invariant value for all concurrent invocations of the function during the execution of a single SIMD loop.
Notes:
  1. You cannot specify both the inbranch and notinbranch clauses.
  2. You can specify an argument in list in at most one of uniform or linear clause.
  3. See Note 2 in the #pragma omp simd topic.

Usage

The omp declare simd directive is a declarative directive. A function can have multiple omp declare simd directives.

Rules

The function body must be a structured block.

A program that branches into or out of the function is nonconforming.

The execution of the function cannot have any side effects that alter the execution for concurrent iterations of a SIMD chunk.

When a function is called from a SIMD loop, the execution of the function cannot result in the execution of an OpenMP construct except for an ordered construct with the simd clause.

Examples

Example 1

In the following example, the omp declare simd directive on the min function creates a SIMD version of the function. The SIMD version of the min function processes multiple arguments concurrently. The number of concurrent arguments for the SIMD version of the function that is created through the omp declare simd directive is implementation defined.

void findmin (int *a, int *b, int *c) {
  #pragma omp simd
  for (i=0; i<N; i++)
  c[i] = min(a[i], b[i]);
}

#pragma omp declare simd 
  int min (int a, int b) { 
  return a < b ? a : b; 
}
Example 2
In the following example, the omp declare simd simdlen(4) directive specifies that the SIMD version of the min function processes four arguments concurrently, that is, four iterations are desired for each SIMD chunk.
void findmin (int *a, int *b, int *c) {
  #pragma omp simd
  for (i=0; i<N; i++)
  c[i] = min(a[i], b[i]);
}

#pragma omp declare simd simdlen(4)
  int min (int a, int b) { 
  return a < b ? a : b; 
}


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us