1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2015 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
7 /* This test tests overlapping of Comm_idups with other comm. generations calls */
17 int main(int argc, char **argv)
25 MPI_Group dup_group, high_group, even_group;
26 MPI_Comm local_comm, inter_comm, test_comm, outcomm, dupcomm;
27 MPI_Comm idupcomms[NUM_IDUPS];
28 MPI_Request reqs[NUM_IDUPS];
30 MTest_Init(&argc, &argv);
31 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
32 MPI_Comm_size(MPI_COMM_WORLD, &size);
33 MPI_Comm_dup(MPI_COMM_WORLD, &dupcomm);
34 MPI_Comm_group(dupcomm, &dup_group);
37 printf("this test requires at least 2 processes\n");
38 MPI_Abort(MPI_COMM_WORLD, 1);
41 /* Idup MPI_COMM_WORLD multiple times */
42 for (i = 0; i < NUM_IDUPS; i++) {
43 MPI_Comm_idup(MPI_COMM_WORLD, &idupcomms[i], &reqs[i]);
46 /* Overlap pending idups with various comm generation functions */
49 MPI_Comm_dup(dupcomm, &outcomm);
50 errs += MTestTestComm(outcomm);
51 MTestFreeComm(&outcomm);
54 MPI_Comm_split(dupcomm, rank % 2, size - rank, &outcomm);
55 errs += MTestTestComm(outcomm);
56 MTestFreeComm(&outcomm);
58 /* Comm_create, high half of dupcomm */
59 ranges[0][0] = size / 2;
60 ranges[0][1] = size - 1;
62 MPI_Group_range_incl(dup_group, 1, ranges, &high_group);
63 MPI_Comm_create(dupcomm, high_group, &outcomm);
64 MPI_Group_free(&high_group);
65 errs += MTestTestComm(outcomm);
66 MTestFreeComm(&outcomm);
68 /* Comm_create_group, even ranks of dupcomm */
69 /* exclude the odd ranks */
70 excl = malloc((size / 2) * sizeof(int));
71 for (i = 0; i < size / 2; i++)
72 excl[i] = (2 * i) + 1;
74 MPI_Group_excl(dup_group, size / 2, excl, &even_group);
78 MPI_Comm_create_group(dupcomm, even_group, 0, &outcomm);
81 outcomm = MPI_COMM_NULL;
83 MPI_Group_free(&even_group);
85 errs += MTestTestComm(outcomm);
86 MTestFreeComm(&outcomm);
88 /* Intercomm_create & Intercomm_merge */
89 MPI_Comm_split(dupcomm, (rank < size / 2), rank, &local_comm);
94 else if (rank == size / 2) {
100 isLeft = rank < size / 2;
102 MPI_Intercomm_create(local_comm, 0, dupcomm, rleader, 99, &inter_comm);
103 MPI_Intercomm_merge(inter_comm, isLeft, &outcomm);
104 MPI_Comm_free(&local_comm);
106 errs += MTestTestComm(inter_comm);
107 MTestFreeComm(&inter_comm);
109 errs += MTestTestComm(outcomm);
110 MTestFreeComm(&outcomm);
112 MPI_Waitall(NUM_IDUPS, reqs, MPI_STATUSES_IGNORE);
113 for (i = 0; i < NUM_IDUPS; i++) {
114 errs += MTestTestComm(idupcomms[i]);
115 MPI_Comm_free(&idupcomms[i]);
118 MPI_Group_free(&dup_group);
119 MPI_Comm_free(&dupcomm);
121 MTest_Finalize(errs);