1
1

datatype/[un]pack_external[_size]: move subroutines down to ompi/datatype

so it can be directly used by test/datatype/external32
This commit is contained in:
Gilles Gouaillardet 2016-03-30 11:43:45 +09:00
parent 63eec552b2
commit 5932287cef
7 changed files with 173 additions and 196 deletions

View File

@ -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
@ -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 \

View File

@ -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$
*
@ -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 */

View File

@ -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;
}

View File

@ -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);
@ -74,39 +70,12 @@ int MPI_Pack_external(const char datarep[], const void *inbuf, int incount,
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);
}

View File

@ -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$
*
@ -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);
@ -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);
}

View File

@ -46,10 +46,6 @@ int MPI_Unpack_external (const char datarep[], const void *inbuf, MPI_Aint insiz
MPI_Datatype datatype)
{
int rc = MPI_SUCCESS;
opal_convertor_t local_convertor;
struct iovec outvec;
unsigned int iov_count;
size_t size;
MEMCHECKER(
memchecker_datatype(datatype);
@ -71,36 +67,12 @@ int MPI_Unpack_external (const char datarep[], const void *inbuf, MPI_Aint insiz
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), 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 );
OPAL_CR_EXIT_LIBRARY();
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_TRUNCATE, FUNC_NAME);
}
/* 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 );
rc = ompi_datatype_unpack_external(datarep, inbuf, insize,
position, outbuf, outcount,
datatype);
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);
}

View File

@ -43,110 +43,6 @@ static void dump_hex(void* what, size_t length)
}
}
int MPI_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;
}
int MPI_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 : OMPI_ERROR;
}
int MPI_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 : OMPI_ERROR;
}
int check_contiguous( void* send_buffer, void* packed,
ompi_datatype_t* datatype, int count, void* arg )
{
@ -220,15 +116,15 @@ static int pack_unpack_datatype( void* send_data, ompi_datatype_t *datatype, int
void* buffer;
int error;
error = MPI_Pack_external_size("external32",
count, datatype, &buffer_size);
error = ompi_datatype_pack_external_size("external32",
count, datatype, &buffer_size);
if( MPI_SUCCESS != error ) goto return_error_code;
buffer = (void*)malloc(buffer_size);
if( NULL == buffer ) { error = MPI_ERR_UNKNOWN; goto return_error_code; }
error = MPI_Pack_external("external32", (void*)send_data, count, datatype,
buffer, buffer_size, &position);
error = ompi_datatype_pack_external("external32", (void*)send_data, count, datatype,
buffer, buffer_size, &position);
if( MPI_SUCCESS != error ) goto return_error_code;
if( 0 != validator(send_data, buffer, datatype, count, validator_arg) ) {
printf("Error during pack external. Bailing out\n");
@ -238,8 +134,8 @@ static int pack_unpack_datatype( void* send_data, ompi_datatype_t *datatype, int
printf("packed %ld bytes into a %ld bytes buffer ", position, buffer_size); dump_hex(buffer, position); printf("\n");
position = 0;
error = MPI_Unpack_external("external32", buffer, buffer_size, &position,
recv_data, count, datatype);
error = ompi_datatype_unpack_external("external32", buffer, buffer_size, &position,
recv_data, count, datatype);
if( MPI_SUCCESS != error ) goto return_error_code;
free(buffer);