Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc tests.
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / comm_create_group_idup.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2015 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;
16     MPI_Group world_group;
17     MPI_Comm group_comm, idup_comm;
18     MPI_Request req;
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 even number of processes\n");
26         MPI_Abort(MPI_COMM_WORLD, 1);
27     }
28
29     /* Create some groups */
30     MPI_Comm_group(MPI_COMM_WORLD, &world_group);
31
32     if (rank % 2 == 0) {
33         MPI_Comm_create_group(MPI_COMM_WORLD, world_group, 0, &group_comm);
34         MPI_Comm_idup(MPI_COMM_WORLD, &idup_comm, &req);
35     }
36     else {
37         MPI_Comm_idup(MPI_COMM_WORLD, &idup_comm, &req);
38         MPI_Comm_create_group(MPI_COMM_WORLD, world_group, 0, &group_comm);
39     }
40
41     MPI_Wait(&req, MPI_STATUSES_IGNORE);
42     /*Test new comm with a barrier */
43     MPI_Barrier(idup_comm);
44     MPI_Barrier(group_comm);
45
46     MPI_Group_free(&world_group);
47     MPI_Comm_free(&idup_comm);
48     MPI_Comm_free(&group_comm);
49     if (rank == 0)
50         printf(" No errors\n");
51
52     MPI_Finalize();
53     return 0;
54 }