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 / ic2.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2012 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7
8 /* regression test for ticket #1574
9  *
10  * Based on test code from N. Radclif @ Cray. */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <mpi.h>
15
16 int main(int argc, char **argv)
17 {
18     MPI_Comm c0, c1, ic;
19     MPI_Group g0, g1, gworld;
20     int a, b, c, d;
21     int rank, size, remote_leader, tag;
22     int ranks[2];
23     int errs = 0;
24
25     tag = 5;
26     c0 = c1 = ic = MPI_COMM_NULL;
27     g0 = g1 = gworld = MPI_GROUP_NULL;
28
29     MPI_Init(&argc, &argv);
30
31     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
32     MPI_Comm_size(MPI_COMM_WORLD, &size);
33
34     if (size < 33) {
35         printf("ERROR: this test requires at least 33 processes\n");
36         MPI_Abort(MPI_COMM_WORLD, 1);
37         return 1;
38     }
39
40     /* group of c0
41      * NOTE: a>=32 is essential for exercising the loop bounds bug from tt#1574 */
42     a = 32;
43     b = 24;
44
45     /* group of c1 */
46     c = 25;
47     d = 26;
48
49     MPI_Comm_group(MPI_COMM_WORLD, &gworld);
50
51     ranks[0] = a;
52     ranks[1] = b;
53     MPI_Group_incl(gworld, 2, ranks, &g0);
54     MPI_Comm_create(MPI_COMM_WORLD, g0, &c0);
55
56     ranks[0] = c;
57     ranks[1] = d;
58     MPI_Group_incl(gworld, 2, ranks, &g1);
59     MPI_Comm_create(MPI_COMM_WORLD, g1, &c1);
60
61     if (rank == a || rank == b) {
62         remote_leader = c;
63         MPI_Intercomm_create(c0, 0, MPI_COMM_WORLD, remote_leader, tag, &ic);
64     }
65     else if (rank == c || rank == d) {
66         remote_leader = a;
67         MPI_Intercomm_create(c1, 0, MPI_COMM_WORLD, remote_leader, tag, &ic);
68     }
69
70     MPI_Group_free(&g0);
71     MPI_Group_free(&g1);
72     MPI_Group_free(&gworld);
73
74     if (c0 != MPI_COMM_NULL)
75         MPI_Comm_free(&c0);
76     if (c1 != MPI_COMM_NULL)
77         MPI_Comm_free(&c1);
78     if (ic != MPI_COMM_NULL)
79         MPI_Comm_free(&ic);
80
81
82     MPI_Reduce((rank == 0 ? MPI_IN_PLACE : &errs), &errs, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
83     if (rank == 0) {
84         if (errs) {
85             printf("found %d errors\n", errs);
86         }
87         else {
88             printf(" No errors\n");
89         }
90     }
91     MPI_Finalize();
92
93     return 0;
94 }