Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning with mc
[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
12 /*
13 static char MTEST_Descrip[] = "Simple intercomm allgather test";
14 */
15
16 int main( int argc, char *argv[] )
17 {
18     int errs = 0, err;
19     int *rbuf = 0, *sbuf = 0;
20     int leftGroup, i, count, rank, rsize;
21     MPI_Comm comm;
22     MPI_Datatype datatype;
23
24     MTest_Init( &argc, &argv );
25
26     datatype = MPI_INT;
27     /* Get an intercommunicator */
28     while (MTestGetIntercomm( &comm, &leftGroup, 4 )) {
29         if (comm == MPI_COMM_NULL) continue;
30         MPI_Comm_rank( comm, &rank );
31         MPI_Comm_remote_size( comm, &rsize );
32
33         /* To improve reporting of problems about operations, we
34            change the error handler to errors return */
35         MPI_Errhandler_set( comm, MPI_ERRORS_RETURN );
36
37         for (count = 1; count < 65000; count = 2 * count) {
38             /* The left group will send rank to the right group;
39                The right group will send -rank to the left group */
40             rbuf = (int *)malloc( count * rsize * sizeof(int) );
41             sbuf = (int *)malloc( count * sizeof(int) );
42             for (i=0; i<count*rsize; i++) rbuf[i] = -1;
43             if (leftGroup) {
44                 for (i=0; i<count; i++)       sbuf[i] = i + rank*count;
45             }
46             else {
47                 for (i=0; i<count; i++)       sbuf[i] = -(i + rank*count);
48             }
49             err = MPI_Allgather( sbuf, count, datatype,
50                                  rbuf, count, datatype, comm );
51             if (err) {
52                 errs++;
53                 MTestPrintError( err );
54             }
55             if (leftGroup) {
56                 for (i=0; i<count*rsize; i++) {
57                     if (rbuf[i] != -i) {
58                         errs++;
59                     }
60                 }
61             }
62             else {
63                 for (i=0; i<count*rsize; i++) {
64                     if (rbuf[i] != i) {
65                         errs++;
66                     }
67                 }
68             }
69
70             /* Use Allgather in a unidirectional way */
71             for (i=0; i<count*rsize; i++) rbuf[i] = -1;
72             if (leftGroup) {
73                 err = MPI_Allgather( sbuf, 0, datatype,
74                                      rbuf, count, datatype, comm );
75                 if (err) {
76                     errs++;
77                     MTestPrintError( err );
78                 }
79                 for (i=0; i<count*rsize; i++) {
80                     if (rbuf[i] != -i) {
81                         errs++;
82                     }
83                 }
84             }
85             else {
86                 err = MPI_Allgather( sbuf, count, datatype,
87                                      rbuf, 0, datatype, comm );
88                 if (err) {
89                     errs++;
90                     MTestPrintError( err );
91                 }
92                 for (i=0; i<count*rsize; i++) {
93                     if (rbuf[i] != -1) {
94                         errs++;
95                     }
96                 }
97             }
98             free( rbuf );
99             free( sbuf );
100         }
101         MTestFreeComm( &comm );
102     }
103
104     MTest_Finalize( errs );
105     MPI_Finalize();
106     return 0;
107 }