scancel_unmatch.c 1.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
 *  (C) 2015 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include "mpitest.h"

/*
static char MTEST_Descrip[] = "Test message reception ordering issues
after cancelling a send";
*/

int main(int argc, char *argv[])
{

    int a, b, flag = 0, errs = 0;
    MPI_Request requests[2];
    MPI_Status statuses[2];

    MPI_Init(&argc, &argv);

    int rank, size;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    int source = 0;
    int dest = size - 1;

    if (rank == 0) {
        a = 10;
        b = 20;
        MPI_Isend(&a, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &requests[0]);
        MPI_Isend(&b, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &requests[1]);
        MPI_Cancel(&requests[1]);
        MPI_Wait(&requests[1], &statuses[1]);
        MPI_Test_cancelled(&statuses[1], &flag);

        if (!flag) {
            printf("Failed to cancel send");
            errs++;
        }
        MPI_Barrier(MPI_COMM_WORLD);
        MPI_Wait(&requests[0], MPI_STATUS_IGNORE);
    }
    else if (rank == 1) {
        MPI_Barrier(MPI_COMM_WORLD);
        MPI_Recv(&a, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
        if (a == 20) {
            printf("Failed! got the data from the wrong send!\n");
            errs++;
        }
    }

    MTest_Finalize(errs);
    MPI_Finalize();
    return 0;
}