Parallel Programming Guide for HP-UX Systems

Data privatization
Privatizing loop variables
Chapter 6116
The save_last directive and pragma allows you to save the final value
of loop_private data objects assigned in the last iteration of the
immediately following loop.
•If
list
(the optional, comma-separated list of loop_private data
objects) is specified, only the final values of those data objects in
list
are saved.
•If
list
is not specified, the final values of all loop_private data
objects assigned in the last loop iteration are saved.
The values for this directive and pragma must be assigned in the last
iteration. If the assignment is executed conditionally, it is your
responsibility to ensure that the condition is met and the assignment
executes. Inaccurate results may occur if the assignment does not
execute on the last iteration. For loop_private arrays, only those
elements of the array assigned on the last iteration are saved.
The form of this directive and pragma is shown in Table 6-3.
save_last must appear immediately before or after the associated
loop_private directive or pragma, or on the same line.
Example 6-7 save_last
The following is a C example of save_last:
#pragma _CNX loop_parallel(ivar=i)
#pragma _CNX loop_private(atemp, x, y)
#pragma _CNX save_last(atemp, x)
for(i=0;i<n;i++) {
if(i==d[i]) atemp = a[i];
if(i==e[i]) atemp = b[i];
if(i==f[i]) atemp = c[i];
a[i] = b[i] + c[i];
b[i] = atemp;
x = atemp * a[i];
y = atemp * c[i];
}
.
.
Table 6-3 Form of save_last directive and pragma
Language Form
Fortran C$DIR SAVE_LAST[(
list
)]
C #pragma _CNX save_last[(
list
)]