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_comm.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 world_group, high_group, even_group;
26     MPI_Comm local_comm, inter_comm, test_comm, outcomm;
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_group(MPI_COMM_WORLD, &world_group);
34
35     if (size < 2) {
36         printf("this test requires at least 2 processes\n");
37         MPI_Abort(MPI_COMM_WORLD, 1);
38     }
39
40     /* Idup MPI_COMM_WORLD multiple times */
41     for (i = 0; i < NUM_IDUPS; i++) {
42         MPI_Comm_idup(MPI_COMM_WORLD, &idupcomms[i], &reqs[i]);
43     }
44
45     /* Overlap pending idups with various comm generation functions */
46
47     /* Comm_dup */
48     MPI_Comm_dup(MPI_COMM_WORLD, &outcomm);
49     errs += MTestTestComm(outcomm);
50     MTestFreeComm(&outcomm);
51
52     /* Comm_split */
53     MPI_Comm_split(MPI_COMM_WORLD, rank % 2, size - rank, &outcomm);
54     errs += MTestTestComm(outcomm);
55     MTestFreeComm(&outcomm);
56
57     /* Comm_create, high half of MPI_COMM_WORLD */
58     ranges[0][0] = size / 2;
59     ranges[0][1] = size - 1;
60     ranges[0][2] = 1;
61     MPI_Group_range_incl(world_group, 1, ranges, &high_group);
62     MPI_Comm_create(MPI_COMM_WORLD, high_group, &outcomm);
63     MPI_Group_free(&high_group);
64     errs += MTestTestComm(outcomm);
65     MTestFreeComm(&outcomm);
66
67     /* Comm_create_group, even ranks of MPI_COMM_WORLD */
68     /* exclude the odd ranks */
69     excl = malloc((size / 2) * sizeof(int));
70     for (i = 0; i < size / 2; i++)
71         excl[i] = (2 * i) + 1;
72
73     MPI_Group_excl(world_group, size / 2, excl, &even_group);
74     free(excl);
75
76     if (rank % 2 == 0) {
77         MPI_Comm_create_group(MPI_COMM_WORLD, even_group, 0, &outcomm);
78     }
79     else {
80         outcomm = MPI_COMM_NULL;
81     }
82     MPI_Group_free(&even_group);
83
84     errs += MTestTestComm(outcomm);
85     MTestFreeComm(&outcomm);
86
87     /* Intercomm_create & Intercomm_merge */
88     MPI_Comm_split(MPI_COMM_WORLD, (rank < size / 2), rank, &local_comm);
89
90     if (rank == 0) {
91         rleader = size / 2;
92     }
93     else if (rank == size / 2) {
94         rleader = 0;
95     }
96     else {
97         rleader = -1;
98     }
99     isLeft = rank < size / 2;
100
101     MPI_Intercomm_create(local_comm, 0, MPI_COMM_WORLD, rleader, 99, &inter_comm);
102     MPI_Intercomm_merge(inter_comm, isLeft, &outcomm);
103     MPI_Comm_free(&local_comm);
104
105     errs += MTestTestComm(inter_comm);
106     MTestFreeComm(&inter_comm);
107
108     errs += MTestTestComm(outcomm);
109     MTestFreeComm(&outcomm);
110
111     MPI_Waitall(NUM_IDUPS, reqs, MPI_STATUSES_IGNORE);
112     for (i = 0; i < NUM_IDUPS; i++) {
113         errs += MTestTestComm(idupcomms[i]);
114         MPI_Comm_free(&idupcomms[i]);
115     }
116
117     MPI_Group_free(&world_group);
118
119     MTest_Finalize(errs);
120     MPI_Finalize();
121     return 0;
122 }