mirror of
https://github.com/OpenMP/Examples.git
synced 2025-04-04 05:41:33 +01:00
28 lines
1.2 KiB
TeX
28 lines
1.2 KiB
TeX
\section{Array Shaping}
|
|
\label{sec:array-shaping}
|
|
|
|
\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-dimentional 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{array_shaping}{1}
|
|
\ccppspecificend
|