<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">%\pagebreak
\section{\kcode{copyprivate} Clause}
\label{sec:copyprivate}
\index{clauses!copyprivate@\kcode{copyprivate}}
\index{copyprivate clause@\kcode{copyprivate} clause}

The \kcode{copyprivate} clause can be used to broadcast values acquired by a single 
thread directly to all instances of the private variables in the other threads. 
In this example, if the routine is called from the sequential part, its behavior 
is not affected by the presence of the directives. If it is called from a \kcode{parallel} 
region, then the actual arguments with which \ucode{a} and \ucode{b} are associated 
must be private. 

\index{constructs!single@\kcode{single}}
\index{single construct@\kcode{single} construct}
The thread that executes the structured block associated with the \kcode{single} 
 construct broadcasts the values of the private variables \ucode{a}, \ucode{b}, 
\ucode{x}, and 
\ucode{y} from its implicit task's data environment to the data environments 
of the other implicit tasks in the thread team. The broadcast completes before 
any of the threads have left the barrier at the end of the construct.

\cexample{copyprivate}{1}

\fexample{copyprivate}{1}

\index{constructs!masked@\kcode{masked}}
\index{masked construct@\kcode{masked} construct}
In this example, assume that the input must be performed by the primary thread. 
Since the \kcode{masked} construct does not support the \kcode{copyprivate} clause, 
it cannot broadcast the input value that is read. However, \kcode{copyprivate} 
is used to broadcast an address where the input value is stored. 

\cexample[5.1]{copyprivate}{2}

\fexample[5.1]{copyprivate}{2}

Suppose that the number of lock variables required within a \kcode{parallel} region 
cannot easily be determined prior to entering it. The \kcode{copyprivate} clause 
can be used to provide access to shared lock variables that are allocated within 
that \kcode{parallel} region.

\cexample{copyprivate}{3}

\begin{fortranspecific}
\fnexample{copyprivate}{3}

Note that the effect of the \kcode{copyprivate} clause on a variable with the 
\bcode{allocatable} attribute is different than on a variable with the \bcode{pointer} 
attribute. The value of \ucode{A} is copied (as if by intrinsic assignment) and 
the pointer \ucode{B} is copied (as if by pointer assignment) to the corresponding 
list items in the other implicit tasks belonging to the \kcode{parallel} region. 

\fnexample{copyprivate}{4}
\end{fortranspecific}


</pre></body></html>