Vector

The function MPI_TYPE_VECTOR is a more general constructor that allows replication of a datatype into locations that consist of equally spaced blocks. Each block is obtained by concatenating the same number of copies of the old datatype. The spacing between blocks is a multiple of the extent of the old datatype.



MPI_TYPE_VECTOR( count, blocklength, stride, oldtype, newtype)

IN
count number of blocks (nonnegative integer)
IN
blocklength number of elements in each block (nonnegative integer)
IN
stride number of elements between start of each block (integer)
IN
oldtype old datatype (handle)
OUT
newtype new datatype (handle)

int MPI_Type_vector(int count, int blocklength, int stride, MPI_Datatype oldtype, MPI_Datatype *newtype)



MPI_TYPE_VECTOR(COUNT, BLOCKLENGTH, STRIDE, OLDTYPE, NEWTYPE, IERROR)
INTEGER COUNT, BLOCKLENGTH, STRIDE, OLDTYPE, NEWTYPE, IERROR



Example 3..21   Assume, again, that oldtype has type map \(
\{ ({\sf double}, 0), ({\sf char}, 8) \} ,
\) with extent 16. A call to MPI_TYPE_VECTOR( 2, 3, 4, oldtype, newtype) will create the datatype with type map,

\begin{displaymath}
\{
({\sf double}, 0), ({\sf char}, 8), ({\sf double}, 16), ({\sf char},
24), ({\sf double}, 32), ({\sf char}, 40),
\end{displaymath}


\begin{displaymath}
({\sf double}, 64), ({\sf char}, 72), ({\sf double}, 80), ({\sf char},
88), ({\sf double}, 96), ({\sf char}, 104)
\} .
\end{displaymath}

That is, two blocks with three copies each of the old type, with a stride of 4 elements ($4 \cdot 16$ bytes) between the blocks.

Example 3..22   A call to MPI_TYPE_VECTOR(3, 1, -2, oldtype, newtype) will create the datatype,

\begin{displaymath}
\{
({\sf double}, 0), ({\sf char}, 8), ({\sf double}, -32), ({\sf char},
-24), ({\sf double}, -64), ({\sf char}, -56)
\} .
\end{displaymath}




In general, assume that oldtype has type map,

\begin{displaymath}
\{ (type_0,disp_0), ..., (type_{n-1}, disp_{n-1}) \} ,
\end{displaymath}

with extent $ex$. Let bl be the blocklength. The newly created datatype has a type map with ${\sf count} \cdot {\sf bl} \cdot n$ entries:

\begin{displaymath}
\{
(type_0, disp_0), ... , (type_{n-1} , disp_{n-1}),
\end{displaymath}


\begin{displaymath}
(type_0 ,disp_0 + ex) , ... ,
(type_{n-1} , disp_{n-1} + ex ), ...,
\end{displaymath}


\begin{displaymath}
(type_0 , disp_0 + ({\sf bl} -1) \cdot ex
) , ... , (type_{n-1} , disp_{n-1} + ({\sf bl} -1) \cdot ex ) ,
\end{displaymath}


\begin{displaymath}
(type_0 ,disp_0 + {\sf stride} \cdot ex ) , ... ,
(type_{n-1} , disp_{n-1} + {\sf stride} \cdot ex ), ... ,
\end{displaymath}


\begin{displaymath}
(type_0 , disp_0 + ({\sf stride} + {\sf bl} -1) \cdot ex ) ,...
..., disp_{n-1} + ({\sf stride} + {\sf bl} -1) \cdot
ex ) , ....,
\end{displaymath}


\begin{displaymath}
(type_0 ,disp_0 + {\sf stride} \cdot ({\sf count}-1) \cdot ex ) , ... ,
\end{displaymath}


\begin{displaymath}
(type_{n-1} , disp_{n-1} + {\sf stride} \cdot ({\sf count} -1) \cdot
ex )
, ... ,
\end{displaymath}


\begin{displaymath}
(type_0 , disp_0 + ({\sf stride} \cdot ({\sf count} -1)
+ {\sf bl} -1) \cdot ex ) , ... ,
\end{displaymath}


\begin{displaymath}
(type_{n-1}, disp_{n-1} + ({\sf stride} \cdot ({\sf count} -1)
+ {\sf bl} -1) \cdot ex )
\} .
\end{displaymath}




A call to MPI_TYPE_CONTIGUOUS(count, oldtype, newtype) is equivalent to a call to MPI_TYPE_VECTOR(count, 1, 1, oldtype, newtype), or to a call to MPI_TYPE_VECTOR(1, count, n, oldtype, newtype), n arbitrary.

MPI-Standard for MARMOT