Blame test/mpi/pt2pt/scancel_unmatch.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *  (C) 2015 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <stdlib.h>
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
Packit 0848f5
/*
Packit 0848f5
static char MTEST_Descrip[] = "Test message reception ordering issues
Packit 0848f5
after cancelling a send";
Packit 0848f5
*/
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
Packit 0848f5
    int a, b, flag = 0, errs = 0;
Packit 0848f5
    MPI_Request requests[2];
Packit 0848f5
    MPI_Status statuses[2];
Packit 0848f5
Packit 0848f5
    MPI_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    int rank, size;
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit 0848f5
    MPI_Comm_size(MPI_COMM_WORLD, &size);
Packit 0848f5
Packit 0848f5
    int source = 0;
Packit 0848f5
    int dest = size - 1;
Packit 0848f5
Packit 0848f5
    if (rank == 0) {
Packit 0848f5
        a = 10;
Packit 0848f5
        b = 20;
Packit 0848f5
        MPI_Isend(&a, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &requests[0]);
Packit 0848f5
        MPI_Isend(&b, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &requests[1]);
Packit 0848f5
        MPI_Cancel(&requests[1]);
Packit 0848f5
        MPI_Wait(&requests[1], &statuses[1]);
Packit 0848f5
        MPI_Test_cancelled(&statuses[1], &flag;;
Packit 0848f5
Packit 0848f5
        if (!flag) {
Packit 0848f5
            printf("Failed to cancel send");
Packit 0848f5
            errs++;
Packit 0848f5
        }
Packit 0848f5
        MPI_Barrier(MPI_COMM_WORLD);
Packit 0848f5
        MPI_Wait(&requests[0], MPI_STATUS_IGNORE);
Packit 0848f5
    }
Packit 0848f5
    else if (rank == 1) {
Packit 0848f5
        MPI_Barrier(MPI_COMM_WORLD);
Packit 0848f5
        MPI_Recv(&a, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
Packit 0848f5
        if (a == 20) {
Packit 0848f5
            printf("Failed! got the data from the wrong send!\n");
Packit 0848f5
            errs++;
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}