Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change include order for smpi tests/examples to avoid conflicts
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / icallgatherv.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 allgatherv test";
14 */
15
16 int main( int argc, char *argv[] )
17 {
18     int errs = 0, err;
19     int *rbuf = 0, *sbuf = 0;
20     int *recvcounts, *recvdispls;
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) continue;
31         MPI_Comm_rank( comm, &rank );
32         MPI_Comm_remote_size( comm, &rsize );
33
34         /* To improve reporting of problems about operations, we
35            change the error handler to errors return */
36         MPI_Errhandler_set( comm, MPI_ERRORS_RETURN );
37
38         for (count = 1; count < 65000; count = 2 * count) {
39             /* The left group will send rank to the right group;
40                The right group will send -rank to the left group */
41             rbuf = (int *)malloc( count * rsize * sizeof(int) );
42             sbuf = (int *)malloc( count * sizeof(int) );
43             recvcounts = (int *) malloc( rsize * sizeof(int) );
44             recvdispls = (int *) malloc( rsize * sizeof(int) );
45             for (i=0; i<count*rsize; i++) rbuf[i] = -1;
46             for (i=0; i<rsize; i++) {
47                 recvcounts[i] = count;
48                 recvdispls[i] = i * count;
49             }
50             if (leftGroup) {
51                 for (i=0; i<count; i++)       sbuf[i] = i + rank*count;
52             }
53             else {
54                 for (i=0; i<count; i++)       sbuf[i] = -(i + rank*count);
55             }
56             err = MPI_Allgatherv( sbuf, count, datatype,
57                                   rbuf, recvcounts, recvdispls, datatype, 
58                                   comm );
59             if (err) {
60                 errs++;
61                 MTestPrintError( err );
62             }
63             if (leftGroup) {
64                 for (i=0; i<count*rsize; i++) {
65                     if (rbuf[i] != -i) {
66                         errs++;
67                     }
68                 }
69             }
70             else {
71                 for (i=0; i<count*rsize; i++) {
72                     if (rbuf[i] != i) {
73                         errs++;
74                     }
75                 }
76             }
77
78             /* Use Allgather in a unidirectional way */
79             for (i=0; i<count*rsize; i++) rbuf[i] = -1;
80             if (leftGroup) {
81                 err = MPI_Allgatherv( sbuf, 0, datatype,
82                                       rbuf, recvcounts, recvdispls, datatype, 
83                                       comm );
84                 if (err) {
85                     errs++;
86                     MTestPrintError( err );
87                 }
88                 for (i=0; i<count*rsize; i++) {
89                     if (rbuf[i] != -i) {
90                         errs++;
91                     }
92                 }
93             }
94             else {
95                 for (i=0; i<rsize; i++) {
96                     recvcounts[i] = 0;
97                     recvdispls[i] = 0;
98                 }
99                 err = MPI_Allgatherv( sbuf, count, datatype,
100                                       rbuf, recvcounts, recvdispls, datatype, comm );
101                 if (err) {
102                     errs++;
103                     MTestPrintError( err );
104                 }
105                 for (i=0; i<count*rsize; i++) {
106                     if (rbuf[i] != -1) {
107                         errs++;
108                     }
109                 }
110             }
111             free( rbuf );
112             free( sbuf );
113             free( recvcounts );
114             free( recvdispls );
115         }
116         MTestFreeComm( &comm );
117     }
118
119     MTest_Finalize( errs );
120     MPI_Finalize();
121     return 0;
122 }