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 allreduce 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) continue;
30 MPI_Comm_rank( comm, &rank );
31 MPI_Comm_remote_size( comm, &rsize );
33 /* To improve reporting of problems about operations, we
34 change the error handler to errors return */
35 MPI_Errhandler_set( comm, MPI_ERRORS_RETURN );
37 for (count = 1; count < 65000; count = 2 * count) {
38 /* printf( "rank = %d(%d)\n", rank, leftGroup ); fflush(stdout); */
39 sendbuf = (int *)malloc( count * sizeof(int) );
40 recvbuf = (int *)malloc( count * sizeof(int) );
42 for (i=0; i<count; i++) sendbuf[i] = i;
45 for (i=0; i<count; i++) sendbuf[i] = -i;
47 for (i=0; i<count; i++) recvbuf[i] = 0;
48 err = MPI_Allreduce( sendbuf, recvbuf, count, datatype,
52 MTestPrintError( err );
54 /* In each process should be the sum of the values from the
57 for (i=0; i<count; i++) {
58 if (recvbuf[i] != -i * rsize) {
61 fprintf( stderr, "recvbuf[%d] = %d\n", i, recvbuf[i] );
67 for (i=0; i<count; i++) {
68 if (recvbuf[i] != i * rsize) {
71 fprintf( stderr, "recvbuf[%d] = %d\n", i, recvbuf[i] );
79 MTestFreeComm( &comm );
82 MTest_Finalize( errs );