mirror of
https://github.com/OpenMP/Examples.git
synced 2025-04-27 08:11:28 +01:00
71 lines
3.4 KiB
TeX
71 lines
3.4 KiB
TeX
\pagebreak
|
|
\section{\code{target} \code{update} Construct}
|
|
\label{sec:target_update}
|
|
|
|
\subsection{Simple \code{target} \code{data} and \code{target} \code{update} Constructs}
|
|
\label{subsec:target_data_and_update}
|
|
\index{constructs!target data@\code{target}~\code{data}}
|
|
\index{target data construct@\code{target}~\code{data} construct}
|
|
\index{constructs!target update@\code{target}~\code{update}}
|
|
\index{target update construct@\code{target}~\code{update} construct}
|
|
\index{target update construct@\code{target}~\code{update} construct!to clause@\code{to} clause}
|
|
\index{target update construct@\code{target}~\code{update} construct!from clause@\code{from} clause}
|
|
\index{target update construct@\code{target}~\code{update} construct!motion-clause@\plc{motion-clause}}
|
|
\index{clauses!motion-clause@\plc{motion-clause}}
|
|
\index{clauses!to@\code{to}}
|
|
\index{clauses!from@\code{from}}
|
|
\index{motion-clause@\plc{motion-clause}!to clause@\code{to} clause}
|
|
\index{motion-clause@\plc{motion-clause}!from clause@\code{from} clause}
|
|
|
|
The following example shows how the \code{target} \code{update} construct updates
|
|
variables in a device data environment.
|
|
|
|
The \code{target} \code{data} construct maps array sections \plc{v1[:N]} and \plc{v2[:N]}
|
|
(arrays \plc{v1} and \plc{v2} in the Fortran code) into a device data environment.
|
|
|
|
The task executing on the host device encounters the first \code{target} region
|
|
and waits for the completion of the region.
|
|
|
|
After the execution of the first \code{target} region, the task executing on
|
|
the host device then assigns new values to \plc{v1[:N]} and \plc{v2[:N]} (\plc{v1} and \plc{v2} arrays
|
|
in Fortran code) in the task's data environment by calling the function \code{init\_again()}.
|
|
|
|
The \code{target} \code{update} construct assigns the new values of \plc{v1} and
|
|
\plc{v2} from the task's data environment to the corresponding mapped array sections
|
|
in the device data environment of the \code{target} \code{data} construct.
|
|
|
|
The task executing on the host device then encounters the second \code{target}
|
|
region and waits for the completion of the region.
|
|
|
|
The second \code{target} region uses the updated values of \plc{v1[:N]} and \plc{v2[:N]}.
|
|
|
|
\cexample[4.0]{target_update}{1}
|
|
|
|
\ffreeexample[4.0]{target_update}{1}
|
|
|
|
\subsection{\code{target} \code{update} Construct with \code{if} Clause}
|
|
\label{subsec:target_update_if}
|
|
\index{target update construct@\code{target}~\code{update} construct!if clause@\code{if} clause}
|
|
\index{clauses!if@\code{if}}
|
|
\index{if clause@\code{if} clause}
|
|
|
|
The following example shows how the \code{target} \code{update} construct updates
|
|
variables in a device data environment.
|
|
|
|
The \code{target} \code{data} construct maps array sections \plc{v1[:N]} and \plc{v2[:N]}
|
|
(arrays \plc{v1} and \plc{v2} in the Fortran code) into a device data environment. In between
|
|
the two \code{target} regions, the task executing on the host device conditionally
|
|
assigns new values to \plc{v1} and \plc{v2} in the task's data environment. The function \code{maybe\_init\_again()}
|
|
returns \plc{true} if new data is written.
|
|
|
|
When the conditional expression (the return value of \code{maybe\_init\_again()}) in the
|
|
\code{if} clause is \plc{true}, the \code{target} \code{update} construct
|
|
assigns the new values of \plc{v1} and \plc{v2} from the task's data environment to the corresponding
|
|
mapped array sections in the \code{target} \code{data} construct's device data
|
|
environment.
|
|
|
|
\cexample[4.0]{target_update}{2}
|
|
|
|
\ffreeexample[4.0]{target_update}{2}
|
|
|