Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MPI_INFO_ENV ... Still does nothing for now
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / comm_group_rand.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2003 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <mpi.h>
10 #include "mpitestconf.h"
11
12 #define LOOPS 100
13
14 int main(int argc, char **argv)
15 {
16     int rank, size, i, j, count;
17     MPI_Group full_group, sub_group;
18     int *included, *ranks;
19     MPI_Comm comm;
20
21     MPI_Init(NULL, NULL);
22     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
23     MPI_Comm_size(MPI_COMM_WORLD, &size);
24
25     ranks = malloc(size * sizeof(int));
26     included = malloc(size * sizeof(int));
27     MPI_Comm_group(MPI_COMM_WORLD, &full_group);
28
29     for (j = 0; j < LOOPS; j++) {
30         srand(j);       /* Deterministic seed */
31
32         count = 0;
33         for (i = 0; i < size; i++) {
34             if (rand() % 2) {   /* randomly include a rank */
35                 included[i] = 1;
36                 ranks[count++] = i;
37             }
38             else
39                 included[i] = 0;
40         }
41
42         MPI_Group_incl(full_group, count, ranks, &sub_group);
43
44         if (included[rank]) {
45             MPI_Comm_create_group(MPI_COMM_WORLD, sub_group, 0, &comm);
46             MPI_Barrier(comm);
47             MPI_Comm_free(&comm);
48         }
49
50         MPI_Group_free(&sub_group);
51     }
52
53     MPI_Group_free(&full_group);
54
55     if (rank == 0)
56         printf(" No Errors\n");
57
58     free(ranks);
59     free(included);
60     MPI_Finalize();
61
62     return 0;
63 }