1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2004 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
13 static char MTEST_Descrip[] = "Test intercomm merge, including the choice of the high value";
16 int main(int argc, char *argv[])
19 int rank, size, rsize;
23 MPI_Comm comm, comm1, comm2, comm3, comm4;
25 MTest_Init(&argc, &argv);
27 /* The following illustrates the use of the routines to
28 * run through a selection of communicators and datatypes.
29 * Use subsets of these for tests that do not involve combinations
30 * of communicators, datatypes, and counts of datatypes */
31 while (MTestGetIntercomm(&comm, &isLeft, minsize)) {
32 if (comm == MPI_COMM_NULL)
34 /* Determine the sender and receiver */
35 MPI_Comm_rank(comm, &rank);
36 MPI_Comm_remote_size(comm, &rsize);
37 MPI_Comm_size(comm, &size);
39 /* Try building intercomms */
40 MPI_Intercomm_merge(comm, isLeft, &comm1);
41 /* Check the size and ranks */
42 MPI_Comm_size(comm1, &nsize);
43 MPI_Comm_rank(comm1, &nrank);
44 if (nsize != size + rsize) {
46 printf("(1) Comm size is %d but should be %d\n", nsize, size + rsize);
48 /* The left processes should be high */
49 if (nrank != rsize + rank) {
51 printf("(1) rank for high process is %d should be %d\n", nrank, rsize + rank);
55 /* The right processes should be low */
58 printf("(1) rank for low process is %d should be %d\n", nrank, rank);
63 MPI_Intercomm_merge(comm, !isLeft, &comm2);
64 /* Check the size and ranks */
65 MPI_Comm_size(comm1, &nsize);
66 MPI_Comm_rank(comm1, &nrank);
67 if (nsize != size + rsize) {
69 printf("(2) Comm size is %d but should be %d\n", nsize, size + rsize);
71 /* The right processes should be high */
72 if (nrank != rsize + rank) {
74 printf("(2) rank for high process is %d should be %d\n", nrank, rsize + rank);
78 /* The left processes should be low */
81 printf("(2) rank for low process is %d should be %d\n", nrank, rank);
87 MPI_Intercomm_merge(comm, 0, &comm3);
89 MPI_Intercomm_merge(comm, 1, &comm4);
91 MPI_Comm_free(&comm1);
92 MPI_Comm_free(&comm2);
93 MPI_Comm_free(&comm3);
94 MPI_Comm_free(&comm4);