The Argument Alias Problem
- In Fortran, it is a mistake to invoke copy with overlapping arguments. The compiler will perform optimizations assuming A and B are not aliases over the computational range.
- In C, argument aliases are allowed. Therefore optimizations (SWP) changing the original order of loads and stores are not possible. There are several ways to remove this restriction:
- the ivdep pragma
- the compiler optimization flag: -OPT:alias=memory-access-model
- the restrict keyword
void copy(double *a, double *b, int n)
for(i=1; i<n; i++) b[i] = a[i];
In Fortran, compiler assumes
In C, compiler assumes pointers a
and b can point to the same address