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.
21 int main( int argc, char **argv )
24 int *sendbuf, *recvbuf;
25 int size, rank, i, j, idx, mycount, sumval;
29 MTest_Init( &argc, &argv );
30 comm = MPI_COMM_WORLD;
32 MPI_Comm_size( comm, &size );
33 MPI_Comm_rank( comm, &rank );
34 mycount = (1024 * 1024) / size;
36 sendbuf = (int *) malloc( mycount * size * sizeof(int) );
38 fprintf( stderr, "Could not allocate %d ints for sendbuf\n",
40 MPI_Abort( MPI_COMM_WORLD, 1 );
43 for (i=0; i<size; i++) {
44 for (j=0; j<mycount; j++) {
45 sendbuf[idx++] = rank + i;
48 recvbuf = (int *)malloc( mycount * sizeof(int) );
50 fprintf( stderr, "Could not allocate %d ints for recvbuf\n",
52 MPI_Abort( MPI_COMM_WORLD, 1 );
55 MPI_Reduce_scatter_block( sendbuf, recvbuf, mycount, MPI_INT, MPI_SUM,
58 sumval = size * rank + ((size - 1) * size)/2;
59 /* recvbuf should be size * (rank + i) */
60 for (i=0; i<mycount; i++) {
61 if (recvbuf[i] != sumval) {
63 fprintf( stdout, "Did not get expected value for reduce scatter\n" );
64 fprintf( stdout, "[%d] Got %d expected %d\n", rank, recvbuf[i], sumval );
68 MPI_Reduce_scatter_block( MPI_IN_PLACE, sendbuf, mycount, MPI_INT, MPI_SUM,
71 sumval = size * rank + ((size - 1) * size)/2;
72 /* recv'ed values for my process should be size * (rank + i) */
73 for (i=0; i<mycount; i++) {
74 if (sendbuf[rank*mycount+i] != sumval) {
76 fprintf( stdout, "Did not get expected value for reduce scatter (in place)\n" );
77 fprintf( stdout, "[%d] Got %d expected %d\n", rank, sendbuf[rank*mycount+i], sumval );
84 MTest_Finalize( err );