mirror of
https://github.com/OpenMP/Examples.git
synced 2025-04-04 05:41:33 +01:00
45 lines
2.2 KiB
TeX
45 lines
2.2 KiB
TeX
\pagebreak
|
|
\section{Unified Shared Memory}
|
|
\label{sec:usm}
|
|
|
|
\index{requires directive@\kcode{requires} directive}
|
|
\index{directives!requires@\kcode{requires}}
|
|
|
|
\index{unified_shared_memory clause@\kcode{unified_shared_memory} clause}
|
|
\index{clauses!unified_shared_memory@\kcode{unified_shared_memory}}
|
|
|
|
The following examples show behavior of scalars, pointers, references (C++) and
|
|
associate names (Fortran) in \kcode{target} constructs when
|
|
unified shared memory (USM) is required throughout the scope of the program by the
|
|
\kcode{unified_shared_memory} clause in a \kcode{requires} directive.
|
|
USM assumes a unified address space.
|
|
|
|
\begin{cppspecific}
|
|
In the C++ code of the first example, a scalar (\ucode{x}), a pointer
|
|
(\ucode{ptr}), and a reference (\ucode{ref}) are used in a \kcode{target} construct in Cases 1, 2 and 3, respectively.
|
|
For the scalar variable \ucode{x}, the predetermined data-sharing attribute is still
|
|
firstprivate under the USM requirement and, hence, any manipulation of the local variable on the device is never reflected on the host.
|
|
With the USM requirement, pointers always refer to the same location in memory on the host and devices.
|
|
Hence, the value of \ucode{x} (in the host data environment) can be modified with \ucode{ptr} in
|
|
the \kcode{target} construct, as seen in Case 2.
|
|
For the reference \ucode{ref}, the object to which it refers is mapped for
|
|
the \kcode{target} construct, as seen in Case 3.
|
|
|
|
\cppnexample[5.2]{usm_scalar_ptr_ref_asc}{1}
|
|
\end{cppspecific}
|
|
|
|
\begin{fortranspecific}
|
|
In Case 1 of the Fortran example, the scalar \ucode{x} is firstprivate under the USM requirement
|
|
in the \kcode{target} construct, and modification of the local variable on the device is
|
|
never updated to the host data environment.
|
|
Also, in Case 2, the use of \ucode{ax}, which is associated with \ucode{x},
|
|
will update the \ucode{x} value in the host data environment.
|
|
In Case 3, the Fortran pointer \ucode{ptr} and its target \ucode{y} are not firstprivate,
|
|
but implicitly mapped. Hence, updates to the value of \ucode{y} appear in the host data environment.
|
|
|
|
%Hence, updates to \ucode{y} in the \kcode{target} construct appear in the data environment of the host.
|
|
|
|
%\pagebreak
|
|
\ffreenexample[5.2]{usm_scalar_ptr_ref_asc}{1}
|
|
\end{fortranspecific}
|