From eb5e5191fa6bed4e2046455ffec796c6c83e760d Mon Sep 17 00:00:00 2001 From: George Bosilca Date: Sun, 19 Sep 2004 07:05:58 +0000 Subject: [PATCH] Adapt to the new datatype engine and correct some minor bugs. This commit was SVN r2753. --- src/mpi/c/pack.c | 84 ++++++++++++++++++++++-------------------- src/mpi/c/pack_size.c | 4 +- src/mpi/c/unpack.c | 85 ++++++++++++++++++++++--------------------- 3 files changed, 91 insertions(+), 82 deletions(-) diff --git a/src/mpi/c/pack.c b/src/mpi/c/pack.c index dcfd8161cb..8218f99de4 100644 --- a/src/mpi/c/pack.c +++ b/src/mpi/c/pack.c @@ -1,3 +1,5 @@ +/* -*- Mode: C; c-basic-offset:4 ; -*- */ + /* * $HEADERS$ */ @@ -25,51 +27,55 @@ static const char FUNC_NAME[] = "MPI_Pack"; int MPI_Pack(void *inbuf, int incount, MPI_Datatype datatype, void *outbuf, int outsize, int *position, MPI_Comm comm) { - int size, rc; - ompi_convertor_t *local_convertor; - struct iovec invec; + int size, rc, freeAfter; + ompi_convertor_t *local_convertor; + struct iovec invec; + unsigned int max_data, iov_count; - if (MPI_PARAM_CHECK) { - OMPI_ERR_INIT_FINALIZE(FUNC_NAME); - if (MPI_COMM_NULL == comm) { - return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM, FUNC_NAME); - } else if ((NULL == inbuf) || (NULL == outbuf) || (NULL == position)) { - return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME); - } else if (incount < 0) { - return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME); - } else if (outsize < 0) { - return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME); - } else if (MPI_DATATYPE_NULL == datatype) { - return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME); - } + if (MPI_PARAM_CHECK) { + OMPI_ERR_INIT_FINALIZE(FUNC_NAME); + if (MPI_COMM_NULL == comm) { + return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM, FUNC_NAME); + } else if ((NULL == inbuf) || (NULL == outbuf) || (NULL == position)) { + return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME); + } else if (incount < 0) { + return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME); + } else if (outsize < 0) { + return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME); + } else if (MPI_DATATYPE_NULL == datatype) { + return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME); } + } - local_convertor = OBJ_NEW(ompi_convertor_t); - ompi_convertor_init_for_send(local_convertor, 0, datatype, incount, - inbuf, *position); + local_convertor = OBJ_NEW(ompi_convertor_t); + ompi_convertor_init_for_send(local_convertor, 0, datatype, incount, + inbuf, 0, NULL /*never allocate memory*/); - /* Check for truncation */ + /* Check for truncation */ - ompi_convertor_get_packed_size(local_convertor, &size); - if (*position + size > outsize) { - OBJ_RELEASE(local_convertor); - return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TRUNCATE, FUNC_NAME); - } - - /* Prepare the iovec with all informations */ - - invec.iov_base = (char*) outbuf + (*position); - invec.iov_len = outsize - (*position); - - /* Do the actual packing */ - - rc = ompi_convertor_pack(local_convertor, &invec, 1); - *position += local_convertor->bConverted; + ompi_convertor_get_packed_size(local_convertor, &size); + if (*position + size > outsize) { OBJ_RELEASE(local_convertor); + return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TRUNCATE, FUNC_NAME); + } - /* All done. Note that the convertor returns 1 upon success, not - OMPI_SUCCESS. */ + /* Prepare the iovec with all informations */ + + invec.iov_base = (char*) outbuf + (*position); + invec.iov_len = outsize - (*position); + + /* Do the actual packing */ + + iov_count = 1; + max_data = invec.iov_len; + rc = ompi_convertor_pack( local_convertor, &invec, &iov_count, + &max_data, &freeAfter ); + *position += local_convertor->bConverted; + OBJ_RELEASE(local_convertor); + + /* All done. Note that the convertor returns 1 upon success, not + OMPI_SUCCESS. */ - OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR, - comm, MPI_ERR_UNKNOWN, FUNC_NAME); + OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR, + comm, MPI_ERR_UNKNOWN, FUNC_NAME); } diff --git a/src/mpi/c/pack_size.c b/src/mpi/c/pack_size.c index 0f2f0daecf..98253cab9b 100644 --- a/src/mpi/c/pack_size.c +++ b/src/mpi/c/pack_size.c @@ -40,8 +40,8 @@ int MPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, } local_convertor = OBJ_NEW(ompi_convertor_t); - ompi_convertor_init_for_send(local_convertor, 0, datatype, - incount, NULL, 0); + ompi_convertor_init_for_send(local_convertor, 0, datatype, incount, + NULL, 0, NULL /* never allocate memory */); ret = ompi_convertor_get_packed_size(local_convertor, size); OBJ_RELEASE(local_convertor); diff --git a/src/mpi/c/unpack.c b/src/mpi/c/unpack.c index e0ff264f6a..e7df9abd62 100644 --- a/src/mpi/c/unpack.c +++ b/src/mpi/c/unpack.c @@ -26,56 +26,59 @@ int MPI_Unpack(void *inbuf, int insize, int *position, void *outbuf, int outcount, MPI_Datatype datatype, MPI_Comm comm) { - int size, rc; - ompi_convertor_t *local_convertor; - struct iovec outvec; + int size, rc, freeAfter; + ompi_convertor_t *local_convertor; + struct iovec outvec; + unsigned int max_data, iov_count; - if (MPI_PARAM_CHECK) { - OMPI_ERR_INIT_FINALIZE(FUNC_NAME); - if (ompi_comm_invalid(comm)) { - return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM, - FUNC_NAME); - } + if (MPI_PARAM_CHECK) { + OMPI_ERR_INIT_FINALIZE(FUNC_NAME); + if (ompi_comm_invalid(comm)) { + return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM, + FUNC_NAME); + } - if ((NULL == inbuf) || (NULL == outbuf) || (NULL == position)) { - return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME); - } + if ((NULL == inbuf) || (NULL == outbuf) || (NULL == position)) { + return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME); + } - if (outcount < 0) { - return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME); - } - - if (MPI_DATATYPE_NULL == datatype) { - return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME); - } + if (outcount < 0) { + return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME); } - local_convertor = OBJ_NEW(ompi_convertor_t); - ompi_convertor_init_for_recv(local_convertor, 0, datatype, outcount, - outbuf, 0); - - /* Check for truncation */ - - ompi_convertor_get_packed_size(local_convertor, &size); - if (*position + size > insize) { - OBJ_RELEASE(local_convertor); - return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TRUNCATE, FUNC_NAME); + if (MPI_DATATYPE_NULL == datatype) { + return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME); } + } - /* Prepare the iovec with all informations */ + local_convertor = OBJ_NEW(ompi_convertor_t); + ompi_convertor_init_for_recv(local_convertor, 0, datatype, outcount, + outbuf, 0, NULL /* never allocate memory */); + + /* Check for truncation */ - outvec.iov_base = (char*) inbuf + (*position); - outvec.iov_len = insize - (*position); - - /* Do the actual unpacking */ - - rc = ompi_convertor_unpack(local_convertor, &outvec, 1); - *position += local_convertor->bConverted; + ompi_convertor_get_packed_size(local_convertor, &size); + if (*position + size > insize) { OBJ_RELEASE(local_convertor); + return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TRUNCATE, FUNC_NAME); + } - /* All done. Note that the convertor returns 1 upon success, not - OMPI_SUCCESS. */ + /* Prepare the iovec with all informations */ - OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR, - comm, MPI_ERR_UNKNOWN, FUNC_NAME); + outvec.iov_base = (char*) inbuf + (*position); + outvec.iov_len = insize - (*position); + + /* Do the actual unpacking */ + iov_count = 1; + max_data = outvec.iov_len; + rc = ompi_convertor_unpack( local_convertor, &outvec, &iov_count, + &max_data, &freeAfter ); + *position += local_convertor->bConverted; + OBJ_RELEASE(local_convertor); + + /* All done. Note that the convertor returns 1 upon success, not + OMPI_SUCCESS. */ + + OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR, + comm, MPI_ERR_UNKNOWN, FUNC_NAME); }