Intel® C++ Compiler 16.0 User and Reference Guide

vector

Indicates to the compiler that the loop should be vectorized according to the argument keywords.

Syntax

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

#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

Instructs 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

Instructs 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

mask_readwrite

Disables memory speculation causing the generation of masked load and store operations within conditions

nomask_readwrite

Enables memory speculation causing the generate of non-masked loads and stores within conditions

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 the 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 the 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 the 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 the [no]vecremainder keyword

If the vector always pragma and keyword are specified, the following occurs:

Using the [no]mask_readwrite keyword

If the vector pragma and mask_readwrite or nomask_readwrite keyword are specified, the following occurs:

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.

Examples

In the following example, the aligned argument keyword is used to request that the loop be vectorized with aligned instructions.

Note that the arrays are declared in such a way that the compiler could not normally prove this would be safe to vectorize.

Example: Using the vector aligned pragma

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: Using 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: Using vector nontemporal pragma

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

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

Example: 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: Using 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;
  } 
}

See Also