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[] = "Simple intercomm reduce test";
16 int main( int argc, char *argv[] )
19 int *sendbuf = 0, *recvbuf=0;
20 int leftGroup, i, count, rank, rsize;
22 MPI_Datatype datatype;
24 MTest_Init( &argc, &argv );
27 /* Get an intercommunicator */
28 while (MTestGetIntercomm( &comm, &leftGroup, 4 )) {
29 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_Comm_set_errhandler( comm, MPI_ERRORS_RETURN );
39 for (count = 1; count < 65000; count = 2 * count) {
40 sendbuf = (int *)malloc( count * sizeof(int) );
41 recvbuf = (int *)malloc( count * sizeof(int) );
42 for (i=0; i<count; i++) {
47 err = MPI_Reduce( sendbuf, recvbuf, count, datatype, MPI_SUM,
48 (rank == 0) ? MPI_ROOT : MPI_PROC_NULL,
52 MTestPrintError( err );
54 /* Test that no other process in this group received the
55 broadcast, and that we got the right answers */
57 for (i=0; i<count; i++) {
58 if (recvbuf[i] != i * rsize) {
64 for (i=0; i<count; i++) {
65 if (recvbuf[i] != -1) {
72 /* In the right group */
73 for (i=0; i<count; i++) sendbuf[i] = i;
74 err = MPI_Reduce( sendbuf, recvbuf, count, datatype, MPI_SUM,
78 MTestPrintError( err );
80 /* Check that we have received no data */
81 for (i=0; i<count; i++) {
82 if (recvbuf[i] != -1) {
90 MTestFreeComm( &comm );
93 MTest_Finalize( errs );