Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update datatype mpich tests
[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     int source = 0;
31     int dest = size - 1;
32
33     if (rank == 0) {
34         a = 10;
35         b = 20;
36         MPI_Isend(&a, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &requests[0]);
37         MPI_Isend(&b, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &requests[1]);
38         MPI_Cancel(&requests[1]);
39         MPI_Wait(&requests[1], &statuses[1]);
40         MPI_Test_cancelled(&statuses[1], &flag);
41
42         if (!flag) {
43             printf("Failed to cancel send");
44             errs++;
45         }
46         MPI_Barrier(MPI_COMM_WORLD);
47         MPI_Wait(&requests[0], MPI_STATUS_IGNORE);
48     }
49     else if (rank == 1) {
50         MPI_Barrier(MPI_COMM_WORLD);
51         MPI_Recv(&a, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
52         if (a == 20) {
53             printf("Failed! got the data from the wrong send!\n");
54             errs++;
55         }
56     }
57
58     MTest_Finalize(errs);
59     MPI_Finalize();
60     return 0;
61 }