Blame test/mpi/rma/putpscw1.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[] = "Put with Post/Start/Complete/Wait";
Packit 0848f5
*/
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
    MPI_Group wingroup, neighbors;
Packit 0848f5
    MTestDatatype sendtype, recvtype;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    /* The following illustrates the use of the routines to
Packit 0848f5
     * run through a selection of communicators and datatypes.
Packit 0848f5
     * Use subsets of these for tests that do not involve combinations
Packit 0848f5
     * of communicators, datatypes, and counts of datatypes */
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
                /* 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
                               (int) extent, MPI_INFO_NULL, comm, &win);
Packit 0848f5
                MPI_Win_get_group(win, &wingroup);
Packit 0848f5
                if (rank == source) {
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
                    sendtype.InitBuf(&sendtype);
Packit 0848f5
Packit 0848f5
                    /* Neighbor is dest only */
Packit 0848f5
                    MPI_Group_incl(wingroup, 1, &dest, &neighbors);
Packit 0848f5
                    err = MPI_Win_start(neighbors, 0, win);
Packit 0848f5
                    if (err) {
Packit 0848f5
                        errs++;
Packit 0848f5
                        if (errs < 10) {
Packit 0848f5
                            MTestPrintError(err);
Packit 0848f5
                        }
Packit 0848f5
                    }
Packit 0848f5
                    MPI_Group_free(&neighbors);
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
                        errs++;
Packit 0848f5
                        MTestPrintError(err);
Packit 0848f5
                    }
Packit 0848f5
                    err = MPI_Win_complete(win);
Packit 0848f5
                    if (err) {
Packit 0848f5
                        errs++;
Packit 0848f5
                        if (errs < 10) {
Packit 0848f5
                            MTestPrintError(err);
Packit 0848f5
                        }
Packit 0848f5
                    }
Packit 0848f5
                }
Packit 0848f5
                else if (rank == dest) {
Packit 0848f5
                    MPI_Group_incl(wingroup, 1, &source, &neighbors);
Packit 0848f5
                    MPI_Win_post(neighbors, 0, win);
Packit 0848f5
                    MPI_Group_free(&neighbors);
Packit 0848f5
                    MPI_Win_wait(win);
Packit 0848f5
                    /* This should have the same effect, in terms of
Packit 0848f5
                     * transfering data, as a send/recv pair */
Packit 0848f5
                    err = MTestCheckRecv(0, &recvtype);
Packit 0848f5
                    if (err) {
Packit 0848f5
                        errs += errs;
Packit 0848f5
                    }
Packit 0848f5
                }
Packit 0848f5
                else {
Packit 0848f5
                    /* Nothing; the other processes need not call any
Packit 0848f5
                     * MPI routines */
Packit 0848f5
                    ;
Packit 0848f5
                }
Packit 0848f5
                MPI_Win_free(&win);
Packit 0848f5
                MTestFreeDatatype(&sendtype);
Packit 0848f5
                MTestFreeDatatype(&recvtype);
Packit 0848f5
                MPI_Group_free(&wingroup);
Packit 0848f5
            }
Packit 0848f5
        }
Packit 0848f5
        MTestFreeComm(&comm);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}