Parallel Programming Guide for HP-UX Systems

Troubleshooting
Aliasing
Chapter 9 173
int n, *ik;
void foo(int *ik)
{
int i;
for (i=0; i<n; i++)
ik[i]=i;
}
Using a temporary local variable solves the problem.
int n;
void foo(int *ik)
{
int i,stop = n;
for (i=0; i<stop; ++i)
ik[i]=i;
}
If ik is a global variable instead of a pointer, the problem does not occur.
Global variables do not cause aliasing problems except when pointers are
involved. The following code is parallelized:
int n, ik[1000];
void foo()
{
int i;
for (i=0; i<n; i++)
ik[i] = i;
}