File: opal_datatype_create.c

package info (click to toggle)
openmpi 5.0.8-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 201,684 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (122 lines) | stat: -rw-r--r-- 4,173 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
 * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2017 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2006 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2009      Oak Ridge National Labs.  All rights reserved.
 * Copyright (c) 2019      Research Organization for Information Science
 *                         and Technology (RIST).  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "opal_config.h"

#include <stddef.h>

#include "limits.h"
#include "opal/constants.h"
#include "opal/datatype/opal_datatype.h"
#include "opal/datatype/opal_datatype_internal.h"
#include "opal/prefetch.h"

static void opal_datatype_construct(opal_datatype_t *pData)
{
    pData->size = 0;
    pData->flags = OPAL_DATATYPE_FLAG_CONTIGUOUS;
    pData->id = 0;
    pData->bdt_used = 0;
    pData->size = 0;
    pData->true_lb = LONG_MAX;
    pData->true_ub = LONG_MIN;
    pData->lb = LONG_MAX;
    pData->ub = LONG_MIN;
    pData->align = 1;
    pData->nbElems = 0;
    memset(pData->name, 0, OPAL_MAX_OBJECT_NAME);

    pData->desc.desc = NULL;
    pData->desc.length = 0;
    pData->desc.used = 0;

    pData->opt_desc.desc = NULL;
    pData->opt_desc.length = 0;
    pData->opt_desc.used = 0;

    pData->ptypes = NULL;
    pData->loops = 0;
}

static void opal_datatype_destruct(opal_datatype_t *datatype)
{
    /**
     * As the default description and the optimized description might point to the
     * same data description we should start by cleaning the optimized description.
     */
    if (NULL != datatype->opt_desc.desc) {
        if (datatype->opt_desc.desc != datatype->desc.desc) {
            free(datatype->opt_desc.desc);
        }
        datatype->opt_desc.length = 0;
        datatype->opt_desc.used = 0;
        datatype->opt_desc.desc = NULL;
    }
    if (!opal_datatype_is_predefined(datatype)) {
        if (NULL != datatype->desc.desc) {
            free(datatype->desc.desc);
            datatype->desc.length = 0;
            datatype->desc.used = 0;
            datatype->desc.desc = NULL;
        }
    }
    /* dont free the ptypes of predefined types (it was not dynamically allocated) */
    if ((NULL != datatype->ptypes) && (!opal_datatype_is_predefined(datatype))) {
        free(datatype->ptypes);
        datatype->ptypes = NULL;
    }

    /* make sure the name is set to empty */
    datatype->name[0] = '\0';
}

OBJ_CLASS_INSTANCE(opal_datatype_t, opal_object_t, opal_datatype_construct, opal_datatype_destruct);

opal_datatype_t *opal_datatype_create(int32_t expectedSize)
{
    opal_datatype_t *datatype = (opal_datatype_t *) OBJ_NEW(opal_datatype_t);

    if (expectedSize == -1) {
        expectedSize = DT_INCREASE_STACK;
    }
    datatype->desc.length = expectedSize + 1; /* one for the fake elem at the end */
    datatype->desc.used = 0;
    datatype->desc.desc = (dt_elem_desc_t *) calloc(datatype->desc.length, sizeof(dt_elem_desc_t));
    /* BEWARE: an upper-layer configured with OPAL_MAX_OBJECT_NAME different than the OPAL-layer
     * will not work! */
    memset(datatype->name, 0, OPAL_MAX_OBJECT_NAME);
    return datatype;
}

int32_t opal_datatype_create_desc(opal_datatype_t *datatype, int32_t expectedSize)
{
    if (expectedSize == -1) {
        expectedSize = DT_INCREASE_STACK;
    }
    datatype->desc.length = expectedSize + 1; /* one for the fake elem at the end */
    datatype->desc.used = 0;
    datatype->desc.desc = (dt_elem_desc_t *) calloc(datatype->desc.length, sizeof(dt_elem_desc_t));
    if (NULL == datatype->desc.desc) {
        return OPAL_ERR_OUT_OF_RESOURCE;
    }
    return OPAL_SUCCESS;
}