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

prefetch/noprefetch

Invites the compiler to issue data prefetches from memory (prefetch) or disables data prefetching (noprefetch). This pragma only applies to Intel® MIC Architecture.

Syntax

#pragma prefetch

#pragma prefetch [var1 [: hint1 [: distance1]] [, var2 [: hint2 [: distance2]]]...]

#pragma noprefetch [var1 [, var2]...]

Arguments

var

Optional memory reference (data to be prefetched)

hint

Optional hint to the compiler to specify the type of prefetch. Possible values are the constants defined in the header xmmintrin.h:

  • _MM_HINT_T0 - for integer data that will be reused

  • _MM_HINT_NT1 - for integer and floating point data that will be reused from L2 cache

  • _MM_HINT_NT2 - for data that will be reused from L3 cache

  • _MM_HINT_NTA - for data that will not be reused

To use this argument, you must also specify var.

distance

Optional integer argument with a value greater than 0. It indicates the number of loop iterations ahead of which a prefetch is issued, before the corresponding load or store instruction. To use this argument, you must also specify var and hint.

Description

The prefetch pragma hints to the compiler to generate data prefetches for some memory references. This affects the heuristics used in the compiler. Prefetching data can minimize the effects of memory latency.

If you specify #pragma prefetch with no arguments, all arrays accessed in the immediately following loop are prefetched.

If the loop includes the expression A(j), placing #pragma prefetch A in front of the loop instructs the compiler to insert prefetches for A(j + d) within the loop. Here, d is the number of iterations ahead of which to prefetch the data, and is determined by the compiler.

To use these directives, compiler option -opt-prefetch (turned on by default if the compiler general optimization level is O2 or higher) must be set.

The noprefetch pragma hints to the compiler not to generate data prefetches for some memory references. This affects the heuristics used in the compiler.

Example

Example 1: Using prefetch pragma

The following example demonstrates how to use the prefetch pragma:

#pragma prefetch htab_p:1:30 
#pragma prefetch htab_p:0:6

// Issue vprefetch1 for htab_p with a distance of 30 vectorized iterations ahead
// Issue vprefetch0 for htab_p with a distance of 6 vectorized iterations ahead
// If pragmas are not present, compiler chooses both distance values 

      for (j=0; j<2*N; j++) {
                  htab_p[i*m1 + j] = -1;
      }

Example 2: Using noprefetch and prefetch pragmas

The following example demonstrates how to use the noprefetch and prefetch pragmas together:

#pragma noprefetch b 
#pragma prefetch a
for(i=0; i<m; i++)
{
  a[i]=b[i]+1;
}

Example 3: Using noprefetch and prefetch pragmas

The following is yet another example of how to use the noprefetch and prefetch pragmas:

for (i=i0; i!=i1; i+=is) {
 
float sum = b[i];
int ip = srow[i];
int c = col[ip];
 
#pragma noprefetch col
#pragma prefetch value:1:80
#pragma prefetch x:1:40
 
for(; ip<srow[i+1]; c=col[++ip])
  sum -= value[ip] * x[c];
  y[i] = sum;
}

Submit feedback on this help topic