VariableBase.h 5.52 KB
Newer Older
1
/*
2
3
4
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
5
6
 * VariableBase.h Base class for Variable and VariableCompound types. Contains
 * common elements.
7
8
 *
 *  Created on: Feb 20, 2017
9
 *      Author: William F Godoy godoywf@ornl.gov
10
11
 */

12
13
#ifndef ADIOS2_CORE_VARIABLEBASE_H_
#define ADIOS2_CORE_VARIABLEBASE_H_
14
15

/// \cond EXCLUDE_FROM_DOXYGEN
16
#include <adios2/core/Operator.h>
17
18
19
#include <sstream>
#include <string>
#include <vector>
20
21
/// \endcond

22
#include "adios2/ADIOSConfig.h"
23
#include "adios2/ADIOSTypes.h"
24

wgodoy's avatar
wgodoy committed
25
namespace adios2
26
{
27
/** Base class for Variable<T> (primitives) and VariableCompound classes */
28
29
30
31
class VariableBase
{

public:
32
33
34
35
36
37
38
39
40
41
42
    /** Operators metadata info */
    struct OperatorInfo
    {
        /** reference to object derived from Operator class */
        Operator &ADIOSOperator;
        /** Variable specific parameters */
        Params Parameters;
        /** resulting sizes from Operator */
        Dims Sizes;
    };

43
44
    /** unique identifier inside Method that creates a Variable */
    const std::string m_Name;
45

46
47
    /** primitive from <T> or compound from struct */
    const std::string m_Type;
wfg's avatar
wfg committed
48

49
50
51
    /** Variable -> sizeof(T),
     *  VariableCompound -> from constructor sizeof(struct) */
    const size_t m_ElementSize;
52

53
54
55
56
    ShapeID m_ShapeID;                 ///< see shape types in ADIOSTypes.h
    bool m_SingleValue = false;        ///< true: single value, false: array
    const bool m_ConstantDims = false; ///< true: fix m_Shape, m_Start, m_Count
    Dims m_Shape;                      ///< total dimensions across MPI
57
58
    Dims m_Start; ///< starting point (offsets) in global shape
    Dims m_Count; ///< dimensions from m_Start in global shape
59

60
61
62
63
    /** Global array was written as Joined array, so read accordingly */
    bool m_ReadAsJoined = false;
    /** Global array was written as Local value, so read accordingly */
    bool m_ReadAsLocalValue = false;
64
65

    /** Registered transforms */
66
    std::vector<OperatorInfo> m_OperatorsInfo;
67

68
    size_t m_AvailableStepsStart = 1;
69
70
    size_t m_AvailableStepsCount = 0;

71
    size_t m_StepsStart = 0;
72
    size_t m_StepsCount = 1;
William F Godoy's avatar
William F Godoy committed
73

74
    /** Index Metadata Position in a serial metadata buffer */
William F Godoy's avatar
William F Godoy committed
75
    size_t m_IndexStart;
76

William F Godoy's avatar
William F Godoy committed
77
78
79
80
81
82
83
84
    /** Index to Step and Subsets inside a step characteristics position in a
     * serial metadata buffer
     * <pre>
     * key: step number (time_index in bp3 format)
     * value:  vector of block starts for that step
     * </pre>
     * */
    std::map<size_t, std::vector<size_t>> m_IndexStepBlockStarts;
85

86
    VariableBase(const std::string &name, const std::string type,
87
88
                 const size_t elementSize, const Dims &shape, const Dims &start,
                 const Dims &count, const bool constantShape,
89
                 const bool debugMode);
90

91
    virtual ~VariableBase() = default;
92
93
94

    /**
     * Returns the payload size in bytes
95
     * @return TotalSize * m_ElementSize
96
     */
William F Godoy's avatar
William F Godoy committed
97
    size_t PayloadSize() const noexcept;
98
99

    /**
100
     * Returns the total number of elements
101
102
     * @return number of elements
     */
103
    size_t TotalSize() const noexcept;
104

105
106
107
108
109
110
111
112
113
114
    /**
     * Set new shape
     * @param shape input shape to be applied to this variable
     */
    void SetShape(const adios2::Dims &shape);

    /**
     * Set new start and count dimensions
     * @param boxDims = {start, count}
     */
William F Godoy's avatar
William F Godoy committed
115
    void SetSelection(const Box<Dims> &boxDims);
116

117
118
119
120
121
122
    /**
     * Set the steps for the variable. The pointer passed at
     * reading must be able to hold enough memory to store multiple steps in a
     * single read. For writing it changes the time step
     * @param boxSteps {startStep, countStep}
     */
William F Godoy's avatar
William F Godoy committed
123
    void SetStepSelection(const Box<size_t> &boxSteps);
124
125
126
127
128
129

    /**
     * Set the local dimension and global offset of the variable using a
     * selection
     * Only bounding boxes are allowed
     */
William F Godoy's avatar
William F Godoy committed
130
    void SetMemorySelection(const Box<Dims> &boxDims);
131

132
133
    size_t GetAvailableStepsStart() const;

134
    size_t GetAvailableStepsCount() const;
135

136
    /**
137
     * Pushed a new transform to a sequence of transports. Not yet implemented.
138
139
140
141
     * @param transform reference to an object derived from the Transform class
     * @param parameters transform specific parameters
     * @return transformID handler
     */
142
    unsigned int AddTransform(Operator &transform,
143
                              const Params &parameters = Params()) noexcept;
144

145
146
    void ResetTransformParameters(const unsigned int transformIndex,
                                  const Params &parameters = Params());
147
148

    /** Clears out the transform sequence defined by AddTransform */
149
    void ClearOperators() noexcept;
150

151
152
    /** Self-check dims according to type, called from Engine before Write
     * @param hint extra debugging info for the exception */
153
    void CheckDimensions(const std::string hint) const;
154

155
156
157
158
159
    /**
     * Returns the minimum required allocation for the current selection
     * @return memory size to be allocated by a pointer/vector to read this
     * variable
     */
160
    size_t SelectionSize() const;
161

162
protected:
163
164
    const bool m_DebugMode = false;

165
166
167
    Dims m_MemoryStart; ///< offset of memory selection
    Dims m_MemoryCount; ///< subset of m_Shape (e.g. remove ghost points)

168
169
    unsigned int m_DeferredCounter = 0;

170
    void InitShapeType();
171
172
173
174

    /** Self-check dims according to type, called right after DefineVariable and
     *  SetSelection.
     * @param hint extra debugging info for the exception */
175
    void CheckDimensionsCommon(const std::string hint) const;
176
};
177

178
} // end namespace adios2
179

180
#endif /* ADIOS2_CORE_VARIABLEBASE_H_ */