HP C A.06.05 Reference Manual
Compiling and Running HP C Programs
Pragmas
Chapter 9 233
Example:
The function below prefetches
ia
and
b
, but not
a[ia[i]]
when compiled with +O2
+Odataprefetch +DA2.0 (or +DA2.0W).
testprefc2(int n, double *a, int *ia, double *b)
{
for (int i=0; i<n, i++) {
b[i]=a[ia[i]];
}
}
Recording this routine as
#define USER_SPECIFIED 30
testprefc2(int n, double *a, int *ia, double *b)
{
int dist=(int)USER_SPECIFIED;
int nend=max(0,n_dist); /* so as not to read past the end of is */
for(i=0;i<nend;i++) /* original loop is for (i=0;i<n;i++) */
{
#pragma prefetch ia[i+4*dist]
#pragma prefetch a[ia[i+dist]]
b[i]=a[ia[i]];
}
/* finish up last part with no prefetching */
for (int i=nend;i<n;i++)
b[i]=a[ia[i]];
}