1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2011 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
7 * Test of reduce scatter with large data on an intercommunicator
8 * (needed in MPICH to trigger the long-data algorithm)
10 * Each processor contributes its rank + the index to the reduction,
11 * then receives the ith sum
13 * Can be called with any number of processors.
20 #include "mpicolltest.h"
22 int main(int argc, char **argv)
26 int size, rsize, rank, i;
27 int recvcount, /* Each process receives this much data */
28 sendcount, /* Each process contributes this much data */
29 basecount; /* Unit of elements - basecount *rsize is recvcount,
32 long long *sendbuf, *recvbuf;
37 MTest_Init(&argc, &argv);
38 comm = MPI_COMM_WORLD;
42 while (MTestGetIntercomm(&comm, &isLeftGroup, 2)) {
43 if (comm == MPI_COMM_NULL)
46 MPI_Comm_remote_size(comm, &rsize);
47 MPI_Comm_size(comm, &size);
48 MPI_Comm_rank(comm, &rank);
51 printf("[%d] %s (%d,%d) remote %d\n", rank, isLeftGroup ? "L" : "R", rank, size, rsize);
54 recvcount = basecount * rsize;
55 sendcount = basecount * rsize * size;
57 recvcounts = (int *) malloc(size * sizeof(int));
59 fprintf(stderr, "Could not allocate %d int for recvcounts\n", size);
60 MPI_Abort(MPI_COMM_WORLD, 1);
62 for (i = 0; i < size; i++)
63 recvcounts[i] = recvcount;
65 sendbuf = (long long *) malloc(sendcount * sizeof(long long));
67 fprintf(stderr, "Could not allocate %d ints for sendbuf\n", sendcount);
68 MPI_Abort(MPI_COMM_WORLD, 1);
71 for (i = 0; i < sendcount; i++) {
72 sendbuf[i] = (long long) (rank * sendcount + i);
74 recvbuf = (long long *) malloc(recvcount * sizeof(long long));
76 fprintf(stderr, "Could not allocate %d ints for recvbuf\n", recvcount);
77 MPI_Abort(MPI_COMM_WORLD, 1);
79 for (i = 0; i < recvcount; i++) {
80 recvbuf[i] = (long long) (-i);
83 MTest_Reduce_scatter(sendbuf, recvbuf, recvcounts, MPI_LONG_LONG, MPI_SUM, comm);
85 /* Check received data */
86 for (i = 0; i < recvcount; i++) {
87 sumval = (long long) (sendcount) * (long long) ((rsize * (rsize - 1)) / 2) +
88 (long long) (i + rank * rsize * basecount) * (long long) rsize;
89 if (recvbuf[i] != sumval) {
92 fprintf(stdout, "Did not get expected value for reduce scatter\n");
93 fprintf(stdout, "[%d] %s recvbuf[%d] = %lld, expected %lld\n",
94 rank, isLeftGroup ? "L" : "R", i, recvbuf[i], sumval);
103 MTestFreeComm(&comm);