Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[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 /* USE_STRICT_MPI may be defined in mpitestconf.h */
11 #include "mpitestconf.h"
12
13 #define LOOPS 100
14
15 int main(int argc, char **argv)
16 {
17     int rank, size, i, j, count;
18     MPI_Group full_group, sub_group;
19     int *included, *ranks;
20     MPI_Comm __attribute__((unused)) comm;
21
22     MPI_Init(NULL, NULL);
23     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
24     MPI_Comm_size(MPI_COMM_WORLD, &size);
25
26     ranks = malloc(size * sizeof(int));
27     included = malloc(size * sizeof(int));
28     MPI_Comm_group(MPI_COMM_WORLD, &full_group);
29
30     for (j = 0; j < LOOPS; j++) {
31         srand(j); /* Deterministic seed */
32
33         count = 0;
34         for (i = 0; i < size; i++) {
35             if (rand() % 2) { /* randomly include a rank */
36                 included[i] = 1;
37                 ranks[count++] = i;
38             }
39             else
40                 included[i] = 0;
41         }
42
43         MPI_Group_incl(full_group, count, ranks, &sub_group);
44
45 #if !defined(USE_STRICT_MPI) && defined(MPICH)
46         if (included[rank]) {
47             MPI_Comm_create_group(MPI_COMM_WORLD, sub_group, 0, &comm);
48             MPI_Barrier(comm);
49             MPI_Comm_free(&comm);
50         }
51 #endif /* USE_STRICT_MPI */
52
53         MPI_Group_free(&sub_group);
54     }
55
56     MPI_Group_free(&full_group);
57
58     if (rank == 0)
59         printf(" No Errors\n");
60
61     MPI_Finalize();
62
63     return 0;
64 }