Export (0) Print
Expand All

A.6 Using the lastprivate Clause 

Correct execution sometimes depends on the value that the last iteration of a loop assigns to a variable. Such programs must list all such variables as arguments to a lastprivate clause (Section on page 27) so that the values of the variables are the same as when the loop is executed sequentially.

#pragma omp parallel
   #pragma omp for lastprivate(i)
      for (i=0; i<n-1; i++)
         a[i] = b[i] + b[i+1];

In the preceding example, the value of i at the end of the parallel region will equal n–1, as in the sequential case.

Community Additions

© 2015 Microsoft