Logo AND Algorithmique Numérique Distribuée

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