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 apparent non-commutative operators";
15 /* While the operator is in fact commutative, this forces the MPI code to
16 run the code that is used for non-commutative operators, and for
17 various message lengths. Other tests check truly non-commutative
20 void mysum( void *cinPtr, void *coutPtr, int *count, MPI_Datatype *dtype );
22 void mysum( void *cinPtr, void *coutPtr, int *count, MPI_Datatype *dtype )
24 const int *cin = (const int *)cinPtr;
25 int *cout = (int *)coutPtr;
30 int main( int argc, char *argv[] )
34 int minsize = 2, count;
39 MTest_Init( &argc, &argv );
41 MPI_Op_create( mysum, 0, &op );
43 while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
44 if (comm == MPI_COMM_NULL) continue;
45 MPI_Comm_size( comm, &size );
46 MPI_Comm_rank( comm, &rank );
48 for (count = 1; count < 65000; count = count * 2) {
50 buf = (int *)malloc( count * sizeof(int) );
51 for (i=0; i<count; i++) buf[i] = rank + i;
52 MPI_Allreduce( MPI_IN_PLACE, buf, count, MPI_INT, op, comm );
53 /* Check the results */
54 for (i=0; i<count; i++) {
55 int result = i * size + (size*(size-1))/2;
56 if (buf[i] != result) {
59 fprintf( stderr, "buf[%d] = %d expected %d\n",
66 MTestFreeComm( &comm );
70 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
71 /* Check to make sure that aliasing is disallowed correctly */
72 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
73 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
74 if (MPI_SUCCESS == MPI_Allreduce(&rank, &rank, 1, MPI_INT, MPI_OP_NULL, MPI_COMM_WORLD))
78 MTest_Finalize( errs );