Invites the compiler to issue data prefetches from memory (prefetch) or disables data prefetching (noprefetch).
#pragma prefetch #pragma prefetch [var1 [: hint1 [: distance1]] [, var2 [: hint2 [: distance2]]]...] #pragma noprefetch [var1 [, var2]...] |
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:
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. |
The prefetch pragma is supported by Intel® Itanium® processors only. 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 asks 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.
The prefetch pragma affects the immediately following loop provided that the compiler general optimization level is -O1 (Linux* operating systems) or /O1 (Windows* operating systems) or higher. Remember that -O2 or /O2 is the default optimization level.
The noprefetch pragma is also supported by Intel® Itanium® processors only. This pragma hints to the compiler not to generate data prefetches for some memory references. This affects the heuristics used in the compiler.
Example 1: 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 2: 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;
}
Example 3: Using noprefetch, prefetch, memref_control pragmas
The following example, which is for IA-64 architecture only, demonstrates how to use the prefetch, noprefetch, and memref_control pragmas together:
#define SIZE 10000
int prefetch(int *a, int *b)
{
int i, sum = 0;
#pragma memref_control a:l2
#pragma noprefetch a
#pragma prefetch b
for (i = 0; i<SIZE; i++)
sum += a[i] * b[i];
return sum;
}
#include <stdio.h>
int main()
{
int i, arr1[SIZE], arr2[SIZE];
for (i = 0; i<SIZE; i++) {
arr1[i] = i;
arr2[i] = i;
}
printf("Demonstrating the use of prefetch, noprefetch,\n"
"and memref_control pragma together.\n");
prefetch(arr1, arr2);
return 0;
}