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 allgatherv test";
16 int main( int argc, char *argv[] )
19 int *rbuf = 0, *sbuf = 0;
20 int *recvcounts, *recvdispls;
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) continue;
31 MPI_Comm_rank( comm, &rank );
32 MPI_Comm_remote_size( comm, &rsize );
34 /* To improve reporting of problems about operations, we
35 change the error handler to errors return */
36 MPI_Errhandler_set( comm, MPI_ERRORS_RETURN );
38 for (count = 1; count < 65000; count = 2 * count) {
39 /* The left group will send rank to the right group;
40 The right group will send -rank to the left group */
41 rbuf = (int *)malloc( count * rsize * sizeof(int) );
42 sbuf = (int *)malloc( count * sizeof(int) );
43 recvcounts = (int *) malloc( rsize * sizeof(int) );
44 recvdispls = (int *) malloc( rsize * sizeof(int) );
45 for (i=0; i<count*rsize; i++) rbuf[i] = -1;
46 for (i=0; i<rsize; i++) {
47 recvcounts[i] = count;
48 recvdispls[i] = i * count;
51 for (i=0; i<count; i++) sbuf[i] = i + rank*count;
54 for (i=0; i<count; i++) sbuf[i] = -(i + rank*count);
56 err = MPI_Allgatherv( sbuf, count, datatype,
57 rbuf, recvcounts, recvdispls, datatype,
61 MTestPrintError( err );
64 for (i=0; i<count*rsize; i++) {
71 for (i=0; i<count*rsize; i++) {
78 /* Use Allgather in a unidirectional way */
79 for (i=0; i<count*rsize; i++) rbuf[i] = -1;
81 err = MPI_Allgatherv( sbuf, 0, datatype,
82 rbuf, recvcounts, recvdispls, datatype,
86 MTestPrintError( err );
88 for (i=0; i<count*rsize; i++) {
95 for (i=0; i<rsize; i++) {
99 err = MPI_Allgatherv( sbuf, count, datatype,
100 rbuf, recvcounts, recvdispls, datatype, comm );
103 MTestPrintError( err );
105 for (i=0; i<count*rsize; i++) {
116 MTestFreeComm( &comm );
119 MTest_Finalize( errs );