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)
29 MPI_Comm_size(comm, &size);
30 MPI_Comm_rank(comm, &rank);
32 for (count = 1; count < 65000; count = count * 2) {
34 buf = (int *) malloc(count * sizeof(int));
35 for (i = 0; i < count; i++)
37 MPI_Allreduce(MPI_IN_PLACE, buf, count, MPI_INT, MPI_SUM, comm);
38 /* Check the results */
39 for (i = 0; i < count; i++) {
40 int result = i * size + (size * (size - 1)) / 2;
41 if (buf[i] != result) {
44 fprintf(stderr, "buf[%d] = %d expected %d\n", i, buf[i], result);