mirror of
https://github.com/OpenMP/Examples.git
synced 2025-04-10 16:32:11 +01:00
54 lines
2.5 KiB
TeX
54 lines
2.5 KiB
TeX
\pagebreak
|
|
\chapter{Devices}
|
|
\label{chap:devices}
|
|
|
|
The \code{target} construct consists of a \code{target} directive
|
|
and an execution region. The \code{target} region is executed on
|
|
the default device or the device specified in the \code{device}
|
|
clause.
|
|
|
|
In OpenMP version 4.0, by default, all variables within the lexical
|
|
scope of the construct are copied \plc{to} and \plc{from} the
|
|
device, unless the device is the host, or the data exists on the
|
|
device from a previously executed data-type construct that
|
|
has created space on the device and possibly copied host
|
|
data to the device storage.
|
|
|
|
The constructs that explicitly
|
|
create storage, transfer data, and free storage on the device
|
|
are catagorized as structured and unstructured. The
|
|
\code{target} \code{data} construct is structured. It creates
|
|
a data region around \code{target} constructs, and is
|
|
convenient for providing persistent data throughout multiple
|
|
\code{target} regions. The \code{target} \code{enter} \code{data} and
|
|
\code{target} \code{exit} \code{data} constructs are unstructured, because
|
|
they can occur anywhere and do not support a "structure"
|
|
(a region) for enclosing \code{target} constructs, as does the
|
|
\code{target} \code{data} construct.
|
|
|
|
The \code{map} clause is used on \code{target}
|
|
constructs and the data-type constructs to map host data. It
|
|
specifies the device storage and data movement \code{to} and \code{from}
|
|
the device, and controls on the storage duration.
|
|
|
|
There is an important change in the OpenMP 4.5 specification
|
|
that alters the data model for scalar variables and C/C++ pointer variables.
|
|
The default behavior for scalar variables and C/C++ pointer variables
|
|
in an 4.5 compliant code is \code{firstprivate}. Example
|
|
codes that have been updated to reflect this new behavior are
|
|
annotated with a description that describes changes required
|
|
for correct execution. Often it is a simple matter of mapping
|
|
the variable as \code{tofrom} to obtain the intended 4.0 behavior.
|
|
|
|
In OpenMP version 4.5 the mechanism for target
|
|
execution is specified as occuring through a \plc{target task}.
|
|
When the \code{target} construct is encountered a new
|
|
\plc{target task} is generated. The \plc{target task}
|
|
completes after the \code{target} region has executed and all data
|
|
transfers have finished.
|
|
|
|
This new specification does not affect the execution of
|
|
pre-4.5 code; it is a necessary element for asynchronous
|
|
execution of the \code{target} region when using the new \code{nowait}
|
|
clause introduced in OpenMP 4.5.
|