Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update mpich comm 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 #include "mpitestconf.h"
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <assert.h>
12
13 int main(int argc, char *argv[])
14 {
15     int size, rank, i, *excl;
16     MPI_Group world_group, even_group;
17     MPI_Comm even_comm;
18
19     MPI_Init(&argc, &argv);
20
21     MPI_Comm_size(MPI_COMM_WORLD, &size);
22     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
23
24     if (size % 2) {
25         fprintf(stderr, "this program requires a multiple of 2 number of processes\n");
26         MPI_Abort(MPI_COMM_WORLD, 1);
27     }
28
29     excl = malloc((size / 2) * sizeof(int));
30     assert(excl);
31
32     /* exclude the odd ranks */
33     for (i = 0; i < size / 2; i++)
34         excl[i] = (2 * i) + 1;
35
36     /* Create some groups */
37     MPI_Comm_group(MPI_COMM_WORLD, &world_group);
38     MPI_Group_excl(world_group, size / 2, excl, &even_group);
39     MPI_Group_free(&world_group);
40
41     if (rank % 2 == 0) {
42         /* Even processes create a group for themselves */
43         MPI_Comm_create_group(MPI_COMM_WORLD, even_group, 0, &even_comm);
44         MPI_Barrier(even_comm);
45         MPI_Comm_free(&even_comm);
46     }
47
48     MPI_Group_free(&even_group);
49     MPI_Barrier(MPI_COMM_WORLD);
50
51     if (rank == 0)
52         printf(" No errors\n");
53
54     free(excl);
55     MPI_Finalize();
56     return 0;
57 }