Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'hypervisor' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid...
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / alltoall1.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 "mpitest.h"
10 #include <stdlib.h>
11
12 /*
13 static char MTEST_Descrip[] = "";
14 */
15
16 int main( int argc, char *argv[] )
17 {
18     int errs = 0;
19     int rank, size;
20     int minsize = 2, count; 
21     MPI_Comm      comm;
22     int *sendbuf, *recvbuf, *p;
23     int sendcount, recvcount;
24     int i, j;
25     MPI_Datatype sendtype, recvtype;
26
27     MTest_Init( &argc, &argv );
28
29     /* The following illustrates the use of the routines to 
30        run through a selection of communicators and datatypes.
31        Use subsets of these for tests that do not involve combinations 
32        of communicators, datatypes, and counts of datatypes */
33     while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
34         if (comm == MPI_COMM_NULL) continue;
35
36         /* Determine the sender and receiver */
37         MPI_Comm_rank( comm, &rank );
38         MPI_Comm_size( comm, &size );
39         
40         /* printf( "Size of comm = %d\n", size ); */
41         for (count = 1; count < 65000; count = count * 2) {
42             
43             /* Create a send buf and a receive buf suitable for testing
44                all to all.  */
45             sendcount = count;
46             recvcount = count;
47             sendbuf   = (int *)malloc( count * size * sizeof(int) );
48             recvbuf   = (int *)malloc( count * size * sizeof(int) );
49             sendtype  = MPI_INT;
50             recvtype  = MPI_INT;
51
52             if (!sendbuf || !recvbuf) {
53                 errs++;
54                 fprintf( stderr, "Failed to allocate sendbuf and/or recvbuf\n" );
55                 MPI_Abort( MPI_COMM_WORLD, 1 );
56             }
57             for (i=0; i<count*size; i++) 
58                 recvbuf[i] = -1;
59             p = sendbuf;
60             for (j=0; j<size; j++) {
61                 for (i=0; i<count; i++) {
62                     *p++ = j * size + rank + i;
63                 }
64             }
65
66             MPI_Alltoall( sendbuf, sendcount, sendtype,
67                           recvbuf, recvcount, recvtype, comm );
68
69             p = recvbuf;
70             for (j=0; j<size; j++) {
71                 for (i=0; i<count; i++) {
72                     if (*p != rank * size + j + i) {
73                         errs++;
74                         if (errs < 10) {
75                             fprintf( stderr, "Error with communicator %s and size=%d count=%d\n",
76                                      MTestGetIntracommName(), size, count );
77                             fprintf( stderr, "recvbuf[%d,%d] = %d, should %d\n",
78                                      j,i, *p, rank * size + j + i );
79                         }
80                     }
81                     p++;
82                 }
83             }
84
85 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
86             /* check MPI_IN_PLACE, added in MPI-2.2 */
87             p = recvbuf;
88             for (j=0; j<size; j++) {
89                 for (i=0; i<count; i++) {
90                     *p++ = j * size + rank + i;
91                 }
92             }
93             MPI_Alltoall( MPI_IN_PLACE, -1/*ignored*/, MPI_DATATYPE_NULL/*ignored*/,
94                           recvbuf, recvcount, recvtype, comm );
95             p = recvbuf;
96             for (j=0; j<size; j++) {
97                 for (i=0; i<count; i++) {
98                     if (*p != rank * size + j + i) {
99                         errs++;
100                         if (errs < 10) {
101                             fprintf( stderr, "Error (MPI_IN_PLACE) with communicator %s and size=%d count=%d\n",
102                                      MTestGetIntracommName(), size, count );
103                             fprintf(stderr, "recvbuf[%d,%d] = %d, should be %d\n",
104                                     j,i, *p, rank * size + j + i );
105                         }
106                     }
107                     p++;
108                 }
109             }
110 #endif
111
112             free( recvbuf );
113             free( sendbuf );
114         }
115         MTestFreeComm( &comm );
116     }
117
118     MTest_Finalize( errs );
119     MPI_Finalize();
120     return 0;
121 }