Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add 2 tests for comm
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / cmfree2.c
1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5
6 #include "mpi.h"
7 #include <stdlib.h>
8 #include "mpitest.h"
9
10 /*
11 static char MTEST_Descrip[] = "Test that communicators have reference count semantics";
12 */
13
14 int main(int argc, char *argv[])
15 {
16     int errs = 0;
17     int rank, size;
18     MPI_Comm comm;
19
20     MTest_Init(&argc, &argv);
21
22     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
23     MPI_Comm_size(MPI_COMM_WORLD, &size);
24     if (size < 2) {
25         fprintf(stderr, "This test requires at least two processes.");
26         MPI_Abort(MPI_COMM_WORLD, 1);
27     }
28
29     MPI_Comm_dup(MPI_COMM_WORLD, &comm);
30
31     if (rank == 0) {
32         MPI_Barrier(MPI_COMM_WORLD);
33         MPI_Ssend(NULL, 0, MPI_INT, 1, 0, comm);
34         MPI_Comm_free(&comm);
35     } else if (rank == 1) {
36         MPI_Request req;
37         /* recv an ssend after the user frees the comm */
38         MPI_Irecv(NULL, 0, MPI_INT, 0, 0, comm, &req);
39         MPI_Comm_free(&comm);
40         MPI_Barrier(MPI_COMM_WORLD);
41         MPI_Wait(&req, MPI_STATUS_IGNORE);
42     } else {
43         MPI_Comm_free(&comm);
44         MPI_Barrier(MPI_COMM_WORLD);
45     }
46
47     MTest_Finalize(errs);
48     return MTestReturnValue(errs);
49 }