The simd pragma enforces vectorization of loops.
#pragma simd [clause[ [,] clause]...] |
clause |
clause can be any of the following:
|
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.
Without explicit vectorlength() and vectorlengthfor() clauses, compiler will choose a vectorlength using its own cost model. Misclassification of variables into private, firstprivate, lastprivate, linear, and reduction, or lack of appropriate classification of variables may lead to unintended consequences such as runtime failures and/or incorrect result.
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:
The countable loop for the simd pragma has to conform to the for-loop style of an OpenMP worksharing loop construct. Additionally, the loop control variable must be a signed integer type.
The vector values must be signed 8-, 16-, 32-, or 64-bit integers, single or double-precision floating point numbers, or single or double-precision complex numbers.
A SIMD loop may contain another loop (for, while, do-while) in it. Goto out of such inner loops are not supported. Break and continue are supported. Note that inlining can create such an inner loop, which may not be obvious at the source level.
A SIMD loop performs memory references unconditionally. Therefore, all address computations must result in valid memory addresses, even though such locations may not be accessed if the loop is executed sequentially.
To disable transformations that enables more vectorization, specify options -no-vec -no-simd (Linux* and Mac OS* X) or /Qvec- /Qsimd- (Windows*)
User-mandated vectorization, also called SIMD vectorization can assert or not assert an error if a #pragma simd annotated loop fails to vectorize. By default #pragma simd is set to noassert, and the compiler will issue a warning if the loop fails to vectorize. To direct the compiler to assert an error when the #pragma simd annotated loop fails to vectorize, add the assert clause to the #pragma simd. If a #pragma simd annotated loop is not vectorized by the compiler, the loop holds its serial semantics.
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];
}
}
Copyright © 1996-2011, Intel Corporation. All rights reserved.