Parallel Programming Guide for HP-UX Systems

Troubleshooting
Aliasing
Chapter 9172
Aliasing stop variables
In the following code, the stop variable n becomes a possible alias for
*iptr when &n is passed to foo. This means that n is altered during the
execution of the loop. As a result, the compiler cannot count the number
of iterations and cannot parallelize the loop.
void salex(int *iptr, int n)
{
int i;
foo(&n);
for (i=0; i < n; i++)
iptr[i] += iptr[i];
return;
}
To parallelize the affected loop, eliminate the call to foo, move the call
below the loop. In this case, flow-sensitive analysis takes care of the
aliasing. You can also create a temporary variable as shown below:
void salex(int *iptr, int n)
{
int i, tmp;
foo(&n);
tmp = n;
for (i=0; i < tmp; i++)
iptr[i] += iptr[i];
return;
}
Because tmp is not aliased to iptr, the loop has a fixed stop value and
the compiler parallelizes it.
Global variables
Potential aliases involving global variables cause optimization problems
in many programs. The compiler cannot tell whether another function
causes a global variable to become aliased.
The following code uses a global variable, n, as a stop value. Because n
may have its address taken and assigned to ik outside the scope of the
function, n must be considered a potential alias for *ik. The value of n,
therefore, is altered on any iteration of the loop. The compiler cannot
determine the stop value and cannot parallelize the loop.