Skip to content
Merged
3 changes: 3 additions & 0 deletions ompi/datatype/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# Copyright (c) 2007-2013 Los Alamos National Security, LLC. All rights
# reserved.
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2016 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
Expand All @@ -37,6 +39,7 @@ libdatatype_la_SOURCES = \
ompi_datatype_create_vector.c \
ompi_datatype_create_darray.c \
ompi_datatype_create_subarray.c \
ompi_datatype_external.c \
ompi_datatype_external32.c \
ompi_datatype_match_size.c \
ompi_datatype_module.c \
Expand Down
13 changes: 12 additions & 1 deletion ompi/datatype/ompi_datatype.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015 Research Organization for Information Science
* Copyright (c) 2015-2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
Expand Down Expand Up @@ -363,5 +363,16 @@ OMPI_DECLSPEC int ompi_datatype_safeguard_pointer_debug_breakpoint( const void*
int count );
#endif /* OPAL_ENABLE_DEBUG */

OMPI_DECLSPEC int ompi_datatype_pack_external( const char datarep[], const void *inbuf, int incount,
ompi_datatype_t *datatype, void *outbuf,
MPI_Aint outsize, MPI_Aint *position);

OMPI_DECLSPEC int ompi_datatype_unpack_external( const char datarep[], const void *inbuf, MPI_Aint insize,
MPI_Aint *position, void *outbuf, int outcount,
ompi_datatype_t *datatype);

OMPI_DECLSPEC int ompi_datatype_pack_external_size( const char datarep[], int incount,
ompi_datatype_t *datatype, MPI_Aint *size);

END_C_DECLS
#endif /* OMPI_DATATYPE_H_HAS_BEEN_INCLUDED */
135 changes: 135 additions & 0 deletions ompi/datatype/ompi_datatype_external.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2016 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015-2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/

#include "ompi_config.h"
#include <stdio.h>

#include "ompi/runtime/params.h"
#include "ompi/communicator/communicator.h"
#include "ompi/datatype/ompi_datatype.h"
#include "opal/datatype/opal_convertor.h"

int ompi_datatype_pack_external(const char datarep[], const void *inbuf, int incount,
ompi_datatype_t *datatype, void *outbuf,
MPI_Aint outsize, MPI_Aint *position)
{
int rc = MPI_SUCCESS;
opal_convertor_t local_convertor;
struct iovec invec;
unsigned int iov_count;
size_t size;

OBJ_CONSTRUCT(&local_convertor, opal_convertor_t);

/* The resulting convertor will be set to the position zero. We have to use
* CONVERTOR_SEND_CONVERSION in order to force the convertor to do anything
* more than just packing the data.
*/
opal_convertor_copy_and_prepare_for_send( ompi_mpi_external32_convertor,
&(datatype->super), incount, (void *) inbuf,
CONVERTOR_SEND_CONVERSION,
&local_convertor );

/* Check for truncation */
opal_convertor_get_packed_size( &local_convertor, &size );
if( (*position + size) > (size_t)outsize ) { /* we can cast as we already checked for < 0 */
OBJ_DESTRUCT( &local_convertor );
return MPI_ERR_TRUNCATE;
}

/* Prepare the iovec with all informations */
invec.iov_base = (char*) outbuf + (*position);
invec.iov_len = size;

/* Do the actual packing */
iov_count = 1;
rc = opal_convertor_pack( &local_convertor, &invec, &iov_count, &size );
*position += size;
OBJ_DESTRUCT( &local_convertor );

/* All done. Note that the convertor returns 1 upon success, not
OMPI_SUCCESS. */
return (rc == 1) ? OMPI_SUCCESS : MPI_ERR_UNKNOWN;
}

