1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
7 * Test of reduce scatter.
9 * Each processor contributes its rank + the index to the reduction,
10 * then receives the ith sum
12 * Can be called with any number of processors.
18 #include "mpicolltest.h"
20 int main(int argc, char **argv)
23 int *sendbuf, recvbuf, *recvcounts;
24 int size, rank, i, sumval;
28 MPI_Init(&argc, &argv);
29 comm = MPI_COMM_WORLD;
31 MPI_Comm_size(comm, &size);
32 MPI_Comm_rank(comm, &rank);
33 sendbuf = (int *) malloc(size * sizeof(int));
34 for (i = 0; i < size; i++)
35 sendbuf[i] = rank + i;
36 recvcounts = (int *) malloc(size * sizeof(int));
37 for (i = 0; i < size; i++)
40 MTest_Reduce_scatter(sendbuf, &recvbuf, recvcounts, MPI_INT, MPI_SUM, comm);
42 sumval = size * rank + ((size - 1) * size) / 2;
43 /* recvbuf should be size * (rank + i) */
44 if (recvbuf != sumval) {
46 fprintf(stdout, "Did not get expected value for reduce scatter\n");
47 fprintf(stdout, "[%d] Got %d expected %d\n", rank, recvbuf, sumval);
50 MPI_Allreduce(&err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
51 if (rank == 0 && toterr == 0) {
52 printf(" No Errors\n");