2 * Test of reduce scatter.
4 * Each processor contributes its rank + the index to the reduction,
5 * then receives the ith sum
7 * Can be called with any number of processors.
14 int main( int argc, char **argv )
17 int *sendbuf, *recvbuf, *recvcounts;
18 int size, rank, i, sumval;
22 MPI_Init( &argc, &argv );
23 comm = MPI_COMM_WORLD;
25 MPI_Comm_size( comm, &size );
26 MPI_Comm_rank( comm, &rank );
27 sendbuf = (int *) malloc( size * sizeof(int) );
28 for (i=0; i<size; i++)
29 sendbuf[i] = rank + i;
30 recvcounts = (int *)malloc( size * sizeof(int) );
31 recvbuf = (int *)malloc( size * sizeof(int) );
32 for (i=0; i<size; i++)
34 MPI_Reduce_scatter( sendbuf, recvbuf, recvcounts, MPI_INT, MPI_SUM, comm );
35 sumval = size * rank + ((size - 1) * size)/2;
36 /* recvbuf should be size * (rank + i) */
37 if (recvbuf[0] != sumval) {
39 fprintf( stdout, "Did not get expected value for reduce scatter\n" );
40 fprintf( stdout, "[%d] Got %d expected %d\n", rank, recvbuf[0], sumval );
43 MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
44 if (rank == 0 && toterr == 0) {
45 printf( " No Errors\n" );