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