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