OpenMP-Examples/devices/array_shaping.tex
2022-11-04 09:35:42 -07:00

47 lines
2.2 KiB
TeX

\section{Array Shaping}
\label{sec:array-shaping}
\index{array shaping!in motion-clause@in \plc{motion-clause}}
\index{constructs!target update@\code{target}~\code{update}}
\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{directives!declare target@\code{declare}~\code{target}}
\index{declare target directive@\code{declare}~\code{target} directive}
\index{directives!begin declare target@\code{begin}~\code{declare}~\code{target}}
\index{begin declare target directive@\code{begin}~\code{declare}~\code{target} directive}
\ccppspecificstart
A pointer variable can be shaped to a multi-dimensional array to facilitate
data access. This is achieved by a \plc{shape-operator} casted in front of
a pointer (lvalue expression):
\begin{description}
\item[]\hspace*{5mm}\code{([$s_1$][$s_2$]...[$s_n$])}\plc{pointer}
\end{description}
where each $s_i$ is an integral-type expression of positive value.
The shape-operator can appear in either the \plc{motion-clause}
of the \code{target}~\code{update} directive or the \code{depend} clause.
The following example shows the use of the shape-operator in the
\code{target}~\code{update} directive. The shape-operator \code{([nx][ny+2])}
casts pointer variable $a$ to a 2-dimensional array of size
\plc{nx}$\times$\plc{(ny+2)}. The resulting array is then accessed as
array sections (such as \code{[0:nx][1]} and \code{[0:nx][ny]})
in the \code{from} or \code{to} clause for transferring two columns of
noncontiguous boundary data from or to the device.
Note the use of additional parentheses
around the shape-operator and $a$ to ensure the correct precedence
over array-section operations.
\cnexample[5.1]{array_shaping}{1}
\ccppspecificend
\clearpage
The shape operator is not defined for Fortran. Explicit array shaping
of procedure arguments can be used instead to achieve a similar goal.
Below is the Fortran-equivalent of the above example that illustrates
the support of transferring two rows of noncontiguous boundary
data in the \code{target}~\code{update} directive.
\ffreeexample[5.2]{array_shaping}{1}