This source file includes following definitions.
- __ompi_datatype_allocate
- __ompi_datatype_release
- ompi_datatype_create
- ompi_datatype_destroy
- ompi_datatype_duplicate
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  21 #include "ompi_config.h"
  22 
  23 #include <stddef.h>
  24 #include <string.h>
  25 
  26 #include "opal/class/opal_pointer_array.h"
  27 #include "opal/util/printf.h"
  28 #include "opal/util/string_copy.h"
  29 #include "ompi/datatype/ompi_datatype.h"
  30 #include "ompi/attribute/attribute.h"
  31 
  32 static void __ompi_datatype_allocate( ompi_datatype_t* datatype )
  33 {
  34     datatype->args               = NULL;
  35     
  36 
  37 
  38     datatype->d_f_to_c_index     = -1;
  39     datatype->id                 = -1;
  40     datatype->d_keyhash          = NULL;
  41     datatype->name[0]            = '\0';
  42     datatype->packed_description = 0;
  43     datatype->pml_data           = 0;
  44 }
  45 
  46 static void __ompi_datatype_release(ompi_datatype_t * datatype)
  47 {
  48     if( NULL != datatype->args ) {
  49         ompi_datatype_release_args( datatype );
  50         datatype->args = NULL;
  51     }
  52 
  53     free ((void *) datatype->packed_description );
  54     datatype->packed_description = 0;
  55 
  56     if( datatype->d_f_to_c_index >= 0 ) {
  57         opal_pointer_array_set_item( &ompi_datatype_f_to_c_table, datatype->d_f_to_c_index, NULL );
  58         datatype->d_f_to_c_index = -1;
  59     }
  60     
  61     if (NULL != datatype->d_keyhash) {
  62         ompi_attr_delete_all( TYPE_ATTR, datatype, datatype->d_keyhash );
  63         OBJ_RELEASE( datatype->d_keyhash );
  64     }
  65     
  66     datatype->name[0] = '\0';
  67 }
  68 
  69 OBJ_CLASS_INSTANCE(ompi_datatype_t, opal_datatype_t, __ompi_datatype_allocate, __ompi_datatype_release);
  70 
  71 ompi_datatype_t * ompi_datatype_create( int32_t expectedSize )
  72 {
  73     int ret;
  74     ompi_datatype_t * datatype = (ompi_datatype_t*)OBJ_NEW(ompi_datatype_t);
  75 
  76     ret = opal_datatype_create_desc( &(datatype->super), expectedSize);
  77     if (OPAL_SUCCESS != ret)
  78         return NULL;
  79 
  80     return datatype;
  81 }
  82 
  83 int32_t ompi_datatype_destroy( ompi_datatype_t** type)
  84 {
  85     ompi_datatype_t* pData = *type;
  86 
  87     if( ompi_datatype_is_predefined(pData) && (pData->super.super.obj_reference_count <= 1) )
  88         return OMPI_ERROR;
  89 
  90     OBJ_RELEASE(pData);
  91     *type = NULL;
  92     return OMPI_SUCCESS;
  93 }
  94 
  95 int32_t
  96 ompi_datatype_duplicate( const ompi_datatype_t* oldType, ompi_datatype_t** newType )
  97 {
  98     ompi_datatype_t * new_ompi_datatype = ompi_datatype_create( oldType->super.desc.used + 2 );
  99 
 100     *newType = new_ompi_datatype;
 101     if( NULL == new_ompi_datatype ) {
 102         return OMPI_ERR_OUT_OF_RESOURCE;
 103     }
 104     opal_datatype_clone( &oldType->super, &new_ompi_datatype->super);
 105     
 106     new_ompi_datatype->super.flags &= ~OMPI_DATATYPE_FLAG_PREDEFINED;
 107     
 108     new_ompi_datatype->id = oldType->id;
 109 
 110     
 111 
 112     new_ompi_datatype->d_keyhash = NULL;
 113     new_ompi_datatype->args = NULL;
 114 
 115     char *new_name;
 116     opal_asprintf(&new_name, "Dup %s", oldType->name);
 117     opal_string_copy(new_ompi_datatype->name, new_name, MPI_MAX_OBJECT_NAME);
 118     new_ompi_datatype->name[MPI_MAX_OBJECT_NAME - 1] = '\0';
 119     free(new_name);
 120 
 121     return OMPI_SUCCESS;
 122 }
 123