Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / icalltoallv.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_Alltoallv by having processor i send different
14   amounts of data to each processor.
15
16   Because there are separate send and receive types to alltoallv,
17   there need to be tests to rearrange data on the fly.  Not done yet.
18
19   The first test sends i items to processor i from all processors.
20
21   Currently, the test uses only MPI_INT; this is adequate for testing systems
22   that use point-to-point operations
23  */
24
25 int main(int argc, char **argv)
26 {
27     MPI_Comm comm;
28     int *sbuf, *rbuf;
29     int rank, size, lsize, asize;
30     int *sendcounts, *recvcounts, *rdispls, *sdispls;
31     int i, j, *p, err;
32     int leftGroup;
33
34     MTest_Init(&argc, &argv);
35     err = 0;
36
37     while (MTestGetIntercomm(&comm, &leftGroup, 4)) {
38         if (comm == MPI_COMM_NULL)
39             continue;
40
41         /* Create the buffer */
42         MPI_Comm_size(comm, &lsize);
43         MPI_Comm_remote_size(comm, &size);
44         asize = (lsize > size) ? lsize : size;
45         MPI_Comm_rank(comm, &rank);
46         sbuf = (int *) malloc(size * size * sizeof(int));
47         rbuf = (int *) malloc(asize * asize * sizeof(int));
48         if (!sbuf || !rbuf) {
49             fprintf(stderr, "Could not allocated buffers!\n");
50             MPI_Abort(comm, 1);
51         }
52
53         /* Load up the buffers */
54         for (i = 0; i < size * size; i++) {
55             sbuf[i] = i + 100 * rank;
56             rbuf[i] = -i;
57         }
58
59         /* Create and load the arguments to alltoallv */
60         sendcounts = (int *) malloc(size * sizeof(int));
61         recvcounts = (int *) malloc(size * sizeof(int));
62         rdispls = (int *) malloc(size * sizeof(int));
63         sdispls = (int *) malloc(size * sizeof(int));
64         if (!sendcounts || !recvcounts || !rdispls || !sdispls) {
65             fprintf(stderr, "Could not allocate arg items!\n");
66             MPI_Abort(comm, 1);
67         }
68         for (i = 0; i < size; i++) {
69             sendcounts[i] = i;
70             sdispls[i] = (i * (i + 1)) / 2;
71             recvcounts[i] = rank;
72             rdispls[i] = i * rank;
73         }
74         MTest_Alltoallv(sbuf, sendcounts, sdispls, MPI_INT,
75                         rbuf, recvcounts, rdispls, MPI_INT, comm);
76
77         /* Check rbuf */
78         for (i = 0; i < size; i++) {
79             p = rbuf + rdispls[i];
80             for (j = 0; j < rank; j++) {
81                 if (p[j] != i * 100 + (rank * (rank + 1)) / 2 + j) {
82                     fprintf(stderr, "[%d] got %d expected %d for %dth\n",
83                             rank, p[j], (i * (i + 1)) / 2 + j, j);
84                     err++;
85                 }
86             }
87         }
88
89         free(sdispls);
90         free(rdispls);
91         free(recvcounts);
92         free(sendcounts);
93         free(rbuf);
94         free(sbuf);
95         MTestFreeComm(&comm);
96     }
97
98     MTest_Finalize(err);
99     MPI_Finalize();
100     return 0;
101 }