Parallel Programming Guide for HP-UX Systems

Troubleshooting
Aliasing
Chapter 9 171
for (i--; i<n; i++)
iptr[i] += 1;
}
Using hidden aliases as pointers
In the next example, ialex takes the address of j and assigns it to *ip.
Thus, j becomes an alias for *ip and, potentially, for *iptr. Assigned
values to iptr[j] within the loop could alter the value of j. As a result,
the compiler cannot use j as an induction variable and, without an
induction variable, it cannot count the iterations of the loop. When the
compiler cannot find the loop’s iteration count the compiler cannot
parallelize the loop.
int *ip;
void ialex(iptr)
int *iptr;{
int j;
*ip = &j;{
for (j=0; j<2048; j++)
iptr[j] = 107;
}
To parallelize this loop, remove the line of code that takes the address of
j or introduce a temporary variable.
Using a pointer as a loop counter
Compiling the following function, the compiler finds that *j is not an
induction variable. This is because an assignment to iptr[*j] could
alter the value of *j within the loop. The compiler does not parallelize
the loop.
void ialex2(iptr, j, n)
int *iptr;
int *j, n;
{
for (*j=0; *j<n; (*j)++)
iptr[*j] = 107;
}
Again, this problem is solved by introducing a temporary iteration
variable.