Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce some tests duration as comm_create takes longer now (comms)
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / comm_idup_comm2.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2015 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 /* This test tests overlapping of Comm_idups with other comm. generations calls */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include "mpi.h"
13 #include "mpitest.h"
14
15 #define NUM_IDUPS 5
16
17 int main(int argc, char **argv)
18 {
19     int errs = 0;
20     int i;
21     int rank, size;
22     int *excl;
23     int ranges[1][3];
24     int isLeft, rleader;
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];
29
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);
35
36     if (size < 2) {
37         printf("this test requires at least 2 processes\n");
38         MPI_Abort(MPI_COMM_WORLD, 1);
39     }
40
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]);
44     }
45
46     /* Overlap pending idups with various comm generation functions */
47
48     /* Comm_dup */
49     MPI_Comm_dup(dupcomm, &outcomm);
50     errs += MTestTestComm(outcomm);
51     MTestFreeComm(&outcomm);
52
53     /* Comm_split */
54     MPI_Comm_split(dupcomm, rank % 2, size - rank, &outcomm);
55     errs += MTestTestComm(outcomm);
56     MTestFreeComm(&outcomm);
57
58     /* Comm_create, high half of dupcomm */
59     ranges[0][0] = size / 2;
60     ranges[0][1] = size - 1;
61     ranges[0][2] = 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);
67
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;
73
74     MPI_Group_excl(dup_group, size / 2, excl, &even_group);
75     free(excl);
76
77     if (rank % 2 == 0) {
78         MPI_Comm_create_group(dupcomm, even_group, 0, &outcomm);
79     }
80     else {
81         outcomm = MPI_COMM_NULL;
82     }
83     MPI_Group_free(&even_group);
84
85     errs += MTestTestComm(outcomm);
86     MTestFreeComm(&outcomm);
87
88     /* Intercomm_create & Intercomm_merge */
89     MPI_Comm_split(dupcomm, (rank < size / 2), rank, &local_comm);
90
91     if (rank == 0) {
92         rleader = size / 2;
93     }
94     else if (rank == size / 2) {
95         rleader = 0;
96     }
97     else {
98         rleader = -1;
99     }
100     isLeft = rank < size / 2;
101
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);
105
106     errs += MTestTestComm(inter_comm);
107     MTestFreeComm(&inter_comm);
108
109     errs += MTestTestComm(outcomm);
110     MTestFreeComm(&outcomm);
111
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]);
116     }
117
118     MPI_Group_free(&dup_group);
119     MPI_Comm_free(&dupcomm);
120
121     MTest_Finalize(errs);
122     MPI_Finalize();
123     return 0;
124 }