Parallel Programming Guide for HP-UX Systems

Troubleshooting
Aliasing
Chapter 9170
+Optrs_ansi
+Optrs_strongly_typed
Iteration and stop values
Aliasing a variable in an array subscript can make it unsafe for the
compiler to parallelize a loop. Below are several situations that can
prevent parallelization.
Using potential aliases as addresses of variables
In the following example, the code passes &j to getval; getval can use
that address in any number of ways, including possibly assigning it to
iptr. Even though iptr is not passed to getval, getval might still
access it as a global variable or through another alias. This situation
makes j a potential alias for *iptr.
void subex(iptr, n, j)
int *iptr, n, j;
{
n = getval(&j,n);
for (j--; j<n; j++)
iptr[j] += 1;
}
This potential alias means that j and iptr[j] might occupy the same
memory space for some value of j. The assignment to iptr[j] on that
iteration would also change the value of j itself. The possible alteration
of j prevents the compiler from safely parallelizing the loop. In this case,
the Optimization Report says that no induction variable could be found
for the loop, and the compiler does not parallelize the loop.
Avoid taking the address of any variable that is used as the iteration
variable for a loop. To parallelize the loop in subex, use a temporary
variable i as shown in the following code:
void subex(iptr, n, j)
int *iptr, n, j;
{
int i;
n = getval(&j,n);
i=j;