Intel® C++ Compiler XE 13.1 User and Reference Guides

vector

Indicates to the compiler that the loop should be vectorized according to the argument keywords always/aligned/assert/unaligned/nontemporal/temporal.

Syntax

#pragma vector {always[assert]|aligned|unaligned|temporal|nontemporal|[no]vecremainder}

#pragma vector nontemporal[(var1[, var2, ...])]

Arguments

always

instructs the compiler to override any efficiency heuristic during the decision to vectorize or not, and vectorize non-unit strides or very unaligned memory accesses; controls the vectorization of the subsequent loop in the program; optionally takes the keyword assert

aligned

instructs the compiler to use aligned data movement instructions for all array references when vectorizing

unaligned

instructs the compiler to use unaligned data movement instructions for all array references when vectorizing

nontemporal

directs the compiler to use non-temporal (that is, streaming) stores on systems based on all supported architectures, unless otherwise specified; optionally takes a comma separated list of variables

On systems based on Intel® MIC Architecture, directs the compiler to generate clevict (cache-line-evict) instructions after the stores based on the non-temporal pragma when the compiler knows that the store addresses are aligned; optionally takes a comma separated list of variables

temporal

directs the compiler to use temporal (that is, non-streaming) stores on systems based on all supported architectures, unless otherwise specified

vecremainder

instructs the compiler to vectorize the remainder loop when the original loop is vectorized

novecremainder

instructs the compiler not to vectorize the remainder loop when the original loop is vectorized

Description

The vector pragma indicates that the loop should be vectorized, if it is legal to do so, ignoring normal heuristic decisions about profitability. The vector pragma takes several argument keywords to specify the kind of loop vectorization required. These keywords are aligned, unaligned, always, temporal, and nontemporal. The compiler does not apply the vector pragma to nested loops, each nested loop needs a preceding pragma statement. Place the pragma before the loop control statement.

Using aligned/unaligned keywords

When the aligned/unaligned argument keyword is used with this pragma, it indicates that the loop should be vectorized using aligned/unaligned data movement instructions for all array references. Specify only one argument keyword: aligned or unaligned.

Caution

If you specify aligned as an argument, you must be sure that the loop is vectorizable using this pragma. Otherwise, the compiler generates incorrect code.

Using always keyword

When the always argument keyword is used, the pragma controls the vectorization of the subsequent loop in the program. If assert is added, the compiler will generate an error-level assertion test to display a message saying that the compiler efficiency heuristics indicate that the loop cannot be vectorized.

Using nontemporal/temporal keywords

The nontemporal and temporal argument keywords are used to control how the "stores" of register contents to storage are performed (streaming versus non-streaming) on systems based on IA-32 and Intel® 64 architectures.

On systems based on Intel® MIC Architecture, #pragma vector nontemporal directs the compiler to generate clevict (cache-line-evict) instructions after the stores based on the non-temporal pragma when the compiler knows that the store addresses are aligned; optionally takes a comma separated list of variables

By default, the compiler automatically determines whether a streaming store should be used for each variable.

Streaming stores may cause significant performance improvements over non-streaming stores for large numbers on certain processors. However, the misuse of streaming stores can significantly degrade performance.

Using [no]vecremainder

If #pragma vector always is specified, the following occurs:

If the vecremainder clause is specified, the compiler vectorizes both the main and remainder loops.

If the novecremainder clause is specified, the compiler vectorizes the main loop, but it does not vectorize the remainder loop.

Note

The pragma vector{always|aligned|unaligned} should be used with care. Overriding the efficiency heuristics of the compiler should only be done if the programmer is absolutely sure that vectorization will improve performance. Furthermore, instructing the compiler to implement all array references with aligned data movement instructions will cause a run-time exception in case some of the access patterns are actually unaligned.

Example

Example 1: Using pragma vector aligned

The loop in the following example uses the aligned argument keyword to request that the loop be vectorized with aligned instructions, as the arrays are declared in such a way that the compiler could not normally prove this would be safe to do so.

void vec_aligned(float *a, int m, int c)
{
  int i;
  // Instruct compiler to ignore assumed vector dependencies.
  #pragma vector aligned
  for (i = 0; i < m; i++)
    a[i] = a[i] * c;
  // Alignment unknown but compiler can still align.
  for (i = 0; i < 100; i++)
    a[i] = a[i] + 1.0f;
}

Example 2: Using pragma vector always

The following example illustrates how to use the vector always pragma.

void vec_always(int *a, int *b, int m)
{
  #pragma vector always
  for(int i = 0; i <= m; i++)
    a[32*i] = b[99*i];
}

Example 3a: Using pragma vector nontemporal

A float-type loop together with the generated assembly is shown in the following example. For large N, significant performance improvements result on Pentium 4 systems over a non-streaming implementation.

float a[1000];
void foo(int N){
  int i;
  #pragma vector nontemporal
  for (i = 0; i < N; i++) {
    a[i] = 1;
  }
}

Example 3b: Using ASM code for the loop body

  .B1.2:
movntps XMMWORD PTR _a[eax], xmm0 
movntps XMMWORD PTR _a[eax+16], xmm0 
add eax, 32 
cmp eax, 4096 
jl .B1.2

Example 4: Using pragma vector nontemporal with variables

The following example illustrates how to use the #pragma vector nontemporal with variables for implementing streaming stores.

double A[1000];
double B[1000];
void foo(int n){
  int i;
#pragma vector nontemporal (A, B)
  for (i=0; i<n; i++){
    A[i] = 0;
    B[i] = i;
  }
}

Submit feedback on this help topic