simd

The simd pragma enforces vectorization of innermost loops.

Syntax

#pragma simd [clause[ [,] clause]...]

where clause can be any of the following:

Arguments

vectorlength(n1[, n2]...)

n is a vector length (VL). It must be an integer that is a power of 2; the value must be 2, 4, 8, or 16. If you specify more than one n, the vectorizor will choose the VL from the values specified.

Causes each iteration in the vector loop to execute the computation equivalent to n iterations of scalar loop execution. Multiple vectorlength clauses are merged as a union.

private(var1[, var2]...)

var is a scalar variable.

Causes each variable to be private to each iteration of a loop. Unless the compiler can prove that initial and last values are unused, the initial value is broadcasted to all private instances, and the last value is copied out from the last iteration instance. Multiple private clauses are merged as a union.

linear(var1:step1 [,var2:step2]...)

var is a scalar variable.

step is a compile-time positive, integer constant expression.

For each iteration of a scalar loop, var1 is incremented by step1, var2 is incremented by step2, and so on. Therefore, every iteration of the vector loop increments the variables by VL*step1, VL*step2, …, to VL*stepN, respectively. If more than one step is specified for a var, a compile-time error occurs. Multiple linear clauses are merged as a union.

reduction(oper:var1 [,var2]…)

oper is a reduction operator.

var is a scalar variable.

Applies the vector reduction indicated by oper to var1, var2, …, varN. The simd pragma may have multiple reduction clauses with the same or different operators. If more than one reduction operator is associated with a var, a compile-time error occurs.

[no]assert

Directs the compiler to assert or not to assert when the vectorization fails. The default is noassert. If this clause is specified more than once, a compile-time error occurs.

Description

The simd pragma is used to guide the compiler to vectorize more loops. Vectorization using the simd pragma complements (but does not replace) the fully automatic approach.

If you specify the simd pragma with no clause, default rules are in effect for variable attributes, vector length, and so forth

You can only specify a particular variable in at most one instance of a private, linear, or reduction clause.

If the compiler is unable to vectorize a loop, a warning will be emitted (use assert clause to make it an error).

If the vectorizer has to stop vectorizing a loop for some reason, the fast floating-point model is used for the SIMD loop.

Note that the simd pragma may not affect all auto-vectorizable loops. Some of these loops do not have a way to describe the SIMD vector semantics.

The following restrictions apply to the simd pragma:

To disable transformations that enables more vectorization, specify options -no-vec -no-simd (Linux* and Mac OS* X) or /Qvec- /Qsimd- (Windows*)

Example

Using #pragma simd.

In the example, the function add_floats() uses too many unknown pointers for the compiler's automatic runtime independence check optimization to kick-in. The programmer can enforce the vectorization of this loop by using #pragma simd and avoid the overhead of runtime check:

 void add_floats(float *a, float *b, float *c, float *d, float *e, int n){
  int i;
#pragma simd
  for (i=0; i<n; i++){
    a[i] = a[i] + b[i] + c[i] + d[i] + e[i];
  }
}

See Also

Submit feedback on this help topic

Copyright © 1996-2010, Intel Corporation. All rights reserved.