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)
27 MPI_Comm_dup(comm, &dupcomm);
29 /* Check that there are separate contexts. We do this by setting
30 * up nonblocking received on both communicators, and then
31 * sending to them. If the contexts are different, tests on the
32 * unsatisfied communicator should indicate no available message */
33 MPI_Comm_rank(comm, &rank);
38 /* These are send/receives to the process with rank zero
39 * in the other group (these are intercommunicators) */
40 MPI_Irecv(&r1buf, 1, MPI_INT, 0, 0, dupcomm, &rreq[0]);
41 MPI_Irecv(&r2buf, 1, MPI_INT, 0, 0, comm, &rreq[1]);
42 MPI_Send(&s2buf, 1, MPI_INT, 0, 0, comm);
43 MPI_Waitsome(2, rreq, &count, indicies, MPI_STATUSES_IGNORE);
44 if (count != 1 || indicies[0] != 1) {
45 /* The only valid return is that exactly one message
46 * has been received */
48 if (count == 1 && indicies[0] != 1) {
49 printf("Error in context values for intercomm\n");
51 else if (count == 2) {
52 printf("Error: two messages received!\n");
56 printf("Error: count = %d", count);
57 for (i = 0; i < count; i++) {
58 printf(" indicies[%d] = %d", i, indicies[i]);
64 /* Make sure that we do not send the next message until
65 * the other process (rank zero in the other group)
66 * has also completed the first step */
67 MPI_Sendrecv(MPI_BOTTOM, 0, MPI_BYTE, 0, 37,
68 MPI_BOTTOM, 0, MPI_BYTE, 0, 37, comm, MPI_STATUS_IGNORE);
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", r1buf, s1buf);
79 printf("Wrong value in communication on comm %d != %d\n", r2buf, s2buf);
82 /* Try to duplicate a duplicated intercomm. (This caused problems
84 MPI_Comm_dup(dupcomm, &dupcomm2);
85 MPI_Comm_free(&dupcomm2);
86 MPI_Comm_free(&dupcomm);