Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge tag 'v3_9_90' into hypervisor
[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     }
29
30     excl = malloc((size / 2) * sizeof(int));
31     assert(excl);
32
33     /* exclude the odd ranks */
34     for (i = 0; i < size / 2; i++)
35         excl[i] = (2 * i) + 1;
36
37     /* Create some groups */
38     MPI_Comm_group(MPI_COMM_WORLD, &world_group);
39     MPI_Group_excl(world_group, size / 2, excl, &even_group);
40     MPI_Group_free(&world_group);
41
42 #if !defined(USE_STRICT_MPI) && defined(MPICH)
43     if (rank % 2 == 0) {
44         /* Even processes create a group for themselves */
45         MPI_Comm_create_group(MPI_COMM_WORLD, even_group, 0, &even_comm);
46         MPI_Barrier(even_comm);
47         MPI_Comm_free(&even_comm);
48     }
49 #endif /* USE_STRICT_MPI */
50
51     MPI_Group_free(&even_group);
52     MPI_Barrier(MPI_COMM_WORLD);
53
54     if (rank == 0)
55         printf(" No errors\n");
56
57     MPI_Finalize();
58     return 0;
59 }