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.
20 #include "mpicolltest.h"
22 /* Limit the number of error reports */
25 int main(int argc, char **argv)
28 int *sendbuf, *recvbuf, *recvcounts;
29 int size, rank, i, j, idx, mycount, sumval;
33 MTest_Init(&argc, &argv);
34 comm = MPI_COMM_WORLD;
36 MPI_Comm_size(comm, &size);
37 MPI_Comm_rank(comm, &rank);
38 recvcounts = (int *) malloc(size * sizeof(int));
40 fprintf(stderr, "Could not allocate %d ints for recvcounts\n", size);
41 MPI_Abort(MPI_COMM_WORLD, 1);
43 mycount = (1024 * 1024) / size;
44 for (i = 0; i < size; i++)
45 recvcounts[i] = mycount;
46 sendbuf = (int *) malloc(mycount * size * sizeof(int));
48 fprintf(stderr, "Could not allocate %d ints for sendbuf\n", mycount * size);
49 MPI_Abort(MPI_COMM_WORLD, 1);
52 for (i = 0; i < size; i++) {
53 for (j = 0; j < mycount; j++) {
54 sendbuf[idx++] = rank + i;
57 recvbuf = (int *) malloc(mycount * sizeof(int));
59 fprintf(stderr, "Could not allocate %d ints for recvbuf\n", mycount);
60 MPI_Abort(MPI_COMM_WORLD, 1);
62 for (i = 0; i < mycount; i++) {
66 MTest_Reduce_scatter(sendbuf, recvbuf, recvcounts, MPI_INT, MPI_SUM, comm);
68 sumval = size * rank + ((size - 1) * size) / 2;
69 /* recvbuf should be size * (rank + i) */
70 for (i = 0; i < mycount; i++) {
71 if (recvbuf[i] != sumval) {
73 if (err < MAX_ERRORS) {
74 fprintf(stdout, "Did not get expected value for reduce scatter\n");
75 fprintf(stdout, "[%d] Got recvbuf[%d] = %d expected %d\n",
76 rank, i, recvbuf[i], sumval);
81 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
82 MTest_Reduce_scatter(MPI_IN_PLACE, sendbuf, recvcounts, MPI_INT, MPI_SUM, comm);
84 sumval = size * rank + ((size - 1) * size) / 2;
85 /* recv'ed values for my process should be size * (rank + i) */
86 for (i = 0; i < mycount; i++) {
87 if (sendbuf[i] != sumval) {
89 if (err < MAX_ERRORS) {
90 fprintf(stdout, "Did not get expected value for reduce scatter (in place)\n");
91 fprintf(stdout, "[%d] Got buf[%d] = %d expected %d\n", rank, i, sendbuf[i], sumval);