1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2011 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
7 * Test of reduce scatter block with large data on an intercommunicator
8 * (needed in MPICH to trigger the long-data algorithm)
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 size, rsize, rank, i;
25 int recvcount, /* Each process receives this much data */
26 sendcount, /* Each process contributes this much data */
27 basecount; /* Unit of elements - basecount *rsize is recvcount,
30 long long *sendbuf, *recvbuf;
35 MTest_Init( &argc, &argv );
36 comm = MPI_COMM_WORLD;
40 while (MTestGetIntercomm( &comm, &isLeftGroup, 2 )) {
41 if (comm == MPI_COMM_NULL) continue;
43 MPI_Comm_remote_size( comm, &rsize );
44 MPI_Comm_size( comm, &size );
45 MPI_Comm_rank( comm, &rank );
48 printf( "[%d] %s (%d,%d) remote %d\n", rank,
49 isLeftGroup ? "L" : "R",
53 recvcount = basecount * rsize;
54 sendcount = basecount * rsize * size;
56 sendbuf = (long long *) malloc( sendcount * sizeof(long long) );
58 fprintf( stderr, "Could not allocate %d ints for sendbuf\n",
60 MPI_Abort( MPI_COMM_WORLD, 1 );
64 for (i=0; i<sendcount; i++) {
65 sendbuf[i] = (long long)(rank*sendcount + i);
67 recvbuf = (long long *)malloc( recvcount * sizeof(long long) );
69 fprintf( stderr, "Could not allocate %d ints for recvbuf\n",
71 MPI_Abort( MPI_COMM_WORLD, 1 );
74 for (i=0; i<recvcount; i++) {
75 recvbuf[i] = (long long)(-i);
78 MPI_Reduce_scatter_block( sendbuf, recvbuf, recvcount, MPI_LONG_LONG,
81 /* Check received data */
82 for (i=0; i<recvcount; i++) {
83 sumval = (long long)(sendcount) * (long long)((rsize * (rsize-1))/2) +
84 (long long)(i + rank * rsize * basecount) * (long long)rsize;
85 if (recvbuf[i] != sumval) {
88 fprintf( stdout, "Did not get expected value for reduce scatter\n" );
89 fprintf( stdout, "[%d] %s recvbuf[%d] = %lld, expected %lld\n",
91 isLeftGroup ? "L" : "R",
92 i, recvbuf[i], sumval );
100 MTestFreeComm( &comm );
103 MTest_Finalize( err );