Struct

MPI_TYPE_STRUCT is the most general type constructor. It further generalizes the previous one in that it allows each block to consist of replications of different datatypes.



MPI_TYPE_STRUCT(count, array_of_blocklengths, array_of_displacements, array_of_types, newtype)

IN
count number of blocks (integer) - also number of entries in arrays array_of_types, array_of_displacements and array_of_blocklengths
IN
array_of_blocklength number of elements in each block (array of integer)
IN
array_of_displacements byte displacement of each block (array of integer)
IN
array_of_types type of elements in each block (array of handles to datatype objects)
OUT
newtype new datatype (handle)

int MPI_Type_struct(int count, int *array_of_blocklengths, MPI_Aint *array_of_displacements, MPI_Datatype *array_of_types, MPI_Datatype *newtype)



MPI_TYPE_STRUCT(COUNT, ARRAY_OF_BLOCKLENGTHS, ARRAY_OF_DISPLACEMENTS, ARRAY_OF_TYPES, NEWTYPE, IERROR)
INTEGER COUNT, ARRAY_OF_BLOCKLENGTHS(*), ARRAY_OF_DISPLACEMENTS(*), ARRAY_OF_TYPES(*), NEWTYPE, IERROR



Example 3..24   Let type1 have type map,

\begin{displaymath}
\{ ({\sf double}, 0), ({\sf char}, 8) \} ,
\end{displaymath}

with extent 16. Let B = (2, 1, 3), D = (0, 16, 26), and T = (MPI_FLOAT, type1, MPI_CHAR). Then a call to MPI_TYPE_STRUCT(3, B, D, T, newtype) returns a datatype with type map,

\begin{displaymath}
\{
({\sf float}, 0), ({\sf float}, 4), ({\sf double}, 16), (...
...24), ({\sf char}, 26), ({\sf char}, 27), ({\sf char}, 28)
\} .
\end{displaymath}

That is, two copies of MPI_FLOAT starting at 0, followed by one copy of type1 starting at 16, followed by three copies of MPI_CHAR, starting at 26. (We assume that a float occupies four bytes.)




In general, let T be the array_of_types argument, where T[i] is a handle to,

\begin{displaymath}
typemap_i = \{ (type_0^i , disp_0^i ) , ... , (type_{n_{i}-1}^i ,
disp_{n_{i}-1}^i ) \} ,
\end{displaymath}

with extent $ex_i$. Let B be the array_of_blocklength argument and D be the array_of_displacements argument. Let c be the count argument. Then the newly created datatype has a type map with $\sum_{i=0}^{{\sf c}-1}{\sf B[i]} \cdot n_i$ entries:

\begin{displaymath}
\{
(type_0^0 , disp_0^0 +{\sf D[0]}) , ... , (type_{n_0}^0 , disp_{n_0}^0 +
{\sf D[0]} ) ,
... ,
\end{displaymath}


\begin{displaymath}
(type_0^0 , disp_0^0 + {\sf D[0]} + ({\sf B[0]}-1) \cdot ex_...
...isp_{n_0}^0 + {\sf D[0]} + ({\sf B[0]-1)} \cdot
ex_0 )
, ... ,
\end{displaymath}


\begin{displaymath}
(type_0^{{\sf c}-1} , disp_0^{{\sf c}-1} +{\sf D[c-1]}) , .....
...
disp_{{n_{{\sf c}-1}}-1}^{{\sf c}-1} + {\sf D[c-1]} ) ,
... ,
\end{displaymath}


\begin{displaymath}
(type_0^{{\sf c}-1} , disp_0^{{\sf c}-1} +
{\sf D[c-1]} + ({\sf B[c-1]}-1) \cdot ex_{{\sf c}-1} ) ,
... ,
\end{displaymath}


\begin{displaymath}
(type_{{n_{{\sf c}-1}}-1}^{{\sf c}-1} ,
disp_{{n_{{\sf c}-1}...
... + {\sf D[c-1]} +
({\sf B[c-1]-1)} \cdot ex_{{\sf c}-1} )
\} .
\end{displaymath}




A call to MPI_TYPE_HINDEXED( count, B, D, oldtype, newtype) is equivalent to a call to MPI_TYPE_STRUCT( count, B, D, T, newtype), where each entry of T is equal to oldtype.

MPI-Standard for MARMOT