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[] = "A simple test of Reduce with all choices of root process";
16 int main( int argc, char *argv[] )
20 int *sendbuf, *recvbuf, i;
21 int minsize = 2, count;
24 MTest_Init( &argc, &argv );
26 while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
27 if (comm == MPI_COMM_NULL) continue;
28 /* Determine the sender and receiver */
29 MPI_Comm_rank( comm, &rank );
30 MPI_Comm_size( comm, &size );
32 for (count = 1; count < 130000; count = count * 2) {
33 sendbuf = (int *)malloc( count * sizeof(int) );
34 recvbuf = (int *)malloc( count * sizeof(int) );
35 for (root = 0; root < size; root ++) {
36 for (i=0; i<count; i++) sendbuf[i] = i;
37 for (i=0; i<count; i++) recvbuf[i] = -1;
38 MPI_Reduce( sendbuf, recvbuf, count, MPI_INT, MPI_SUM,
41 for (i=0; i<count; i++) {
42 if (recvbuf[i] != i * size) {
52 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
54 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
55 if (MPI_SUCCESS == MPI_Reduce(&rank, &rank, 1, MPI_INT, MPI_SUM, 0, comm))
60 MTestFreeComm( &comm );
63 MTest_Finalize( errs );