Blame test/mpi/rma/epochtest.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2009 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
/*
Packit 0848f5
 * This test looks at the behavior of MPI_Win_fence and epochs.  Each
Packit 0848f5
 * MPI_Win_fence may both begin and end both the exposure and access epochs.
Packit 0848f5
 * Thus, it is not necessary to use MPI_Win_fence in pairs.
Packit 0848f5
 *
Packit 0848f5
 * The tests have this form:
Packit 0848f5
 *    Process A             Process B
Packit 0848f5
 *     fence                 fence
Packit 0848f5
 *      put,put
Packit 0848f5
 *     fence                 fence
Packit 0848f5
 *                            put,put
Packit 0848f5
 *     fence                 fence
Packit 0848f5
 *      put,put               put,put
Packit 0848f5
 *     fence                 fence
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[] = "Put with Fences used to separate epochs";
Packit 0848f5
*/
Packit 0848f5
Packit 0848f5
#define MAX_PERR 10
Packit 0848f5
Packit 0848f5
int PrintRecvedError(const char *, MTestDatatype *, MTestDatatype *);
Packit 0848f5
Packit 0848f5
int main(int argc, char **argv)
Packit 0848f5
{
Packit 0848f5
    int errs = 0, err;
Packit 0848f5
    int rank, size, source, dest;
Packit 0848f5
    int minsize = 2, count;
Packit 0848f5
    MPI_Comm comm;
Packit 0848f5
    MPI_Win win;
Packit 0848f5
    MPI_Aint extent,lb;
Packit 0848f5
    MTestDatatype sendtype, recvtype;
Packit 0848f5
    int onlyInt = 0;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
    /* Check for a simple choice of communicator and datatypes */
Packit 0848f5
    if (getenv("MTEST_SIMPLE"))
Packit 0848f5
        onlyInt = 1;
Packit 0848f5
Packit 0848f5
    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
Packit 0848f5
        if (comm == MPI_COMM_NULL)
Packit 0848f5
            continue;
Packit 0848f5
        /* Determine the sender and receiver */
Packit 0848f5
        MPI_Comm_rank(comm, &rank;;
Packit 0848f5
        MPI_Comm_size(comm, &size);
Packit 0848f5
        source = 0;
Packit 0848f5
        dest = size - 1;
Packit 0848f5
Packit 0848f5
        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
Packit 0848f5
            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
Packit 0848f5
Packit 0848f5
                MTestPrintfMsg(1,
Packit 0848f5
                               "Putting count = %d of sendtype %s receive type %s\n",
Packit 0848f5
                               count, MTestGetDatatypeName(&sendtype),
Packit 0848f5
                               MTestGetDatatypeName(&recvtype));
Packit 0848f5
Packit 0848f5
                /* Make sure that everyone has a recv buffer */
Packit 0848f5
                recvtype.InitBuf(&recvtype);
Packit 0848f5
Packit 0848f5
                MPI_Type_extent(recvtype.datatype, &extent);
Packit 0848f5
                MPI_Type_lb(recvtype.datatype, &lb);
Packit 0848f5
                MPI_Win_create(recvtype.buf, recvtype.count * extent + lb,
Packit 0848f5
                               extent, MPI_INFO_NULL, comm, &win);
Packit 0848f5
                /* To improve reporting of problems about operations, we
Packit 0848f5
                 * change the error handler to errors return */
Packit 0848f5
                MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
Packit 0848f5
Packit 0848f5
                /* At this point, we have all of the elements that we
Packit 0848f5
                 * need to begin the multiple fence and put tests */
Packit 0848f5
                /* Fence 1 */
Packit 0848f5
                err = MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
Packit 0848f5
                if (err) {
Packit 0848f5
                    if (errs++ < MAX_PERR)
Packit 0848f5
                        MTestPrintError(err);
Packit 0848f5
                }
Packit 0848f5
                /* Source puts */
Packit 0848f5
                if (rank == source) {
Packit 0848f5
                    sendtype.InitBuf(&sendtype);
Packit 0848f5
Packit 0848f5
                    err = MPI_Put(sendtype.buf, sendtype.count,
Packit 0848f5
                                  sendtype.datatype, dest, 0,
Packit 0848f5
                                  recvtype.count, recvtype.datatype, win);
Packit 0848f5
                    if (err) {
Packit 0848f5
                        if (errs++ < MAX_PERR)
Packit 0848f5
                            MTestPrintError(err);
Packit 0848f5
                    }
Packit 0848f5
                }
Packit 0848f5
Packit 0848f5
                /* Fence 2 */
Packit 0848f5
                err = MPI_Win_fence(0, win);
Packit 0848f5
                if (err) {
Packit 0848f5
                    if (errs++ < MAX_PERR)
Packit 0848f5
                        MTestPrintError(err);
Packit 0848f5
                }
Packit 0848f5
                /* dest checks data, then Dest puts */
Packit 0848f5
                if (rank == dest) {
Packit 0848f5
                    err = MTestCheckRecv(0, &recvtype);
Packit 0848f5
                    if (err) {
Packit 0848f5
                        if (errs++ < MAX_PERR) {
Packit 0848f5
                            PrintRecvedError("fence 2", &sendtype, &recvtype);
Packit 0848f5
                        }
Packit 0848f5
                    }
Packit 0848f5
                    sendtype.InitBuf(&sendtype);
Packit 0848f5
Packit 0848f5
                    err = MPI_Put(sendtype.buf, sendtype.count,
Packit 0848f5
                                  sendtype.datatype, source, 0,
Packit 0848f5
                                  recvtype.count, recvtype.datatype, win);
Packit 0848f5
                    if (err) {
Packit 0848f5
                        if (errs++ < MAX_PERR)
Packit 0848f5
                            MTestPrintError(err);
Packit 0848f5
                    }
Packit 0848f5
                }
Packit 0848f5
Packit 0848f5
                /* Fence 3 */
Packit 0848f5
                err = MPI_Win_fence(0, win);
Packit 0848f5
                if (err) {
Packit 0848f5
                    if (errs++ < MAX_PERR)
Packit 0848f5
                        MTestPrintError(err);
Packit 0848f5
                }
Packit 0848f5
                /* src checks data, then Src and dest puts */
Packit 0848f5
                if (rank == source) {
Packit 0848f5
                    err = MTestCheckRecv(0, &recvtype);
Packit 0848f5
                    if (err) {
Packit 0848f5
                        if (errs++ < MAX_PERR) {
Packit 0848f5
                            PrintRecvedError("fence 3", &sendtype, &recvtype);
Packit 0848f5
                        }
Packit 0848f5
                    }
Packit 0848f5
                    sendtype.InitBuf(&sendtype);
Packit 0848f5
Packit 0848f5
                    err = MPI_Put(sendtype.buf, sendtype.count,
Packit 0848f5
                                  sendtype.datatype, dest, 0,
Packit 0848f5
                                  recvtype.count, recvtype.datatype, win);
Packit 0848f5
                    if (err) {
Packit 0848f5
                        if (errs++ < MAX_PERR)
Packit 0848f5
                            MTestPrintError(err);
Packit 0848f5
                    }
Packit 0848f5
                }
Packit 0848f5
                if (rank == dest) {
Packit 0848f5
                    sendtype.InitBuf(&sendtype);
Packit 0848f5
Packit 0848f5
                    err = MPI_Put(sendtype.buf, sendtype.count,
Packit 0848f5
                                  sendtype.datatype, source, 0,
Packit 0848f5
                                  recvtype.count, recvtype.datatype, win);
Packit 0848f5
                    if (err) {
Packit 0848f5
                        if (errs++ < MAX_PERR)
Packit 0848f5
                            MTestPrintError(err);
Packit 0848f5
                    }
Packit 0848f5
                }
Packit 0848f5
Packit 0848f5
                /* Fence 4 */
Packit 0848f5
                err = MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
Packit 0848f5
                if (err) {
Packit 0848f5
                    if (errs++ < MAX_PERR)
Packit 0848f5
                        MTestPrintError(err);
Packit 0848f5
                }
Packit 0848f5
                /* src and dest checks data */
Packit 0848f5
                if (rank == source) {
Packit 0848f5
                    err = MTestCheckRecv(0, &recvtype);
Packit 0848f5
                    if (err) {
Packit 0848f5
                        if (errs++ < MAX_PERR) {
Packit 0848f5
                            PrintRecvedError("src fence4", &sendtype, &recvtype);
Packit 0848f5
                        }
Packit 0848f5
                    }
Packit 0848f5
                }
Packit 0848f5
                if (rank == dest) {
Packit 0848f5
                    err = MTestCheckRecv(0, &recvtype);
Packit 0848f5
                    if (err) {
Packit 0848f5
                        if (errs++ < MAX_PERR) {
Packit 0848f5
                            PrintRecvedError("dest fence4", &sendtype, &recvtype);
Packit 0848f5
                        }
Packit 0848f5
                    }
Packit 0848f5
                }
Packit 0848f5
Packit 0848f5
                MPI_Win_free(&win);
Packit 0848f5
                MTestFreeDatatype(&sendtype);
Packit 0848f5
                MTestFreeDatatype(&recvtype);
Packit 0848f5
Packit 0848f5
                /* Only do one datatype in the simple case */
Packit 0848f5
                if (onlyInt)
Packit 0848f5
                    break;
Packit 0848f5
            }
Packit 0848f5
            /* Only do one count in the simple case */
Packit 0848f5
            if (onlyInt)
Packit 0848f5
                break;
Packit 0848f5
        }
Packit 0848f5
        MTestFreeComm(&comm);
Packit 0848f5
        /* Only do one communicator in the simple case */
Packit 0848f5
        if (onlyInt)
Packit 0848f5
            break;
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
Packit 0848f5
Packit 0848f5
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
Packit 0848f5
int PrintRecvedError(const char *msg, MTestDatatype * sendtypePtr, MTestDatatype * recvtypePtr)
Packit 0848f5
{
Packit 0848f5
    printf
Packit 0848f5
        ("At step %s, Data in target buffer did not match for destination datatype %s (put with source datatype %s)\n",
Packit 0848f5
         msg, MTestGetDatatypeName(recvtypePtr), MTestGetDatatypeName(sendtypePtr));
Packit 0848f5
    /* Redo the test, with the errors printed */
Packit 0848f5
    recvtypePtr->printErrors = 1;
Packit 0848f5
    (void) MTestCheckRecv(0, recvtypePtr);
Packit 0848f5
    return 0;
Packit 0848f5
}