root/ompi/datatype/ompi_datatype_create.c

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

DEFINITIONS

This source file includes following definitions.
  1. __ompi_datatype_allocate
  2. __ompi_datatype_release
  3. ompi_datatype_create
  4. ompi_datatype_destroy
  5. ompi_datatype_duplicate

   1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
   2 /*
   3  * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2013 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2009      Oak Ridge National Labs.  All rights reserved.
  12  * Copyright (c) 2010-2018 Cisco Systems, Inc.  All rights reserved
  13  * Copyright (c) 2018      Amazon.com, Inc. or its affiliates.  All Rights reserved.
  14  * $COPYRIGHT$
  15  *
  16  * Additional copyrights may follow
  17  *
  18  * $HEADER$
  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     /* Do not add the newly created datatypes to the f2c translation table. We will add them only
  36      * if necessary, basically upon the first call the MPI_Datatype_f2c.
  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     /* any pending attributes ? */
  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     /* make sure the name is set to empty */
  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     /* Strip the predefined flag at the OMPI level. */
 106     new_ompi_datatype->super.flags &= ~OMPI_DATATYPE_FLAG_PREDEFINED;
 107     /* By default maintain the relationships related to the old data (such as ops) */
 108     new_ompi_datatype->id = oldType->id;
 109 
 110     /* Set the keyhash to NULL -- copying attributes is *only* done at
 111        the top level (specifically, MPI_TYPE_DUP). */
 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 

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