1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2010 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
7 * Test of reduce scatter with large data (needed in MPICH to trigger the
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.
21 int main(int argc, char **argv)
24 int *sendbuf, *recvbuf;
25 int size, rank, i, j, idx, mycount, sumval;
29 MTest_Init(&argc, &argv);
30 comm = MPI_COMM_WORLD;
32 MPI_Comm_size(comm, &size);
33 MPI_Comm_rank(comm, &rank);
34 mycount = (1024 * 1024) / size;
36 sendbuf = (int *) malloc(mycount * size * sizeof(int));
38 fprintf(stderr, "Could not allocate %d ints for sendbuf\n", mycount * size);
39 MPI_Abort(MPI_COMM_WORLD, 1);
42 for (i = 0; i < size; i++) {
43 for (j = 0; j < mycount; j++) {
44 sendbuf[idx++] = rank + i;
47 recvbuf = (int *) malloc(mycount * sizeof(int));
49 fprintf(stderr, "Could not allocate %d ints for recvbuf\n", mycount);
50 MPI_Abort(MPI_COMM_WORLD, 1);
53 MPI_Reduce_scatter_block(sendbuf, recvbuf, mycount, MPI_INT, MPI_SUM, comm);
55 sumval = size * rank + ((size - 1) * size) / 2;
56 /* recvbuf should be size * (rank + i) */
57 for (i = 0; i < mycount; i++) {
58 if (recvbuf[i] != sumval) {
60 fprintf(stdout, "Did not get expected value for reduce scatter\n");
61 fprintf(stdout, "[%d] Got %d expected %d\n", rank, recvbuf[i], sumval);
65 MPI_Reduce_scatter_block(MPI_IN_PLACE, sendbuf, mycount, MPI_INT, MPI_SUM, comm);
67 sumval = size * rank + ((size - 1) * size) / 2;
68 /* recv'ed values for my process should be size * (rank + i) */
69 for (i = 0; i < mycount; i++) {
70 if (sendbuf[i] != sumval) {
72 fprintf(stdout, "Did not get expected value for reduce scatter (in place)\n");
73 fprintf(stdout, "[%d] Got %d expected %d\n", rank, sendbuf[i], sumval);