Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
still not our
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / struct-derived-zeros.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 /* Based on code from Jeff Parker at IBM. */
7
8 #include <stdio.h>
9
10 #include <mpi.h>
11 #include "mpitest.h"
12
13 int main(int argc, char *argv[])
14 {
15     MPI_Datatype mystruct, vecs[3];
16     MPI_Aint stride = 5, displs[3];
17     int i=0, blockcount[3];
18     int errs=0;
19
20     MTest_Init( &argc, &argv );
21
22     for(i = 0; i < 3; i++)
23     {
24         MPI_Type_hvector(i, 1, stride, MPI_INT, &vecs[i]);
25         MPI_Type_commit(&vecs[i]);
26         blockcount[i]=1;
27     }
28     displs[0]=0; displs[1]=-100; displs[2]=-200; /* irrelevant */
29
30     MPI_Type_struct(3, blockcount, displs, vecs, &mystruct);
31     MPI_Type_commit(&mystruct);
32
33     MPI_Type_free(&mystruct);
34     for(i = 0; i < 3; i++)
35     {
36         MPI_Type_free(&vecs[i]);
37     }
38
39     /* this time with the first argument always 0 */
40     for(i = 0; i < 3; i++)
41     {
42         MPI_Type_hvector(0, 1, stride, MPI_INT, &vecs[i]);
43         MPI_Type_commit(&vecs[i]);
44         blockcount[i]=1;
45     }
46     displs[0]=0; displs[1]=-100; displs[2]=-200; /* irrelevant */
47
48     MPI_Type_struct(3, blockcount, displs, vecs, &mystruct);
49     MPI_Type_commit(&mystruct);
50
51     MPI_Type_free(&mystruct);
52     for(i = 0; i < 3; i++)
53     {
54         MPI_Type_free(&vecs[i]);
55     }
56
57     MTest_Finalize( errs );
58     MPI_Finalize();
59
60     return 0;
61 }