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;
27 for (i = 0; i < n; i++)
31 int main(int argc, char *argv[])
35 int minsize = 2, count;
40 MTest_Init(&argc, &argv);
42 MPI_Op_create(mysum, 0, &op);
44 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
45 if (comm == MPI_COMM_NULL)
47 MPI_Comm_size(comm, &size);
48 MPI_Comm_rank(comm, &rank);
50 for (count = 1; count < 65000; count = count * 2) {
52 buf = (int *) malloc(count * sizeof(int));
53 for (i = 0; i < count; i++)
55 MPI_Allreduce(MPI_IN_PLACE, buf, count, MPI_INT, op, comm);
56 /* Check the results */
57 for (i = 0; i < count; i++) {
58 int result = i * size + (size * (size - 1)) / 2;
59 if (buf[i] != result) {
62 fprintf(stderr, "buf[%d] = %d expected %d\n", i, buf[i], result);