int ompi_datatype_unpack_external (const char datarep[], const void *inbuf, MPI_Aint insize,
MPI_Aint *position, void *outbuf, int outcount,
ompi_datatype_t *datatype)
{
int rc = MPI_SUCCESS;
opal_convertor_t local_convertor;
struct iovec outvec;
unsigned int iov_count;
size_t size;

OBJ_CONSTRUCT(&local_convertor, opal_convertor_t);

/* the resulting convertor will be set to the position ZERO */
opal_convertor_copy_and_prepare_for_recv( ompi_mpi_external32_convertor,
&(datatype->super), outcount, outbuf,
0,
&local_convertor );

/* Check for truncation */
opal_convertor_get_packed_size( &local_convertor, &size );
if( (*position + size) > (unsigned int)insize ) {
OBJ_DESTRUCT( &local_convertor );
return MPI_ERR_TRUNCATE;
}

/* Prepare the iovec with all informations */
outvec.iov_base = (char*) inbuf + (*position);
outvec.iov_len = size;

/* Do the actual unpacking */
iov_count = 1;
rc = opal_convertor_unpack( &local_convertor, &outvec, &iov_count, &size );
*position += size;
OBJ_DESTRUCT( &local_convertor );

/* All done. Note that the convertor returns 1 upon success, not
OMPI_SUCCESS. */
return (rc == 1) ? OMPI_SUCCESS : MPI_ERR_UNKNOWN;
}

int ompi_datatype_pack_external_size(const char datarep[], int incount,
ompi_datatype_t *datatype, MPI_Aint *size)
{
opal_convertor_t local_convertor;
size_t length;

OBJ_CONSTRUCT(&local_convertor, opal_convertor_t);

/* the resulting convertor will be set to the position ZERO */
opal_convertor_copy_and_prepare_for_recv( ompi_mpi_external32_convertor,
&(datatype->super), incount, NULL,
CONVERTOR_SEND_CONVERSION,
&local_convertor );

opal_convertor_get_unpacked_size( &local_convertor, &length );
*size = (MPI_Aint)length;
OBJ_DESTRUCT( &local_convertor );

return OMPI_SUCCESS;
}
10 changes: 6 additions & 4 deletions ompi/mpi/c/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* Copyright (c) 2004-2016 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
Expand Down Expand Up @@ -45,7 +45,7 @@ static const char FUNC_NAME[] = "MPI_Pack";
int MPI_Pack(const void *inbuf, int incount, MPI_Datatype datatype,
void *outbuf, int outsize, int *position, MPI_Comm comm)
{
int rc;
int rc = MPI_SUCCESS;
opal_convertor_t local_convertor;
struct iovec invec;
unsigned int iov_count;
Expand All @@ -67,9 +67,11 @@ int MPI_Pack(const void *inbuf, int incount, MPI_Datatype datatype,
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 || NULL == datatype) {
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME);
}
OMPI_CHECK_DATATYPE_FOR_SEND(rc, datatype, incount);
OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
OMPI_CHECK_USER_BUFFER(rc, inbuf, datatype, incount);
OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
}

