root/ompi/mpi/c/pack.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. MPI_Pack

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   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-2017 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 #include "ompi_config.h"
  25 #include <stdio.h>
  26 
  27 #include "ompi/mpi/c/bindings.h"
  28 #include "ompi/runtime/params.h"
  29 #include "ompi/communicator/communicator.h"
  30 #include "ompi/errhandler/errhandler.h"
  31 #include "ompi/datatype/ompi_datatype.h"
  32 #include "opal/datatype/opal_convertor.h"
  33 #include "ompi/memchecker.h"
  34 
  35 #if OMPI_BUILD_MPI_PROFILING
  36 #if OPAL_HAVE_WEAK_SYMBOLS
  37 #pragma weak MPI_Pack = PMPI_Pack
  38 #endif
  39 #define MPI_Pack PMPI_Pack
  40 #endif
  41 
  42 static const char FUNC_NAME[] = "MPI_Pack";
  43 
  44 
  45 int MPI_Pack(const void *inbuf, int incount, MPI_Datatype datatype,
  46              void *outbuf, int outsize, int *position, MPI_Comm comm)
  47 {
  48     int rc = MPI_SUCCESS, ret;
  49     opal_convertor_t local_convertor;
  50     struct iovec invec;
  51     unsigned int iov_count;
  52     size_t size;
  53 
  54     MEMCHECKER(
  55         memchecker_datatype(datatype);
  56         memchecker_call(&opal_memchecker_base_isdefined, inbuf, incount, datatype);
  57         memchecker_comm(comm);
  58     );
  59 
  60     if (MPI_PARAM_CHECK) {
  61         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  62         if (ompi_comm_invalid(comm)) {
  63             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM, FUNC_NAME);
  64         } else if ((NULL == outbuf) || (NULL == position)) {  /* inbuf can be MPI_BOTTOM */
  65             return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
  66         } else if (incount < 0) {
  67             return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
  68         } else if (outsize < 0) {
  69             return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
  70         }
  71         OMPI_CHECK_DATATYPE_FOR_SEND(rc, datatype, incount);
  72         OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
  73         OMPI_CHECK_USER_BUFFER(rc, inbuf, datatype, incount);
  74         OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
  75     }
  76 
  77     OPAL_CR_ENTER_LIBRARY();
  78 
  79     OBJ_CONSTRUCT( &local_convertor, opal_convertor_t );
  80     /* the resulting convertor will be set to the position ZERO */
  81     opal_convertor_copy_and_prepare_for_send( ompi_mpi_local_convertor, &(datatype->super),
  82                                               incount, (void *) inbuf, 0, &local_convertor );
  83 
  84     /* Check for truncation */
  85     opal_convertor_get_packed_size( &local_convertor, &size );
  86     if( (*position + size) > (unsigned int)outsize ) {  /* we can cast as we already checked for < 0 */
  87         OBJ_DESTRUCT( &local_convertor );
  88         OPAL_CR_EXIT_LIBRARY();
  89         return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TRUNCATE, FUNC_NAME);
  90     }
  91 
  92     /* Prepare the iovec with all informations */
  93     invec.iov_base = (char*) outbuf + (*position);
  94     invec.iov_len = size;
  95 
  96     /* Do the actual packing */
  97     iov_count = 1;
  98     ret = opal_convertor_pack( &local_convertor, &invec, &iov_count, &size );
  99     *position += size;
 100     OBJ_DESTRUCT( &local_convertor );
 101 
 102     OPAL_CR_EXIT_LIBRARY();
 103 
 104     /* All done.  Note that the convertor returns 1 upon success, not
 105        OPAL_SUCCESS. */
 106     if (1 != ret) {
 107         rc = OMPI_ERROR;
 108     }
 109     OMPI_ERRHANDLER_RETURN(rc, comm, MPI_ERR_UNKNOWN, FUNC_NAME);
 110 }

/* [<][>][^][v][top][bottom][index][help] */