Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / bcastzerotype.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2012 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <assert.h>
11
12 #include <mpi.h>
13
14 /* test broadcast behavior with non-zero counts but zero-sized types */
15
16 int main(int argc, char *argv[])
17 {
18     int i, type_size;
19     MPI_Datatype type = MPI_DATATYPE_NULL;
20     char *buf = NULL;
21     int wrank, wsize;
22
23     MPI_Init(&argc, &argv);
24     MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
25     MPI_Comm_size(MPI_COMM_WORLD, &wsize);
26
27     /* a random non-zero sized buffer */
28 #define NELEM (10)
29     buf = malloc(NELEM*sizeof(int));
30     assert(buf);
31
32     for (i = 0; i < NELEM; i++) {
33         buf[i] = wrank * NELEM + i;
34     }
35
36     /* create a zero-size type */
37     MPI_Type_contiguous(0, MPI_INT, &type);
38     MPI_Type_commit(&type);
39     MPI_Type_size(type, &type_size);
40     assert(type_size == 0);
41
42     /* do the broadcast, which will break on some MPI implementations */
43     MPI_Bcast(buf, NELEM, type, 0, MPI_COMM_WORLD);
44
45     /* check that the buffer remains unmolested */
46     for (i = 0; i < NELEM; i++) {
47         assert(buf[i] == wrank * NELEM + i);
48     }
49
50     MPI_Type_free(&type);
51     MPI_Finalize();
52
53     if (wrank == 0) {
54         printf(" No errors\n");
55     }
56
57     return 0;
58 }