Logo AND Algorithmique Numérique Distribuée

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