Blame test/mpi/errors/pt2pt/errinstatts.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2003 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
Packit 0848f5
/*
Packit 0848f5
static char MTEST_Descrip[] = "Test err in status return, using truncated \
Packit 0848f5
messages for MPI_Testsome";
Packit 0848f5
*/
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    int errs = 0;
Packit 0848f5
    MPI_Comm comm;
Packit 0848f5
    MPI_Request r[2];
Packit 0848f5
    MPI_Status s[2];
Packit 0848f5
    int indices[2], outcount;
Packit 0848f5
    int errval, errclass;
Packit 0848f5
    int b1[20], b2[20], rank, size, src, dest, i, j;
Packit 0848f5
Packit 0848f5
    MTEST_VG_MEM_INIT(b1, 20 * sizeof(int));
Packit 0848f5
    MTEST_VG_MEM_INIT(b2, 20 * sizeof(int));
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    /* Create some receive requests.  tags 0-9 will succeed, tags 10-19
Packit 0848f5
     * will be used for ERR_TRUNCATE (fewer than 20 messages will be used) */
Packit 0848f5
    comm = MPI_COMM_WORLD;
Packit 0848f5
Packit 0848f5
    MPI_Comm_rank(comm, &rank;;
Packit 0848f5
    MPI_Comm_size(comm, &size);
Packit 0848f5
Packit 0848f5
    src = 1;
Packit 0848f5
    dest = 0;
Packit 0848f5
    if (rank == dest) {
Packit 0848f5
        MPI_Errhandler_set(comm, MPI_ERRORS_RETURN);
Packit 0848f5
        errval = MPI_Irecv(b1, 10, MPI_INT, src, 0, comm, &r[0]);
Packit 0848f5
        if (errval) {
Packit 0848f5
            errs++;
Packit 0848f5
            MTestPrintError(errval);
Packit 0848f5
            printf("Error returned from Irecv\n");
Packit 0848f5
        }
Packit 0848f5
        errval = MPI_Irecv(b2, 10, MPI_INT, src, 10, comm, &r[1]);
Packit 0848f5
        if (errval) {
Packit 0848f5
            errs++;
Packit 0848f5
            MTestPrintError(errval);
Packit 0848f5
            printf("Error returned from Irecv\n");
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
        /* Wait for Irecvs to be posted before the sender calls send.  This
Packit 0848f5
         * prevents the operation from completing and returning an error in the
Packit 0848f5
         * Irecv. */
Packit 0848f5
        errval = MPI_Recv(NULL, 0, MPI_INT, src, 100, comm, MPI_STATUS_IGNORE);
Packit 0848f5
        if (errval) {
Packit 0848f5
            errs++;
Packit 0848f5
            MTestPrintError(errval);
Packit 0848f5
            printf("Error returned from Recv\n");
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
        /* Wait for sends to complete at the sender before proceeding */
Packit 0848f5
        /* WARNING: This does not guarantee that the sends are ready to
Packit 0848f5
         * complete at the receiver. */
Packit 0848f5
        errval = MPI_Recv(NULL, 0, MPI_INT, src, 10, comm, MPI_STATUS_IGNORE);
Packit 0848f5
        if (errval) {
Packit 0848f5
            errs++;
Packit 0848f5
            MTestPrintError(errval);
Packit 0848f5
            printf("Error returned from Recv\n");
Packit 0848f5
        }
Packit 0848f5
        for (i = 0; i < 2; i++) {
Packit 0848f5
            s[i].MPI_ERROR = -1;
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
        /* WARNING: The following assumes that Testsome will complete both
Packit 0848f5
         * send/irecv pairs.  This is *not* guaranteed by the MPI standard. */
Packit 0848f5
        errval = MPI_Testsome(2, r, &outcount, indices, s);
Packit 0848f5
        MPI_Error_class(errval, &errclass);
Packit 0848f5
        if (errclass != MPI_ERR_IN_STATUS) {
Packit 0848f5
            errs++;
Packit 0848f5
            printf
Packit 0848f5
                ("Did not get ERR_IN_STATUS in Testsome (outcount = %d, should equal 2); class returned was %d\n",
Packit 0848f5
                 outcount, errclass);
Packit 0848f5
        }
Packit 0848f5
        else if (outcount != 2) {
Packit 0848f5
            errs++;
Packit 0848f5
            printf("Test returned outcount = %d\n", outcount);
Packit 0848f5
        }
Packit 0848f5
        else {
Packit 0848f5
            /* Check for success */
Packit 0848f5
            for (i = 0; i < outcount; i++) {
Packit 0848f5
                j = i;
Packit 0848f5
                /* Indices is the request index */
Packit 0848f5
                if (s[j].MPI_TAG < 10 && s[j].MPI_ERROR != MPI_SUCCESS) {
Packit 0848f5
                    errs++;
Packit 0848f5
                    printf("correct msg had error class %d\n", s[j].MPI_ERROR);
Packit 0848f5
                }
Packit 0848f5
                else if (s[j].MPI_TAG >= 10 && s[j].MPI_ERROR == MPI_SUCCESS) {
Packit 0848f5
                    errs++;
Packit 0848f5
                    printf("truncated msg had MPI_SUCCESS\n");
Packit 0848f5
                }
Packit 0848f5
            }
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
    }
Packit 0848f5
    else if (rank == src) {
Packit 0848f5
        /* Wait for Irecvs to be posted before the sender calls send */
Packit 0848f5
        MPI_Ssend(NULL, 0, MPI_INT, dest, 100, comm);
Packit 0848f5
Packit 0848f5
        /* Send test messages, then send another message so that the test does
Packit 0848f5
         * not start until we are sure that the sends have begun */
Packit 0848f5
        MPI_Send(b1, 10, MPI_INT, dest, 0, comm);
Packit 0848f5
        MPI_Send(b2, 11, MPI_INT, dest, 10, comm);
Packit 0848f5
Packit 0848f5
        /* Wait for sends to complete before proceeding to the testsome. */
Packit 0848f5
        MPI_Ssend(NULL, 0, MPI_INT, dest, 10, comm);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
Packit 0848f5
}