|
| 1 | +/* -*- Mode: C; c-basic-offset:4 ; -*- */ |
| 2 | +/* |
| 3 | + * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana |
| 4 | + * University Research and Technology |
| 5 | + * Corporation. All rights reserved. |
| 6 | + * Copyright (c) 2004-2016 The University of Tennessee and The University |
| 7 | + * of Tennessee Research Foundation. All rights |
| 8 | + * reserved. |
| 9 | + * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart, |
| 10 | + * University of Stuttgart. All rights reserved. |
| 11 | + * Copyright (c) 2004-2005 The Regents of the University of California. |
| 12 | + * All rights reserved. |
| 13 | + * Copyright (c) 2006 Cisco Systems, Inc. All rights reserved. |
| 14 | + * Copyright (c) 2013 Los Alamos National Security, LLC. All rights |
| 15 | + * reserved. |
| 16 | + * Copyright (c) 2015-2016 Research Organization for Information Science |
| 17 | + * and Technology (RIST). All rights reserved. |
| 18 | + * $COPYRIGHT$ |
| 19 | + * |
| 20 | + * Additional copyrights may follow |
| 21 | + * |
| 22 | + * $HEADER$ |
| 23 | + */ |
| 24 | + |
| 25 | +#include "ompi_config.h" |
| 26 | +#include <stdio.h> |
| 27 | + |
| 28 | +#include "ompi/runtime/params.h" |
| 29 | +#include "ompi/communicator/communicator.h" |
| 30 | +#include "ompi/datatype/ompi_datatype.h" |
| 31 | +#include "opal/datatype/opal_convertor.h" |
| 32 | + |
| 33 | +int ompi_datatype_pack_external(const char datarep[], const void *inbuf, int incount, |
| 34 | + ompi_datatype_t *datatype, void *outbuf, |
| 35 | + MPI_Aint outsize, MPI_Aint *position) |
| 36 | +{ |
| 37 | + int rc = MPI_SUCCESS; |
| 38 | + opal_convertor_t local_convertor; |
| 39 | + struct iovec invec; |
| 40 | + unsigned int iov_count; |
| 41 | + size_t size; |
| 42 | + |
| 43 | + OBJ_CONSTRUCT(&local_convertor, opal_convertor_t); |
| 44 | + |
| 45 | + /* The resulting convertor will be set to the position zero. We have to use |
| 46 | + * CONVERTOR_SEND_CONVERSION in order to force the convertor to do anything |
| 47 | + * more than just packing the data. |
| 48 | + */ |
| 49 | + opal_convertor_copy_and_prepare_for_send( ompi_mpi_external32_convertor, |
| 50 | + &(datatype->super), incount, (void *) inbuf, |
| 51 | + CONVERTOR_SEND_CONVERSION, |
| 52 | + &local_convertor ); |
| 53 | + |
| 54 | + /* Check for truncation */ |
| 55 | + opal_convertor_get_packed_size( &local_convertor, &size ); |
| 56 | + if( (*position + size) > (size_t)outsize ) { /* we can cast as we already checked for < 0 */ |
| 57 | + OBJ_DESTRUCT( &local_convertor ); |
| 58 | + return MPI_ERR_TRUNCATE; |
| 59 | + } |
| 60 | + |
| 61 | + /* Prepare the iovec with all informations */ |
| 62 | + invec.iov_base = (char*) outbuf + (*position); |
| 63 | + invec.iov_len = size; |
| 64 | + |
| 65 | + /* Do the actual packing */ |
| 66 | + iov_count = 1; |
| 67 | + rc = opal_convertor_pack( &local_convertor, &invec, &iov_count, &size ); |
| 68 | + *position += size; |
| 69 | + OBJ_DESTRUCT( &local_convertor ); |
| 70 | + |
| 71 | + /* All done. Note that the convertor returns 1 upon success, not |
| 72 | + OMPI_SUCCESS. */ |
| 73 | + return (rc == 1) ? OMPI_SUCCESS : MPI_ERR_UNKNOWN; |
| 74 | +} |
| 75 | + |
| 76 | +int ompi_datatype_unpack_external (const char datarep[], const void *inbuf, MPI_Aint insize, |
| 77 | + MPI_Aint *position, void *outbuf, int outcount, |
| 78 | + ompi_datatype_t *datatype) |
| 79 | +{ |
| 80 | + int rc = MPI_SUCCESS; |
| 81 | + opal_convertor_t local_convertor; |
| 82 | + struct iovec outvec; |
| 83 | + unsigned int iov_count; |
| 84 | + size_t size; |
| 85 | + |
| 86 | + OBJ_CONSTRUCT(&local_convertor, opal_convertor_t); |
| 87 | + |
| 88 | + /* the resulting convertor will be set to the position ZERO */ |
| 89 | + opal_convertor_copy_and_prepare_for_recv( ompi_mpi_external32_convertor, |
| 90 | + &(datatype->super), outcount, outbuf, |
| 91 | + 0, |
| 92 | + &local_convertor ); |
| 93 | + |
| 94 | + /* Check for truncation */ |
| 95 | + opal_convertor_get_packed_size( &local_convertor, &size ); |
| 96 | + if( (*position + size) > (unsigned int)insize ) { |
| 97 | + OBJ_DESTRUCT( &local_convertor ); |
| 98 | + return MPI_ERR_TRUNCATE; |
| 99 | + } |
| 100 | + |
| 101 | + /* Prepare the iovec with all informations */ |
| 102 | + outvec.iov_base = (char*) inbuf + (*position); |
| 103 | + outvec.iov_len = size; |
| 104 | + |
| 105 | + /* Do the actual unpacking */ |
| 106 | + iov_count = 1; |
| 107 | + rc = opal_convertor_unpack( &local_convertor, &outvec, &iov_count, &size ); |
| 108 | + *position += size; |
| 109 | + OBJ_DESTRUCT( &local_convertor ); |
| 110 | + |
| 111 | + /* All done. Note that the convertor returns 1 upon success, not |
| 112 | + OMPI_SUCCESS. */ |
| 113 | + return (rc == 1) ? OMPI_SUCCESS : MPI_ERR_UNKNOWN; |
| 114 | +} |
| 115 | + |
| 116 | +int ompi_datatype_pack_external_size(const char datarep[], int incount, |
| 117 | + ompi_datatype_t *datatype, MPI_Aint *size) |
| 118 | +{ |
| 119 | + opal_convertor_t local_convertor; |
| 120 | + size_t length; |
| 121 | + |
| 122 | + OBJ_CONSTRUCT(&local_convertor, opal_convertor_t); |
| 123 | + |
| 124 | + /* the resulting convertor will be set to the position ZERO */ |
| 125 | + opal_convertor_copy_and_prepare_for_recv( ompi_mpi_external32_convertor, |
| 126 | + &(datatype->super), incount, NULL, |
| 127 | + CONVERTOR_SEND_CONVERSION, |
| 128 | + &local_convertor ); |
| 129 | + |
| 130 | + opal_convertor_get_unpacked_size( &local_convertor, &length ); |
| 131 | + *size = (MPI_Aint)length; |
| 132 | + OBJ_DESTRUCT( &local_convertor ); |
| 133 | + |
| 134 | + return OMPI_SUCCESS; |
| 135 | +} |
0 commit comments