Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into adrien
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / scancel_unmatch.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
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTEST_Descrip[] = "Test message reception ordering issues
14 after cancelling a send";
15 */
16
17 int main(int argc, char *argv[])
18 {
19
20     int a, b, flag = 0, errs = 0;
21     MPI_Request requests[2];
22     MPI_Status statuses[2];
23
24     MPI_Init(&argc, &argv);
25
26     int rank, size;
27     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
28     MPI_Comm_size(MPI_COMM_WORLD, &size);
29
30
31     if (rank == 0) {
32         a = 10;
33         b = 20;
34         MPI_Isend(&a, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &requests[0]);
35         MPI_Isend(&b, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &requests[1]);
36         MPI_Cancel(&requests[1]);
37         MPI_Wait(&requests[1], &statuses[1]);
38         MPI_Test_cancelled(&statuses[1], &flag);
39
40         if (!flag) {
41             printf("Failed to cancel send");
42             errs++;
43         }
44         MPI_Barrier(MPI_COMM_WORLD);
45         MPI_Wait(&requests[0], MPI_STATUS_IGNORE);
46     }
47     else if (rank == 1) {
48         MPI_Barrier(MPI_COMM_WORLD);
49         MPI_Recv(&a, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
50         if (a == 20) {
51             printf("Failed! got the data from the wrong send!\n");
52             errs++;
53         }
54     }
55
56     MTest_Finalize(errs);
57     MPI_Finalize();
58     return 0;
59 }