Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix dist
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / icallgather.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11 #include "mpicolltest.h"
12
13 /*
14 static char MTEST_Descrip[] = "Simple intercomm allgather test";
15 */
16
17 int main(int argc, char *argv[])
18 {
19     int errs = 0, err;
20     int *rbuf = 0, *sbuf = 0;
21     int leftGroup, i, count, rank, rsize;
22     MPI_Comm comm;
23     MPI_Datatype datatype;
24
25     MTest_Init(&argc, &argv);
26
27     datatype = MPI_INT;
28     /* Get an intercommunicator */
29     while (MTestGetIntercomm(&comm, &leftGroup, 4)) {
30         if (comm == MPI_COMM_NULL)
31             continue;
32         MPI_Comm_rank(comm, &rank);
33         MPI_Comm_remote_size(comm, &rsize);
34
35         /* To improve reporting of problems about operations, we
36          * change the error handler to errors return */
37         MPI_Errhandler_set(comm, MPI_ERRORS_RETURN);
38
39         for (count = 1; count < 65000; count = 2 * count) {
40             /* The left group will send rank to the right group;
41              * The right group will send -rank to the left group */
42             rbuf = (int *) malloc(count * rsize * sizeof(int));
43             sbuf = (int *) malloc(count * sizeof(int));
44             for (i = 0; i < count * rsize; i++)
45                 rbuf[i] = -1;
46             if (leftGroup) {
47                 for (i = 0; i < count; i++)
48                     sbuf[i] = i + rank * count;
49             }
50             else {
51                 for (i = 0; i < count; i++)
52                     sbuf[i] = -(i + rank * count);
53             }
54             err = MTest_Allgather(sbuf, count, datatype, rbuf, count, datatype, comm);
55             if (err) {
56                 errs++;
57                 MTestPrintError(err);
58             }
59             if (leftGroup) {
60                 for (i = 0; i < count * rsize; i++) {
61                     if (rbuf[i] != -i) {
62                         errs++;
63                     }
64                 }
65             }
66             else {
67                 for (i = 0; i < count * rsize; i++) {
68                     if (rbuf[i] != i) {
69                         errs++;
70                     }
71                 }
72             }
73
74             /* Use Allgather in a unidirectional way */
75             for (i = 0; i < count * rsize; i++)
76                 rbuf[i] = -1;
77             if (leftGroup) {
78                 err = MTest_Allgather(sbuf, 0, datatype, rbuf, count, datatype, comm);
79                 if (err) {
80                     errs++;
81                     MTestPrintError(err);
82                 }
83                 for (i = 0; i < count * rsize; i++) {
84                     if (rbuf[i] != -i) {
85                         errs++;
86                     }
87                 }
88             }
89             else {
90                 err = MTest_Allgather(sbuf, count, datatype, rbuf, 0, datatype, comm);
91                 if (err) {
92                     errs++;
93                     MTestPrintError(err);
94                 }
95                 for (i = 0; i < count * rsize; i++) {
96                     if (rbuf[i] != -1) {
97                         errs++;
98                     }
99                 }
100             }
101             free(rbuf);
102             free(sbuf);
103         }
104         MTestFreeComm(&comm);
105     }
106
107     MTest_Finalize(errs);
108     MPI_Finalize();
109     return 0;
110 }