Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add mpich3 topo tests
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / comm_create_group.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2011 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 /* USE_STRICT_MPI may be defined in mpitestconf.h */
8 #include "mpitestconf.h"
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdlib.h>
12 #include <assert.h>
13
14 int main(int argc, char *argv[])
15 {
16     int size, rank, i, *excl;
17     MPI_Group world_group, even_group;
18     MPI_Comm  __attribute__((unused)) even_comm;
19
20     MPI_Init(&argc, &argv);
21
22     MPI_Comm_size(MPI_COMM_WORLD, &size);
23     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
24
25     if (size % 2) {
26         fprintf(stderr, "this program requires a multiple of 2 number of processes\n");
27         MPI_Abort(MPI_COMM_WORLD, 1);
28         exit(1);
29     }
30
31     excl = malloc((size / 2) * sizeof(int));
32     assert(excl);
33
34     /* exclude the odd ranks */
35     for (i = 0; i < size / 2; i++)
36         excl[i] = (2 * i) + 1;
37
38     /* Create some groups */
39     MPI_Comm_group(MPI_COMM_WORLD, &world_group);
40     MPI_Group_excl(world_group, size / 2, excl, &even_group);
41     MPI_Group_free(&world_group);
42
43 #if !defined(USE_STRICT_MPI) && defined(MPICH)
44     if (rank % 2 == 0) {
45         /* Even processes create a group for themselves */
46         MPI_Comm_create_group(MPI_COMM_WORLD, even_group, 0, &even_comm);
47         MPI_Barrier(even_comm);
48         MPI_Comm_free(&even_comm);
49     }
50 #endif /* USE_STRICT_MPI */
51
52     MPI_Group_free(&even_group);
53     MPI_Barrier(MPI_COMM_WORLD);
54
55     if (rank == 0)
56         printf(" No errors\n");
57
58     MPI_Finalize();
59     return 0;
60 }