root/ompi/mca/mtl/base/mtl_base_datatype.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. ompi_mtl_datatype_pack
  2. ompi_mtl_datatype_recv_buf
  3. ompi_mtl_datatype_unpack

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2006 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * $COPYRIGHT$
  13  *
  14  * Additional copyrights may follow
  15  *
  16  * $HEADER$
  17  */
  18 
  19 #include "ompi_config.h"
  20 
  21 #include "ompi/mca/mca.h"
  22 #include "ompi/mca/mtl/mtl.h"
  23 #include "ompi/mca/mtl/base/base.h"
  24 #include "ompi/constants.h"
  25 #include "ompi/datatype/ompi_datatype.h"
  26 #include "opal/datatype/opal_convertor.h"
  27 #include "opal/datatype/opal_datatype_internal.h"
  28 
  29 #ifndef MTL_BASE_DATATYPE_H_INCLUDED
  30 #define MTL_BASE_DATATYPE_H_INCLUDED
  31 
  32 __opal_attribute_always_inline__ static inline int
  33 ompi_mtl_datatype_pack(struct opal_convertor_t *convertor,
  34                        void **buffer,
  35                        size_t *buffer_len,
  36                        bool *freeAfter)
  37 {
  38     struct iovec iov;
  39     uint32_t iov_count = 1;
  40 
  41 #if !(OPAL_ENABLE_HETEROGENEOUS_SUPPORT)
  42     if (convertor->pDesc &&
  43         !(convertor->flags & CONVERTOR_COMPLETED) &&
  44         opal_datatype_is_contiguous_memory_layout(convertor->pDesc,
  45                                                   convertor->count)) {
  46             *freeAfter = false;
  47             *buffer = convertor->pBaseBuf;
  48             *buffer_len = convertor->local_size;
  49             return OPAL_SUCCESS;
  50     }
  51 #endif
  52 
  53     opal_convertor_get_packed_size(convertor, buffer_len);
  54     *freeAfter  = false;
  55     if( 0 == *buffer_len ) {
  56         *buffer     = NULL;
  57         return OMPI_SUCCESS;
  58     }
  59     iov.iov_len = *buffer_len;
  60     iov.iov_base = NULL;
  61     if (opal_convertor_need_buffers(convertor)) {
  62         iov.iov_base = malloc(*buffer_len);
  63         if (NULL == iov.iov_base) return OMPI_ERR_OUT_OF_RESOURCE;
  64         *freeAfter = true;
  65     }
  66 
  67     opal_convertor_pack( convertor, &iov, &iov_count, buffer_len );
  68 
  69     *buffer = iov.iov_base;
  70 
  71     return OMPI_SUCCESS;
  72 }
  73 
  74 
  75 __opal_attribute_always_inline__ static inline int
  76 ompi_mtl_datatype_recv_buf(struct opal_convertor_t *convertor,
  77                            void ** buffer,
  78                            size_t *buffer_len,
  79                            bool *free_on_error)
  80 {
  81     opal_convertor_get_packed_size(convertor, buffer_len);
  82     *free_on_error = false;
  83     if( 0 == *buffer_len ) {
  84         *buffer = NULL;
  85         *buffer_len = 0;
  86         return OMPI_SUCCESS;
  87     }
  88     if (opal_convertor_need_buffers(convertor)) {
  89         *buffer = malloc(*buffer_len);
  90         *free_on_error = true;
  91     } else {
  92         *buffer = convertor->pBaseBuf +
  93             convertor->use_desc->desc[convertor->use_desc->used].end_loop.first_elem_disp;
  94     }
  95     return OMPI_SUCCESS;
  96 }
  97 
  98 
  99 __opal_attribute_always_inline__ static inline int
 100 ompi_mtl_datatype_unpack(struct opal_convertor_t *convertor,
 101                          void *buffer,
 102                          size_t buffer_len)
 103 {
 104     struct iovec iov;
 105     uint32_t iov_count = 1;
 106 
 107     if (buffer_len > 0 && opal_convertor_need_buffers(convertor)) {
 108         iov.iov_len = buffer_len;
 109         iov.iov_base = buffer;
 110 
 111         opal_convertor_unpack(convertor, &iov, &iov_count, &buffer_len );
 112 
 113         free(buffer);
 114     }
 115 
 116     return OMPI_SUCCESS;
 117 }
 118 
 119 #endif /* MTL_BASE_DATATYPE_H_INCLUDED */

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