2004-01-30 00:42:40 +03:00
|
|
|
/*
|
|
|
|
* $HEADERS$
|
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-01-30 00:42:40 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "mpi.h"
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "mpi/c/bindings.h"
|
2004-05-08 03:44:49 +04:00
|
|
|
#include "datatype/datatype.h"
|
|
|
|
#include "errhandler/errhandler.h"
|
|
|
|
#include "communicator/communicator.h"
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "class/ompi_object.h"
|
2004-01-30 00:42:40 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILING_DEFINES
|
2004-01-30 00:42:40 +03:00
|
|
|
#pragma weak MPI_Pack = PMPI_Pack
|
|
|
|
#endif
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_PROFILING_DEFINES
|
2004-04-20 22:50:43 +04:00
|
|
|
#include "mpi/c/profile/defines.h"
|
|
|
|
#endif
|
|
|
|
|
2004-06-24 20:47:00 +04:00
|
|
|
static const char FUNC_NAME[] = "MPI_Pack";
|
2004-05-08 03:44:49 +04:00
|
|
|
|
|
|
|
|
2004-01-30 00:42:40 +03:00
|
|
|
int MPI_Pack(void *inbuf, int incount, MPI_Datatype datatype,
|
2004-05-08 03:44:49 +04:00
|
|
|
void *outbuf, int outsize, int *position, MPI_Comm comm)
|
|
|
|
{
|
|
|
|
int size, rc;
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_convertor_t *local_convertor;
|
2004-05-08 03:44:49 +04:00
|
|
|
struct iovec invec;
|
|
|
|
|
|
|
|
if (MPI_PARAM_CHECK) {
|
2004-07-30 06:58:53 +04:00
|
|
|
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
|
2004-05-08 03:44:49 +04:00
|
|
|
if (MPI_COMM_NULL == comm) {
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM, FUNC_NAME);
|
2004-07-30 06:58:53 +04:00
|
|
|
} else if ((NULL == inbuf) || (NULL == outbuf) || (NULL == position)) {
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
|
2004-07-30 06:58:53 +04:00
|
|
|
} else if (incount < 0) {
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
|
2004-07-30 06:58:53 +04:00
|
|
|
} else if (outsize < 0) {
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
|
2004-07-30 06:58:53 +04:00
|
|
|
} else if (MPI_DATATYPE_NULL == datatype) {
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME);
|
2004-05-08 03:44:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-30 02:45:06 +04:00
|
|
|
local_convertor = OBJ_NEW(ompi_convertor_t);
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_convertor_init_for_send(local_convertor, 0, datatype, incount,
|
2004-08-30 11:52:09 +04:00
|
|
|
inbuf, 0);
|
|
|
|
|
|
|
|
/* Check for truncation */
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_convertor_get_packed_size(local_convertor, &size);
|
2004-08-30 11:52:09 +04:00
|
|
|
if (*position + size >= outsize) {
|
2004-08-30 02:45:06 +04:00
|
|
|
OBJ_RELEASE(local_convertor);
|
2004-08-30 11:52:09 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TRUNCATE, FUNC_NAME);
|
2004-05-08 03:44:49 +04:00
|
|
|
}
|
|
|
|
|
2004-08-30 11:52:09 +04:00
|
|
|
/* Prepare the iovec with all informations */
|
2004-05-08 03:44:49 +04:00
|
|
|
|
2004-08-30 11:52:09 +04:00
|
|
|
invec.iov_base = (char*) outbuf + (*position);
|
2004-05-08 03:44:49 +04:00
|
|
|
invec.iov_len = outsize - (*position);
|
|
|
|
|
|
|
|
/* Do the actual packing */
|
2004-08-30 11:52:09 +04:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
rc = ompi_convertor_pack(local_convertor, &invec, 1);
|
2004-05-08 03:44:49 +04:00
|
|
|
*position += local_convertor->bConverted;
|
2004-08-30 11:52:09 +04:00
|
|
|
OBJ_RELEASE(local_convertor);
|
2004-08-30 02:45:06 +04:00
|
|
|
|
2004-08-30 11:52:09 +04:00
|
|
|
/* All done. Note that the convertor returns 1 upon success, not
|
|
|
|
OMPI_SUCCESS. */
|
2004-05-08 03:44:49 +04:00
|
|
|
|
2004-08-30 11:52:09 +04:00
|
|
|
OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR,
|
|
|
|
comm, MPI_ERR_UNKNOWN, FUNC_NAME);
|
2004-01-30 00:42:40 +03:00
|
|
|
}
|