root/opal/datatype/opal_datatype_create.c

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

DEFINITIONS

This source file includes following definitions.
  1. opal_datatype_construct
  2. opal_datatype_destruct
  3. opal_datatype_create
  4. opal_datatype_create_desc

   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-2017 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) 2004-2006 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2009      Oak Ridge National Labs.  All rights reserved.
  14  * Copyright (c) 2019      Research Organization for Information Science
  15  *                         and Technology (RIST).  All rights reserved.
  16  * $COPYRIGHT$
  17  *
  18  * Additional copyrights may follow
  19  *
  20  * $HEADER$
  21  */
  22 
  23 #include "opal_config.h"
  24 
  25 #include <stddef.h>
  26 
  27 #include "opal/constants.h"
  28 #include "opal/datatype/opal_datatype.h"
  29 #include "opal/datatype/opal_datatype_internal.h"
  30 #include "limits.h"
  31 #include "opal/prefetch.h"
  32 
  33 static void opal_datatype_construct( opal_datatype_t* pData )
  34 {
  35     pData->size               = 0;
  36     pData->flags              = OPAL_DATATYPE_FLAG_CONTIGUOUS;
  37     pData->id                 = 0;
  38     pData->bdt_used           = 0;
  39     pData->size               = 0;
  40     pData->true_lb            = LONG_MAX;
  41     pData->true_ub            = LONG_MIN;
  42     pData->lb                 = LONG_MAX;
  43     pData->ub                 = LONG_MIN;
  44     pData->align              = 1;
  45     pData->nbElems            = 0;
  46     memset(pData->name, 0, OPAL_MAX_OBJECT_NAME);
  47 
  48     pData->desc.desc          = NULL;
  49     pData->desc.length        = 0;
  50     pData->desc.used          = 0;
  51 
  52     pData->opt_desc.desc      = NULL;
  53     pData->opt_desc.length    = 0;
  54     pData->opt_desc.used      = 0;
  55 
  56     pData->ptypes             = NULL;
  57     pData->loops              = 0;
  58 }
  59 
  60 static void opal_datatype_destruct( opal_datatype_t* datatype )
  61 {
  62     /**
  63      * As the default description and the optimized description might point to the
  64      * same data description we should start by cleaning the optimized description.
  65      */
  66     if( NULL != datatype->opt_desc.desc ) {
  67         if( datatype->opt_desc.desc != datatype->desc.desc )
  68             free( datatype->opt_desc.desc );
  69         datatype->opt_desc.length = 0;
  70         datatype->opt_desc.used   = 0;
  71         datatype->opt_desc.desc   = NULL;
  72     }
  73     if (!opal_datatype_is_predefined(datatype)) {
  74         if( NULL != datatype->desc.desc ) {
  75             free( datatype->desc.desc );
  76             datatype->desc.length = 0;
  77             datatype->desc.used   = 0;
  78             datatype->desc.desc   = NULL;
  79         }
  80     }
  81     /* dont free the ptypes of predefined types (it was not dynamically allocated) */
  82     if( (NULL != datatype->ptypes) && (!opal_datatype_is_predefined(datatype)) ) {
  83         free(datatype->ptypes);
  84         datatype->ptypes = NULL;
  85     }
  86 
  87     /* make sure the name is set to empty */
  88     datatype->name[0] = '\0';
  89 }
  90 
  91 OBJ_CLASS_INSTANCE(opal_datatype_t, opal_object_t, opal_datatype_construct, opal_datatype_destruct);
  92 
  93 opal_datatype_t* opal_datatype_create( int32_t expectedSize )
  94 {
  95     opal_datatype_t* datatype = (opal_datatype_t*)OBJ_NEW(opal_datatype_t);
  96 
  97     if( expectedSize == -1 ) expectedSize = DT_INCREASE_STACK;
  98     datatype->desc.length = expectedSize + 1;  /* one for the fake elem at the end */
  99     datatype->desc.used   = 0;
 100     datatype->desc.desc   = (dt_elem_desc_t*)calloc(datatype->desc.length, sizeof(dt_elem_desc_t));
 101     /* BEWARE: an upper-layer configured with OPAL_MAX_OBJECT_NAME different than the OPAL-layer will not work! */
 102     memset( datatype->name, 0, OPAL_MAX_OBJECT_NAME );
 103     return datatype;
 104 }
 105 
 106 int32_t opal_datatype_create_desc( opal_datatype_t * datatype, int32_t expectedSize )
 107 {
 108     if( expectedSize == -1 )
 109         expectedSize = DT_INCREASE_STACK;
 110     datatype->desc.length = expectedSize + 1;  /* one for the fake elem at the end */
 111     datatype->desc.used   = 0;
 112     datatype->desc.desc   = (dt_elem_desc_t*)calloc(datatype->desc.length, sizeof(dt_elem_desc_t));
 113     if (NULL == datatype->desc.desc)
 114         return OPAL_ERR_OUT_OF_RESOURCE;
 115     return OPAL_SUCCESS;
 116 }

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