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.
11 int main( int argc, char *argv[] )
14 MPI_Comm comm, dupcomm, dupcomm2;
18 int r1buf, r2buf, s1buf, s2buf;
21 MTest_Init( &argc, &argv );
23 while (MTestGetIntercomm( &comm, &isLeft, 2 )) {
24 if (comm == MPI_COMM_NULL) continue;
26 MPI_Comm_dup( comm, &dupcomm );
28 /* Check that there are separate contexts. We do this by setting
29 up nonblocking received on both communicators, and then
30 sending to them. If the contexts are different, tests on the
31 unsatisfied communicator should indicate no available message */
32 MPI_Comm_rank( comm, &rank );
37 /* These are send/receives to the process with rank zero
38 in the other group (these are intercommunicators) */
39 MPI_Irecv( &r1buf, 1, MPI_INT, 0, 0, dupcomm, &rreq[0] );
40 MPI_Irecv( &r2buf, 1, MPI_INT, 0, 0, comm, &rreq[1] );
41 MPI_Send( &s2buf, 1, MPI_INT, 0, 0, comm );
42 MPI_Waitsome(2, rreq, &count, indicies, MPI_STATUSES_IGNORE);
43 if (count != 1 || indicies[0] != 1) {
44 /* The only valid return is that exactly one message
47 if (count == 1 && indicies[0] != 1) {
48 printf( "Error in context values for intercomm\n" );
50 else if (count == 2) {
51 printf( "Error: two messages received!\n" );
55 printf( "Error: count = %d", count );
56 for (i=0; i<count; i++) {
57 printf( " indicies[%d] = %d", i, indicies[i] );
63 /* Make sure that we do not send the next message until
64 the other process (rank zero in the other group)
65 has also completed the first step */
66 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_BYTE, 0, 37,
67 MPI_BOTTOM, 0, MPI_BYTE, 0, 37, comm,
70 /* Complete the receive on dupcomm */
71 MPI_Send( &s1buf, 1, MPI_INT, 0, 0, dupcomm );
72 MPI_Wait( &rreq[0], MPI_STATUS_IGNORE );
75 printf( "Wrong value in communication on dupcomm %d != %d\n",
80 printf( "Wrong value in communication on comm %d != %d\n",
84 /* Try to duplicate a duplicated intercomm. (This caused problems
86 MPI_Comm_dup( dupcomm, &dupcomm2 );
87 MPI_Comm_free( &dupcomm2 );
88 MPI_Comm_free( &dupcomm );
89 MTestFreeComm( &comm );
91 MTest_Finalize( errs );