root/ompi/mpi/c/unpack.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_Unpack

   1 /*
   2  * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2016 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2006-2013 Cisco Systems, Inc.  All rights reserved.
  13  * Copyright (c) 2015-2017 Research Organization for Information Science
  14  *                         and Technology (RIST). All rights reserved.
  15  * $COPYRIGHT$
  16  *
  17  * Additional copyrights may follow
  18  *
  19  * $HEADER$
  20  */
  21 #include "ompi_config.h"
  22 #include <stdio.h>
  23 
  24 #include "ompi/mpi/c/bindings.h"
  25 #include "ompi/runtime/params.h"
  26 #include "ompi/communicator/communicator.h"
  27 #include "ompi/errhandler/errhandler.h"
  28 #include "ompi/datatype/ompi_datatype.h"
  29 #include "opal/datatype/opal_convertor.h"
  30 #include "ompi/memchecker.h"
  31 
  32 #if OMPI_BUILD_MPI_PROFILING
  33 #if OPAL_HAVE_WEAK_SYMBOLS
  34 #pragma weak MPI_Unpack = PMPI_Unpack
  35 #endif
  36 #define MPI_Unpack PMPI_Unpack
  37 #endif
  38 
  39 static const char FUNC_NAME[] = "MPI_Unpack";
  40 
  41 
  42 int MPI_Unpack(const void *inbuf, int insize, int *position,
  43                void *outbuf, int outcount, MPI_Datatype datatype,
  44                MPI_Comm comm)
  45 {
  46     int rc = MPI_SUCCESS;
  47     opal_convertor_t local_convertor;
  48     struct iovec outvec;
  49     unsigned int iov_count;
  50     size_t size;
  51 
  52     MEMCHECKER(
  53         memchecker_datatype(datatype);
  54         memchecker_call(&opal_memchecker_base_isdefined, outbuf, outcount, datatype);
  55         memchecker_comm(comm);
  56     );
  57 
  58     if (MPI_PARAM_CHECK) {
  59         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  60         if (ompi_comm_invalid(comm)) {
  61             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
  62                                           FUNC_NAME);
  63         }
  64 
  65         if ((NULL == inbuf) || (NULL == position)) {  /* outbuf can be MPI_BOTTOM */
  66             return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
  67         }
  68 
  69         if (outcount < 0) {
  70             return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
  71         }
  72 
  73         OMPI_CHECK_DATATYPE_FOR_RECV(rc, datatype, outcount);
  74         OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
  75         OMPI_CHECK_USER_BUFFER(rc, outbuf, datatype, outcount);
  76         OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
  77     }
  78 
  79     OPAL_CR_ENTER_LIBRARY();
  80 
  81     if( insize > 0 ) {
  82         int ret;
  83         OBJ_CONSTRUCT( &local_convertor, opal_convertor_t );
  84         /* the resulting convertor will be set the the position ZERO */
  85         opal_convertor_copy_and_prepare_for_recv( ompi_mpi_local_convertor, &(datatype->super),
  86                                                   outcount, outbuf, 0, &local_convertor );
  87 
  88         /* Check for truncation */
  89         opal_convertor_get_packed_size( &local_convertor, &size );
  90         if( (*position + size) > (unsigned int)insize ) {
  91             OBJ_DESTRUCT( &local_convertor );
  92             OPAL_CR_EXIT_LIBRARY();
  93             return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TRUNCATE, FUNC_NAME);
  94         }
  95 
  96         /* Prepare the iovec with all informations */
  97         outvec.iov_base = (char*) inbuf + (*position);
  98         outvec.iov_len = size;
  99 
 100         /* Do the actual unpacking */
 101         iov_count = 1;
 102         ret = opal_convertor_unpack( &local_convertor, &outvec, &iov_count, &size );
 103         *position += size;
 104         OBJ_DESTRUCT( &local_convertor );
 105         /* All done.  Note that the convertor returns 1 upon success, not
 106            OPAL_SUCCESS. */
 107         if (1 != ret) {
 108             rc = OMPI_ERROR;
 109         }
 110     }
 111 
 112     OPAL_CR_EXIT_LIBRARY();
 113 
 114     OMPI_ERRHANDLER_RETURN(rc, comm, MPI_ERR_UNKNOWN, FUNC_NAME);
 115 }

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