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 allgather test";
16 int main( int argc, char *argv[] )
19 int *rbuf = 0, *sbuf = 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 /* The left group will send rank to the right group;
39 The right group will send -rank to the left group */
40 rbuf = (int *)malloc( count * rsize * sizeof(int) );
41 sbuf = (int *)malloc( count * sizeof(int) );
42 for (i=0; i<count*rsize; i++) rbuf[i] = -1;
44 for (i=0; i<count; i++) sbuf[i] = i + rank*count;
47 for (i=0; i<count; i++) sbuf[i] = -(i + rank*count);
49 err = MPI_Allgather( sbuf, count, datatype,
50 rbuf, count, datatype, comm );
53 MTestPrintError( err );
56 for (i=0; i<count*rsize; i++) {
63 for (i=0; i<count*rsize; i++) {
70 /* Use Allgather in a unidirectional way */
71 for (i=0; i<count*rsize; i++) rbuf[i] = -1;
73 err = MPI_Allgather( sbuf, 0, datatype,
74 rbuf, count, datatype, comm );
77 MTestPrintError( err );
79 for (i=0; i<count*rsize; i++) {
86 err = MPI_Allgather( sbuf, count, datatype,
87 rbuf, 0, datatype, comm );
90 MTestPrintError( err );
92 for (i=0; i<count*rsize; i++) {
101 MTestFreeComm( &comm );
104 MTest_Finalize( errs );