Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix build and dist, add missing folder
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / hindexed_block_contents.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2012 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 /* test based on a bug report from Lisandro Dalcin:
8  * http://lists.mcs.anl.gov/pipermail/mpich-dev/2012-October/000978.html */
9
10 #include <mpi.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 /* USE_STRICT_MPI may be defined in mpitestconf.h */
14 #include "mpitestconf.h"
15
16 /* assert-like macro that bumps the err count and emits a message */
17 #define check(x_)                                                                 \
18     do {                                                                          \
19         if (!(x_)) {                                                              \
20             ++errs;                                                               \
21             if (errs < 10) {                                                      \
22                 fprintf(stderr, "check failed: (%s), line %d\n", #x_, __LINE__); \
23             }                                                                     \
24         }                                                                         \
25     } while (0)
26
27 int main(int argc, char **argv)
28 {
29     int errs = 0;
30     int rank;
31     MPI_Datatype t;
32     int count = 4;
33     int blocklength = 2;
34     MPI_Aint displacements[] = {0, 8, 16, 24};
35
36     MPI_Init(&argc, &argv);
37     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
38
39     if (!rank) {
40         MPI_Type_create_hindexed_block(count, blocklength,
41                                         displacements, MPI_INT,
42                                         &t);
43         MPI_Type_commit(&t);
44         {
45             int ni, na, nd, combiner;
46             int i[1024];
47             MPI_Aint a[1024];
48             MPI_Datatype d[1024];
49             int k;
50             MPI_Type_get_envelope(t, &ni, &na, &nd, &combiner);
51             MPI_Type_get_contents(t, ni, na, nd, i, a, d);
52
53             check(ni == 2);
54             check(i[0] == 4);
55             check(i[1] == 2);
56
57             check(na == 4);
58             for (k=0; k < na; k++)
59                 check(a[k] == (k * 8));
60
61             check(nd == 1);
62             check(d[0] == MPI_INT);
63         }
64
65         MPI_Type_free(&t);
66     }
67
68     if (rank == 0) {
69         if (errs) {
70             printf("found %d errors\n", errs);
71         }
72         else {
73             printf(" No errors\n");
74         }
75     }
76     MPI_Finalize();
77     return 0;
78 }