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 / icalltoall.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 alltoall test";
14 */
15
16 int main( int argc, char *argv[] )
17 {
18     int errs = 0, err;
19     int *sendbuf = 0, *recvbuf = 0;
20     int leftGroup, i, j, idx, count, rrank, rsize;
21     MPI_Comm comm;
22     MPI_Datatype datatype;
23
24     MTest_Init( &argc, &argv );
25
26     datatype = MPI_INT;
27     while (MTestGetIntercomm( &comm, &leftGroup, 4 )) {
28         if (comm == MPI_COMM_NULL) continue;
29         for (count = 1; count < 66000; count = 2 * count) {
30             /* Get an intercommunicator */
31             MPI_Comm_remote_size( comm, &rsize );
32             MPI_Comm_rank( comm, &rrank );
33             sendbuf = (int *)malloc( rsize * count * sizeof(int) );
34             recvbuf = (int *)malloc( rsize * count * sizeof(int) );
35             for (i=0; i<rsize*count; i++) recvbuf[i] = -1;
36             if (leftGroup) {
37                 idx = 0;
38                 for (j=0; j<rsize; j++) {
39                     for (i=0; i<count; i++) {
40                         sendbuf[idx++] = i + rrank;
41                     }
42                 }
43                 err = MPI_Alltoall( sendbuf, count, datatype, 
44                                     NULL, 0, datatype, comm );
45                 if (err) {
46                     errs++;
47                     MTestPrintError( err );
48                 }
49             }
50             else {
51                 int rank, size;
52
53                 MPI_Comm_rank( comm, &rank );
54                 MPI_Comm_size( comm, &size );
55
56                 /* In the right group */
57                 err = MPI_Alltoall( NULL, 0, datatype, 
58                                     recvbuf, count, datatype, comm );
59                 if (err) {
60                     errs++;
61                     MTestPrintError( err );
62                 }
63                 /* Check that we have received the correct data */
64                 idx = 0;
65                 for (j=0; j<rsize; j++) {
66                     for (i=0; i<count; i++) {
67                         if (recvbuf[idx++] != i + j) {
68                             errs++;
69                             if (errs < 10) 
70                                 fprintf( stderr, "buf[%d] = %d on %d\n", 
71                                          i, recvbuf[i], rank );
72                         }
73                     }
74                 }
75             }
76             free( recvbuf );
77             free( sendbuf );
78         }
79         MTestFreeComm( &comm );
80     }
81
82     MTest_Finalize( errs );
83     MPI_Finalize();
84     return 0;
85 }