Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
14 changes: 8 additions & 6 deletions ompi/mpi/c/pack.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-2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
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 = MPI_SUCCESS;
int rc = MPI_SUCCESS, ret;
opal_convertor_t local_convertor;
struct iovec invec;
unsigned int iov_count;
Expand Down Expand Up @@ -92,12 +92,14 @@ int MPI_Pack(const void *inbuf, int incount, MPI_Datatype datatype,

/* Do the actual packing */
iov_count = 1;
rc = opal_convertor_pack( &local_convertor, &invec, &iov_count, &size );
ret = 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. */
OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR,
comm, MPI_ERR_UNKNOWN, FUNC_NAME);
OPAL_SUCCESS. */
if (1 != ret) {
rc = OMPI_ERROR;
}
OMPI_ERRHANDLER_RETURN(rc, comm, MPI_ERR_UNKNOWN, FUNC_NAME);
}
41 changes: 5 additions & 36 deletions ompi/mpi/c/pack_external.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-2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
Expand Down Expand Up @@ -47,10 +47,6 @@ int MPI_Pack_external(const char datarep[], const void *inbuf, int incount,
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;

MEMCHECKER(
memchecker_datatype(datatype);
Expand All @@ -72,36 +68,9 @@ int MPI_Pack_external(const char datarep[], const void *inbuf, int incount,
OMPI_ERRHANDLER_CHECK(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
}

OBJ_CONSTRUCT(&local_convertor, opal_convertor_t);
rc = ompi_datatype_pack_external(datarep, inbuf, incount,
datatype, outbuf,
outsize, position);

/* 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 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 );

/* 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(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
}
21 changes: 5 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-2017 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 @@ -62,17 +61,7 @@ int MPI_Pack_external_size(const char datarep[], int incount,
}


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;
rc = ompi_datatype_pack_external_size(datarep, incount,
datatype, size);
OMPI_ERRHANDLER_RETURN(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
}
12 changes: 7 additions & 5 deletions ompi/mpi/c/unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006-2013 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* Copyright (c) 2015-2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
Expand Down Expand Up @@ -78,6 +78,7 @@ int MPI_Unpack(const void *inbuf, int insize, int *position,


if( insize > 0 ) {
int ret;
OBJ_CONSTRUCT( &local_convertor, opal_convertor_t );
/* the resulting convertor will be set the the position ZERO */
opal_convertor_copy_and_prepare_for_recv( ompi_mpi_local_convertor, &(datatype->super),
Expand All @@ -96,13 +97,14 @@ int MPI_Unpack(const void *inbuf, int insize, int *position,

/* Do the actual unpacking */
iov_count = 1;
rc = opal_convertor_unpack( &local_convertor, &outvec, &iov_count, &size );
ret = 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. */
rc = (1 == rc) ? OMPI_SUCCESS : OMPI_ERROR;
OPAL_SUCCESS. */
if (1 != ret) {
rc = OMPI_ERROR;
}
}

OMPI_ERRHANDLER_RETURN(rc, comm, MPI_ERR_UNKNOWN, FUNC_NAME);
Expand Down
Loading