1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2007 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
13 * This program tests that MPI_Comm_create applies to intercommunicators;
14 * this is an extension added in MPI-2
16 int main(int argc, char *argv[])
19 int size, isLeft, wrank;
20 MPI_Comm intercomm, newcomm;
21 MPI_Group oldgroup, newgroup;
23 MTest_Init(&argc, &argv);
25 MPI_Comm_size(MPI_COMM_WORLD, &size);
27 printf("This test requires at least 4 processes\n");
28 MPI_Abort(MPI_COMM_WORLD, 1);
30 MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
32 while (MTestGetIntercomm(&intercomm, &isLeft, 2)) {
33 int ranks[10], nranks, result;
35 if (intercomm == MPI_COMM_NULL)
38 MPI_Comm_group(intercomm, &oldgroup);
41 MTestPrintfMsg(1, "Creating a new intercomm 0-0\n");
42 MPI_Group_incl(oldgroup, nranks, ranks, &newgroup);
43 MPI_Comm_create(intercomm, newgroup, &newcomm);
45 /* Make sure that the new communicator has the appropriate pieces */
46 if (newcomm != MPI_COMM_NULL) {
47 int new_rsize, new_size, flag, commok = 1;
49 MPI_Comm_set_name(newcomm, (char *) "Single rank in each group");
50 MPI_Comm_test_inter(intercomm, &flag);
53 printf("[%d] Output communicator is not an intercomm\n", wrank);
57 MPI_Comm_remote_size(newcomm, &new_rsize);
58 MPI_Comm_size(newcomm, &new_size);
59 /* The new communicator has 1 process in each group */
62 printf("[%d] Remote size is %d, should be one\n", wrank, new_rsize);
67 printf("[%d] Local size is %d, should be one\n", wrank, new_size);
72 errs += MTestTestComm(newcomm);
75 MPI_Group_free(&newgroup);
76 if (newcomm != MPI_COMM_NULL) {
77 MPI_Comm_free(&newcomm);
80 /* Now, do a sort of dup, using the original group */
81 MTestPrintfMsg(1, "Creating a new intercomm (manual dup)\n");
82 MPI_Comm_create(intercomm, oldgroup, &newcomm);
83 MPI_Comm_set_name(newcomm, (char *) "Dup of original");
84 MTestPrintfMsg(1, "Creating a new intercomm (manual dup (done))\n");
86 MPI_Comm_compare(intercomm, newcomm, &result);
87 MTestPrintfMsg(1, "Result of comm/intercomm compare is %d\n", result);
88 if (result != MPI_CONGRUENT) {
89 const char *rname = 0;
104 printf("[%d] Expected MPI_CONGRUENT but saw %d (%s)", wrank, result, rname);
109 /* Try to communication between each member of intercomm */
110 errs += MTestTestComm(newcomm);
113 if (newcomm != MPI_COMM_NULL) {
114 MPI_Comm_free(&newcomm);
116 /* test that an empty group in either side of the intercomm results in
117 * MPI_COMM_NULL for all members of the comm */
119 /* left side reuses oldgroup, our local group in intercomm */
120 MPI_Comm_create(intercomm, oldgroup, &newcomm);
123 /* right side passes MPI_GROUP_EMPTY */
124 MPI_Comm_create(intercomm, MPI_GROUP_EMPTY, &newcomm);
126 if (newcomm != MPI_COMM_NULL) {
127 printf("[%d] expected MPI_COMM_NULL, but got a different communicator\n", wrank);
132 if (newcomm != MPI_COMM_NULL) {
133 MPI_Comm_free(&newcomm);
135 MPI_Group_free(&oldgroup);
136 MPI_Comm_free(&intercomm);
139 MTest_Finalize(errs);