OPAL_CR_ENTER_LIBRARY();
Expand Down
51 changes: 11 additions & 40 deletions ompi/mpi/c/pack_external.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* Copyright (c) 2004-2016 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
Expand Down Expand Up @@ -46,11 +46,7 @@ int MPI_Pack_external(const char datarep[], const void *inbuf, int incount,
MPI_Datatype datatype, void *outbuf,
MPI_Aint outsize, MPI_Aint *position)
{
int rc;
opal_convertor_t local_convertor;
struct iovec invec;
unsigned int iov_count;
size_t size;
int rc = MPI_SUCCESS;

MEMCHECKER(
memchecker_datatype(datatype);
Expand All @@ -65,46 +61,21 @@ int MPI_Pack_external(const char datarep[], const void *inbuf, int incount,
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COUNT, FUNC_NAME);
} else if (outsize < 0) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, FUNC_NAME);
} else if (MPI_DATATYPE_NULL == datatype || NULL == datatype) {
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_TYPE, FUNC_NAME);
}
OMPI_CHECK_DATATYPE_FOR_SEND(rc, datatype, incount);
OMPI_ERRHANDLER_CHECK(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
OMPI_CHECK_USER_BUFFER(rc, inbuf, datatype, incount);
OMPI_ERRHANDLER_CHECK(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
}

OPAL_CR_ENTER_LIBRARY();

OBJ_CONSTRUCT(&local_convertor, opal_convertor_t);

/* The resulting convertor will be set to the position zero. We have to use
* CONVERTOR_SEND_CONVERSION in order to force the convertor to do anything
* more than just packing the data.
*/
opal_convertor_copy_and_prepare_for_send( ompi_mpi_external32_convertor,
&(datatype->super), incount, (void *) inbuf,
CONVERTOR_SEND_CONVERSION,
&local_convertor );

/* Check for truncation */
opal_convertor_get_packed_size( &local_convertor, &size );
if( (*position + size) > (size_t)outsize ) { /* we can cast as we already checked for < 0 */
OBJ_DESTRUCT( &local_convertor );
OPAL_CR_EXIT_LIBRARY();
return OMPI_ERRHANDLER_INVOKE( MPI_COMM_WORLD, MPI_ERR_TRUNCATE, FUNC_NAME );
}

/* Prepare the iovec with all informations */
invec.iov_base = (char*) outbuf + (*position);
invec.iov_len = size;

/* Do the actual packing */
iov_count = 1;
rc = opal_convertor_pack( &local_convertor, &invec, &iov_count, &size );
*position += size;
OBJ_DESTRUCT( &local_convertor );
rc = ompi_datatype_pack_external(datarep, inbuf, incount,
datatype, outbuf,
outsize, position);

OPAL_CR_EXIT_LIBRARY();

/* All done. Note that the convertor returns 1 upon success, not
OMPI_SUCCESS. */
OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR,
MPI_COMM_WORLD, MPI_ERR_UNKNOWN, FUNC_NAME);
OMPI_ERRHANDLER_RETURN((OMPI_SUCCESS == rc) ? OMPI_SUCCESS : OMPI_ERROR,
MPI_COMM_WORLD, rc, FUNC_NAME);
}
23 changes: 7 additions & 16 deletions ompi/mpi/c/pack_external_size.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Copyright (c) 2006 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015 Research Organization for Information Science
* Copyright (c) 2015-2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
Expand Down Expand Up @@ -45,8 +45,7 @@ static const char FUNC_NAME[] = "MPI_Pack_external_size";
int MPI_Pack_external_size(const char datarep[], int incount,
MPI_Datatype datatype, MPI_Aint *size)
{
opal_convertor_t local_convertor;
size_t length;
int rc = MPI_SUCCESS;

MEMCHECKER(
memchecker_datatype(datatype);
Expand All @@ -63,18 +62,10 @@ int MPI_Pack_external_size(const char datarep[], int incount,

OPAL_CR_ENTER_LIBRARY();

OBJ_CONSTRUCT(&local_convertor, opal_convertor_t);

/* the resulting convertor will be set to the position ZERO */
opal_convertor_copy_and_prepare_for_recv( ompi_mpi_external32_convertor,
&(datatype->super), incount, NULL,
CONVERTOR_SEND_CONVERSION,
&local_convertor );

opal_convertor_get_unpacked_size( &local_convertor, &length );
*size = (MPI_Aint)length;
OBJ_DESTRUCT( &local_convertor );

rc = ompi_datatype_pack_external_size(datarep, incount,
datatype, size);
OPAL_CR_EXIT_LIBRARY();
return OMPI_SUCCESS;

OMPI_ERRHANDLER_RETURN((OMPI_SUCCESS == rc) ? OMPI_SUCCESS : OMPI_ERROR,
MPI_COMM_WORLD, rc, FUNC_NAME);
}
14 changes: 7 additions & 7 deletions ompi/mpi/c/unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* Copyright (c) 2004-2016 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
Expand Down Expand Up @@ -43,7 +43,7 @@ int MPI_Unpack(const void *inbuf, int insize, int *position,
void *outbuf, int outcount, MPI_Datatype datatype,
MPI_Comm comm)
{
int rc = 1;
int rc = MPI_SUCCESS;
opal_convertor_t local_convertor;
struct iovec outvec;
unsigned int iov_count;
Expand All @@ -70,9 +70,10 @@ int MPI_Unpack(const void *inbuf, int insize, int *position,
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
}

if (MPI_DATATYPE_NULL == datatype || NULL == datatype) {
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME);
}
OMPI_CHECK_DATATYPE_FOR_RECV(rc, datatype, outcount);
OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
OMPI_CHECK_USER_BUFFER(rc, outbuf, datatype, outcount);
OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
}

OPAL_CR_ENTER_LIBRARY();
Expand Down Expand Up @@ -103,12 +104,11 @@ int MPI_Unpack(const void *inbuf, int insize, int *position,

/* All done. Note that the convertor returns 1 upon success, not
OMPI_SUCCESS. */

rc = (1 == rc) ? OMPI_SUCCESS : OMPI_ERROR;
}

OPAL_CR_EXIT_LIBRARY();

OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR,
comm, MPI_ERR_UNKNOWN, FUNC_NAME);

}
Loading