1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
13 static char MTEST_Descrip[] = "Test MPI_Allreduce with MPI_IN_PLACE";
16 int main( int argc, char *argv[] )
20 int minsize = 2, count;
24 MTest_Init( &argc, &argv );
26 while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
27 if (comm == MPI_COMM_NULL) continue;
28 MPI_Comm_size( comm, &size );
29 MPI_Comm_rank( comm, &rank );
31 for (count = 1; count < 65000; count = count * 2) {
33 buf = (int *)malloc( count * sizeof(int) );
34 for (i=0; i<count; i++) buf[i] = rank + i;
35 MPI_Allreduce( MPI_IN_PLACE, buf, count, MPI_INT, MPI_SUM, comm );
36 /* Check the results */
37 for (i=0; i<count; i++) {
38 int result = i * size + (size*(size-1))/2;
39 if (buf[i] != result) {
42 fprintf( stderr, "buf[%d] = %d expected %d\n",
49 MTestFreeComm( &comm );
52 MTest_Finalize( errs );