OpenMP-Examples/Examples_lastprivate.tex
2020-06-26 07:54:45 -07:00

25 lines
894 B
TeX

\pagebreak
\section{The \code{lastprivate} Clause}
\label{sec:lastprivate}
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 in a \code{lastprivate}
clause so that the values of the variables are the same as when the loop is executed
sequentially.
\cexample{lastprivate}{1}
\fexample{lastprivate}{1}
\clearpage
The next example illustrates the use of the \code{conditional} modifier in
a \code{lastprivate} clause to return the last value when it may not come from
the last iteration of a loop.
That is, users can preserve the serial equivalence semantics of the loop.
The conditional lastprivate ensures the final value of the variable after the loop
is as if the loop iterations were executed in a sequential order.
\cexample[5.0]{lastprivate}{2}
\ffreeexample[5.0]{lastprivate}{2}