Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix dist
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / icalltoallw.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include "mpitest.h"
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include "mpicolltest.h"
11
12 /*
13   This program tests MPI_Alltoallw by having processor i send different
14   amounts of data to each processor.  This is just the MPI_Alltoallv test,
15   but with displacements in bytes rather than units of the datatype.
16
17   Because there are separate send and receive types to alltoallw,
18   there need to be tests to rearrange data on the fly.  Not done yet.
19
20   The first test sends i items to processor i from all processors.
21
22   Currently, the test uses only MPI_INT; this is adequate for testing systems
23   that use point-to-point operations
24  */
25
26 int main(int argc, char **argv)
27 {
28
29     MPI_Comm comm;
30     int *sbuf, *rbuf;
31     int rank, size, lsize, asize;
32     int *sendcounts, *recvcounts, *rdispls, *sdispls;
33     int i, j, *p, err;
34     MPI_Datatype *sendtypes, *recvtypes;
35     int leftGroup;
36
37     MTest_Init(&argc, &argv);
38     err = 0;
39
40     while (MTestGetIntercomm(&comm, &leftGroup, 4)) {
41         if (comm == MPI_COMM_NULL)
42             continue;
43
44         /* Create the buffer */
45         MPI_Comm_size(comm, &lsize);
46         MPI_Comm_remote_size(comm, &size);
47         asize = (lsize > size) ? lsize : size;
48         MPI_Comm_rank(comm, &rank);
49         sbuf = (int *) malloc(size * size * sizeof(int));
50         rbuf = (int *) malloc(asize * asize * sizeof(int));
51         if (!sbuf || !rbuf) {
52             fprintf(stderr, "Could not allocated buffers!\n");
53             MPI_Abort(comm, 1);
54         }
55
56         /* Load up the buffers */
57         for (i = 0; i < size * size; i++) {
58             sbuf[i] = i + 100 * rank;
59             rbuf[i] = -i;
60         }
61
62         /* Create and load the arguments to alltoallv */
63         sendcounts = (int *) malloc(size * sizeof(int));
64         recvcounts = (int *) malloc(size * sizeof(int));
65         rdispls = (int *) malloc(size * sizeof(int));
66         sdispls = (int *) malloc(size * sizeof(int));
67         sendtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
68         recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
69         if (!sendcounts || !recvcounts || !rdispls || !sdispls || !sendtypes || !recvtypes) {
70             fprintf(stderr, "Could not allocate arg items!\n");
71             MPI_Abort(comm, 1);
72         }
73         /* Note that process 0 sends no data (sendcounts[0] = 0) */
74         for (i = 0; i < size; i++) {
75             sendcounts[i] = i;
76             sdispls[i] = (((i + 1) * (i)) / 2) * sizeof(int);
77             sendtypes[i] = MPI_INT;
78             recvcounts[i] = rank;
79             rdispls[i] = i * rank * sizeof(int);
80             recvtypes[i] = MPI_INT;
81         }
82         MTest_Alltoallw(sbuf, sendcounts, sdispls, sendtypes,
83                         rbuf, recvcounts, rdispls, recvtypes, comm);
84
85         /* Check rbuf */
86         for (i = 0; i < size; i++) {
87             p = rbuf + rdispls[i] / sizeof(int);
88             for (j = 0; j < rank; j++) {
89                 if (p[j] != i * 100 + (rank * (rank + 1)) / 2 + j) {
90                     fprintf(stderr, "[%d] got %d expected %d for %dth\n",
91                             rank, p[j], (i * (i + 1)) / 2 + j, j);
92                     err++;
93                 }
94             }
95         }
96
97         free(sendtypes);
98         free(recvtypes);
99         free(sdispls);
100         free(rdispls);
101         free(recvcounts);
102         free(sendcounts);
103         free(rbuf);
104         free(sbuf);
105         MTestFreeComm(&comm);
106     }
107
108     MTest_Finalize(err);
109     MPI_Finalize();
110     return 0;
111 }