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.
19 int main( int argc, char **argv )
22 int *sendbuf, recvbuf, *recvcounts;
23 int size, rank, i, sumval;
27 MPI_Init( &argc, &argv );
28 comm = MPI_COMM_WORLD;
30 MPI_Comm_size( comm, &size );
31 MPI_Comm_rank( comm, &rank );
32 sendbuf = (int *) malloc( size * sizeof(int) );
33 for (i=0; i<size; i++)
34 sendbuf[i] = rank + i;
35 recvcounts = (int *)malloc( size * sizeof(int) );
36 for (i=0; i<size; i++)
39 MPI_Reduce_scatter( sendbuf, &recvbuf, recvcounts, MPI_INT, MPI_SUM, comm );
41 sumval = size * rank + ((size - 1) * size)/2;
42 /* recvbuf should be size * (rank + i) */
43 if (recvbuf != sumval) {
45 fprintf( stdout, "Did not get expected value for reduce scatter\n" );
46 fprintf( stdout, "[%d] Got %d expected %d\n", rank, recvbuf, sumval );
49 MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
50 if (rank == 0 && toterr == 0) {
51 printf( " No Errors\n" );