From c01a17dad928aa82622d2348b861662064e00236 Mon Sep 17 00:00:00 2001 From: Tim Woodall Date: Tue, 26 Oct 2004 14:55:23 +0000 Subject: [PATCH] - fixed arg list in sendrecv - added brain dead sendrecv_replace implementation This commit was SVN r3339. --- src/mpi/c/sendrecv.c | 4 +- src/mpi/c/sendrecv_replace.c | 96 ++++++++++++++++++++++++++++++++++-- 2 files changed, 93 insertions(+), 7 deletions(-) diff --git a/src/mpi/c/sendrecv.c b/src/mpi/c/sendrecv.c index 9e3c190628..8f7577e735 100644 --- a/src/mpi/c/sendrecv.c +++ b/src/mpi/c/sendrecv.c @@ -20,9 +20,9 @@ static const char FUNC_NAME[] = "MPI_Sendrecv"; -int MPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype recvtype, +int MPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag, void *recvbuf, int recvcount, - MPI_Datatype sendtype, int source, int recvtag, + MPI_Datatype recvtype, int source, int recvtag, MPI_Comm comm, MPI_Status *status) { ompi_request_t* req; diff --git a/src/mpi/c/sendrecv_replace.c b/src/mpi/c/sendrecv_replace.c index 7960f7280d..b28a321cc7 100644 --- a/src/mpi/c/sendrecv_replace.c +++ b/src/mpi/c/sendrecv_replace.c @@ -7,6 +7,7 @@ #include "mpi.h" #include "mpi/c/bindings.h" #include "communicator/communicator.h" +#include "datatype/datatype.h" #include "errhandler/errhandler.h" #if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILING_DEFINES @@ -25,11 +26,96 @@ int MPI_Sendrecv_replace(void * buf, int count, MPI_Datatype datatype, MPI_Comm comm, MPI_Status *status) { - if (MPI_PARAM_CHECK) { - OMPI_ERR_INIT_FINALIZE(FUNC_NAME); - } + int rc; + if ( MPI_PARAM_CHECK ) { + rc = MPI_SUCCESS; + OMPI_ERR_INIT_FINALIZE(FUNC_NAME); + if (ompi_comm_invalid(comm)) { + return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM, FUNC_NAME); + } else if (count < 0) { + rc = MPI_ERR_COUNT; + } else if (datatype == MPI_DATATYPE_NULL) { + rc = MPI_ERR_TYPE; + } else if (dest != MPI_PROC_NULL && ompi_comm_peer_invalid(comm, dest)) { + rc = MPI_ERR_RANK; + } else if (sendtag < 0 || sendtag > MPI_TAG_UB_VALUE) { + rc = MPI_ERR_TAG; + } else if (source != MPI_PROC_NULL && source != MPI_ANY_SOURCE && ompi_comm_peer_invalid(comm, source)) { + rc = MPI_ERR_RANK; + } else if (((recvtag < 0) && (recvtag != MPI_ANY_TAG)) || (recvtag > MPI_TAG_UB_VALUE)) { + rc = MPI_ERR_TAG; + } + OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME); + } + + /* simple case */ + if ( source == MPI_PROC_NULL || dest == MPI_PROC_NULL || count == 0 ) { + return MPI_Sendrecv(buf,count,datatype,dest,sendtag,buf,count,datatype,source,recvtag,comm,status); + } else { - /* This function is not yet implemented */ + ompi_convertor_t convertor; + struct iovec iov; + unsigned char recv_data[2048]; + size_t packed_size; + size_t iov_count, max_data; + int free_after; + ompi_status_public_t recv_status; + ompi_proc_t* proc = ompi_comm_peer_lookup(comm,dest); + if(proc == NULL) { + rc = MPI_ERR_RANK; + OMPI_ERRHANDLER_RETURN(rc, comm, rc, FUNC_NAME); + } - return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_OTHER, FUNC_NAME); + /* initialize convertor to unpack recv buffer */ + OBJ_CONSTRUCT(&convertor, ompi_convertor_t); + ompi_convertor_copy(proc->proc_convertor, &convertor); + ompi_convertor_init_for_recv( + &convertor, + 0, + datatype, + count, + buf, + 0, + NULL); + + /* setup a buffer for recv */ + ompi_convertor_get_packed_size(&convertor, &packed_size); + if(packed_size > sizeof(recv_data)) { + iov.iov_base = malloc(packed_size); + if(iov.iov_base == NULL) { + OMPI_ERRHANDLER_RETURN(OMPI_ERR_OUT_OF_RESOURCE, comm, MPI_ERR_BUFFER, FUNC_NAME); + } + } else { + iov.iov_base = recv_data; + } + + /* recv into temporary buffer */ + rc = MPI_Sendrecv(buf, count, datatype, dest, sendtag, iov.iov_base, packed_size, + MPI_BYTE, source, recvtag, comm, &recv_status); + if (rc != MPI_SUCCESS) { + if(packed_size > sizeof(recv_data)) + free(iov.iov_base); + OBJ_DESTRUCT(&convertor); + OMPI_ERRHANDLER_RETURN(rc, comm, rc, FUNC_NAME); + } + + /* unpack into users buffer */ + iov.iov_len = recv_status._count; + iov_count = 1; + max_data = recv_status._count; + ompi_convertor_unpack(&convertor, &iov, &iov_count, &max_data, &free_after); + + /* return status to user */ + if(status != MPI_STATUS_IGNORE) { + *status = recv_status; + } + + /* release resources */ + if(packed_size > sizeof(recv_data)) { + free(iov.iov_base); + } + OBJ_DESTRUCT(&convertor); + return MPI_SUCCESS; + } } +