Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[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, displacements, MPI_INT, &t);
41         MPI_Type_commit(&t);
42         {
43             int ni, na, nd, combiner;
44             int i[1024];
45             MPI_Aint a[1024];
46             MPI_Datatype d[1024];
47             int k;
48             MPI_Type_get_envelope(t, &ni, &na, &nd, &combiner);
49             MPI_Type_get_contents(t, ni, na, nd, i, a, d);
50
51             check(ni == 2);
52             check(i[0] == 4);
53             check(i[1] == 2);
54
55             check(na == 4);
56             for (k = 0; k < na; k++)
57                 check(a[k] == (k * 8));
58
59             check(nd == 1);
60             check(d[0] == MPI_INT);
61         }
62
63         MPI_Type_free(&t);
64     }
65
66     if (rank == 0) {
67         if (errs) {
68             printf("found %d errors\n", errs);
69         }
70         else {
71             printf(" No errors\n");
72         }
73     }
74     MPI_Finalize();
75     return 0;
76 }