1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2001 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
11 int main(int argc, char *argv[])
13 MPI_Group g1, g2, g4, g5, g45, selfgroup, g6;
14 int ranks[16], size, rank, myrank, range[1][3];
16 int i, rin[16], rout[16], result;
18 MPI_Init(&argc, &argv);
20 MPI_Comm_group(MPI_COMM_WORLD, &g1);
21 MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
22 MPI_Comm_size(MPI_COMM_WORLD, &size);
24 fprintf(stderr, "Test requires 8 processes (16 prefered) only %d provided\n", size);
28 /* 16 members, this process is rank 0, return in group 1 */
36 MPI_Group_incl(g1, 3, ranks, &g2);
38 /* Check the resulting group */
39 MPI_Group_size(g2, &size);
40 MPI_Group_rank(g2, &rank);
43 fprintf(stderr, "Size should be %d, is %d\n", 3, size);
47 fprintf(stderr, "Rank should be %d, is %d\n", 0, rank);
54 MPI_Group_translate_ranks(g2, 3, rin, g1, rout);
55 for (i = 0; i < 3; i++) {
56 if (rout[i] != ranks[i]) {
57 fprintf(stderr, "translated rank[%d] %d should be %d\n", i, rout[i], ranks[i]);
62 /* Translate the process of the self group against another group */
63 MPI_Comm_group(MPI_COMM_SELF, &selfgroup);
65 MPI_Group_translate_ranks(selfgroup, 1, rin, g1, rout);
66 if (rout[0] != myrank) {
67 fprintf(stderr, "translated of self is %d should be %d\n", rout[0], myrank);
71 for (i = 0; i < size; i++)
73 MPI_Group_translate_ranks(g1, size, rin, selfgroup, rout);
74 for (i = 0; i < size; i++) {
75 if (i == myrank && rout[i] != 0) {
76 fprintf(stderr, "translated world to self of %d is %d\n", i, rout[i]);
79 else if (i != myrank && rout[i] != MPI_UNDEFINED) {
80 fprintf(stderr, "translated world to self of %d should be undefined, is %d\n",
85 MPI_Group_free(&selfgroup);
87 /* Exclude everyone in our group */
89 int ii, *lranks, g1size;
91 MPI_Group_size(g1, &g1size);
93 lranks = (int *) malloc(g1size * sizeof(int));
94 for (ii = 0; ii < g1size; ii++)
96 MPI_Group_excl(g1, g1size, lranks, &g6);
97 if (g6 != MPI_GROUP_EMPTY) {
98 fprintf(stderr, "Group formed by excluding all ranks not empty\n");
105 /* Add tests for additional group operations */
109 * intersect (w, g2) => g2
110 * intersect (w, g3) => g3
111 * intersect (g2, g3) => empty
115 * union(g4, g5) => world
116 * g6 = rincl n-1:1:-1
117 * g7 = rexcl n-1:1:-1
118 * union(g6, g7) => concat of entries, similar to world
124 range[0][1] = size - 1;
126 MPI_Group_range_excl(g1, 1, range, &g5);
129 range[0][1] = size - 1;
131 MPI_Group_range_incl(g1, 1, range, &g4);
133 MPI_Group_union(g4, g5, &g45);
135 MPI_Group_compare(MPI_GROUP_EMPTY, g4, &result);
136 if (result != MPI_UNEQUAL) {
138 fprintf(stderr, "Comparison with empty group gave %d, not 3\n", result);
142 MPI_Group_free(&g45);
144 /* Now, duplicate the test, but using negative strides */
145 range[0][0] = size - 1;
148 MPI_Group_range_excl(g1, 1, range, &g5);
150 range[0][0] = size - 1;
153 MPI_Group_range_incl(g1, 1, range, &g4);
155 MPI_Group_union(g4, g5, &g45);
157 MPI_Group_compare(MPI_GROUP_EMPTY, g4, &result);
158 if (result != MPI_UNEQUAL) {
161 "Comparison with empty group (formed with negative strides) gave %d, not 3\n",
166 MPI_Group_free(&g45);
171 printf(" No Errors\n");
174 printf("Found %d errors\n", errs);