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.
11 #include "mpicolltest.h"
14 static char MTEST_Descrip[] = "Simple intercomm allreduce test";
17 int main(int argc, char *argv[])
20 int *sendbuf = 0, *recvbuf = 0;
21 int leftGroup, i, count, rank, rsize;
23 MPI_Datatype datatype;
25 MTest_Init(&argc, &argv);
28 /* Get an intercommunicator */
29 while (MTestGetIntercomm(&comm, &leftGroup, 4)) {
30 if (comm == MPI_COMM_NULL)
32 MPI_Comm_rank(comm, &rank);
33 MPI_Comm_remote_size(comm, &rsize);
35 /* To improve reporting of problems about operations, we
36 * change the error handler to errors return */
37 MPI_Errhandler_set(comm, MPI_ERRORS_RETURN);
39 for (count = 1; count < 65000; count = 2 * count) {
40 /* printf("rank = %d(%d)\n", rank, leftGroup); fflush(stdout); */
41 sendbuf = (int *) malloc(count * sizeof(int));
42 recvbuf = (int *) malloc(count * sizeof(int));
44 for (i = 0; i < count; i++)
48 for (i = 0; i < count; i++)
51 for (i = 0; i < count; i++)
53 err = MTest_Allreduce(sendbuf, recvbuf, count, datatype, MPI_SUM, comm);
58 /* In each process should be the sum of the values from the
61 for (i = 0; i < count; i++) {
62 if (recvbuf[i] != -i * rsize) {
65 fprintf(stderr, "recvbuf[%d] = %d\n", i, recvbuf[i]);
71 for (i = 0; i < count; i++) {
72 if (recvbuf[i] != i * rsize) {
75 fprintf(stderr, "recvbuf[%d] = %d\n", i, recvbuf[i]);