SST  7.0.0
StructuralSimulationToolkit
statoutputhdf5.h
1 // Copyright 2009-2017 Sandia Corporation. Under the terms
2 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2017, Sandia Corporation
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef _H_SST_CORE_STATISTICS_OUTPUTHDF5
13 #define _H_SST_CORE_STATISTICS_OUTPUTHDF5
14 
15 #include "sst/core/sst_types.h"
16 
17 #include <sst/core/statapi/statoutput.h>
18 #include <sst/core/warnmacros.h>
19 
20 DISABLE_WARN_MISSING_OVERRIDE
21 #include "H5Cpp.h"
22 REENABLE_WARNING
23 
24 #include <map>
25 #include <string>
26 
27 namespace SST {
28 namespace Statistics {
29 
30 /**
31  \class StatisticOutputHDF5
32 
33  The class for statistics output to a comma separated file.
34 */
36 {
37 public:
38  /** Construct a StatOutputHDF5
39  * @param outputParameters - Parameters used for this Statistic Output
40  */
41  StatisticOutputHDF5(Params& outputParameters);
42 
43  bool acceptsGroups() const override { return true; }
44 protected:
45  /** Perform a check of provided parameters
46  * @return True if all required parameters and options are acceptable
47  */
48  bool checkOutputParameters() override;
49 
50  /** Print out usage for this Statistic Output */
51  void printUsage() override;
52 
53  void implStartRegisterFields(StatisticBase *stat) override;
54  void implRegisteredField(fieldHandle_t fieldHandle) override;
55  void implStopRegisterFields() override;
56 
57  void implStartRegisterGroup(StatisticGroup* group ) override;
58  void implStopRegisterGroup() override;
59 
60  /** Indicate to Statistic Output that simulation started.
61  * Statistic output may perform any startup code here as necessary.
62  */
63  void startOfSimulation() override;
64 
65  /** Indicate to Statistic Output that simulation ended.
66  * Statistic output may perform any shutdown code here as necessary.
67  */
68  void endOfSimulation() override;
69 
70  /** Implementation function for the start of output.
71  * This will be called by the Statistic Processing Engine to indicate that
72  * a Statistic is about to send data to the Statistic Output for processing.
73  * @param statistic - Pointer to the statistic object than the output can
74  * retrieve data from.
75  */
76  void implStartOutputEntries(StatisticBase* statistic) override;
77 
78  /** Implementation function for the end of output.
79  * This will be called by the Statistic Processing Engine to indicate that
80  * a Statistic is finished sendind data to the Statistic Output for processing.
81  * The Statisic Output can perform any output related functions here.
82  */
83  void implStopOutputEntries() override;
84 
85  void implStartOutputGroup(StatisticGroup* group) override;
86  void implStopOutputGroup() override;
87 
88  /** Implementation functions for output.
89  * These will be called by the statistic to provide Statistic defined
90  * data to be output.
91  * @param fieldHandle - The handle to the registered statistic field.
92  * @param data - The data related to the registered field to be output.
93  */
94  void implOutputField(fieldHandle_t fieldHandle, int32_t data) override;
95  void implOutputField(fieldHandle_t fieldHandle, uint32_t data) override;
96  void implOutputField(fieldHandle_t fieldHandle, int64_t data) override;
97  void implOutputField(fieldHandle_t fieldHandle, uint64_t data) override;
98  void implOutputField(fieldHandle_t fieldHandle, float data) override;
99  void implOutputField(fieldHandle_t fieldHandle, double data) override;
100 
101 protected:
102  StatisticOutputHDF5() {;} // For serialization
103 
104 private:
105 
106  typedef union {
107  int32_t i32;
108  uint32_t u32;
109  int64_t i64;
110  uint64_t u64;
111  float f;
112  double d;
113  } StatData_u;
114 
115 
116  class DataSet {
117  public:
118  DataSet(H5::H5File *file) : file(file) { }
119  virtual ~DataSet() { }
120  H5::H5File* getFile() { return file; }
121  virtual bool isGroup() const = 0;
122 
123  virtual void setCurrentStatistic(StatisticBase *UNUSED(stat)) { }
124  virtual void registerField(StatisticFieldInfo *fi) = 0;
125  virtual void finalizeCurrentStatistic() = 0;
126 
127  virtual void beginGroupRegistration(StatisticGroup *UNUSED(group)) { }
128  virtual void finalizeGroupRegistration() { }
129 
130 
131  virtual void startNewGroupEntry() {}
132  virtual void finishGroupEntry() {}
133 
134  virtual void startNewEntry(StatisticBase *stat) = 0;
135  virtual StatData_u& getFieldLoc(fieldHandle_t fieldHandle) = 0;
136  virtual void finishEntry() = 0;
137 
138  protected:
139  H5::H5File *file;
140  };
141 
142  class StatisticInfo : public DataSet {
143  StatisticBase *statistic;
144  std::vector<fieldHandle_t> indexMap;
145  std::vector<StatData_u> currentData;
146  std::vector<fieldType_t> typeList;
147  std::vector<std::string> fieldNames;
148 
149  H5::DataSet *dataset;
150  H5::CompType *memType;
151 
152  hsize_t nEntries;
153 
154  public:
155  StatisticInfo(StatisticBase *stat, H5::H5File *file) :
156  DataSet(file), statistic(stat), nEntries(0)
157  {
158  typeList.push_back(StatisticFieldInfo::UINT64);
159  indexMap.push_back(-1);
160  fieldNames.push_back("SimTime");
161  }
162  ~StatisticInfo() {
163  if ( dataset ) delete dataset;
164  if ( memType ) delete memType;
165  }
166  void registerField(StatisticFieldInfo *fi) override;
167  void finalizeCurrentStatistic() override;
168 
169  bool isGroup() const override { return false; }
170  void startNewEntry(StatisticBase *stat) override;
171  StatData_u& getFieldLoc(fieldHandle_t fieldHandle) override;
172  void finishEntry() override;
173  };
174 
175  class GroupInfo : public DataSet {
176  struct GroupStat {
177  GroupInfo *gi;
178  std::string statPath;
179 
180  H5::DataSet *dataset;
181  H5::CompType *memType;
182 
183  hsize_t nEntries;
184 
185  std::vector<std::string> registeredFields; /* fi->uniqueName */
186  std::vector<fieldType_t> typeList;
187  std::map<fieldHandle_t, size_t> handleIndexMap;
188 
189  std::vector<StatData_u> currentData;
190  size_t currentCompOffset;
191 
192 
193  GroupStat(GroupInfo *group, StatisticBase *stat);
194  void finalizeRegistration();
195  static std::string getStatName(StatisticBase* stat);
196 
197  void startNewGroupEntry();
198 
199  void startNewEntry(size_t componentIndex, StatisticBase *stat);
200  StatData_u& getFieldLoc(fieldHandle_t fieldHandle);
201  void finishEntry();
202 
203  void finishGroupEntry();
204  };
205 
206 
207 
208  hsize_t nEntries;
209  std::map<std::string, GroupStat> m_statGroups;
210  GroupStat *m_currentStat;
211  StatisticGroup *m_statGroup;
212  std::vector<BaseComponent*> m_components;
213  H5::DataSet *timeDataSet;
214 
215  public:
216  GroupInfo(StatisticGroup *group, H5::H5File *file);
217  void beginGroupRegistration(StatisticGroup *UNUSED(group)) override { }
218  void setCurrentStatistic(StatisticBase *stat) override;
219  void registerField(StatisticFieldInfo *fi) override;
220  void finalizeCurrentStatistic() override;
221  void finalizeGroupRegistration() override;
222 
223  bool isGroup() const override { return true; }
224  void startNewEntry(StatisticBase *stat) override;
225  StatData_u& getFieldLoc(fieldHandle_t fieldHandle) override { return m_currentStat->getFieldLoc(fieldHandle); }
226  void finishEntry() override;
227 
228  void startNewGroupEntry() override;
229  void finishGroupEntry() override;
230  size_t getNumComponents() const { return m_components.size(); }
231 
232  const std::string& getName() const { return m_statGroup->name; }
233  };
234 
235 
236  H5::H5File* m_hFile;
237  DataSet* m_currentDataSet;
238  std::map<StatisticBase*, StatisticInfo*> m_statistics;
239  std::map<std::string, GroupInfo> m_statGroups;
240 
241 
242  StatisticInfo* initStatistic(StatisticBase* statistic);
243  StatisticInfo* getStatisticInfo(StatisticBase* statistic);
244 };
245 
246 } //namespace Statistics
247 } //namespace SST
248 
249 #endif
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:47
fieldHandle_t registerField(const char *fieldName)
Register a field to be output (templated function)
Definition: statoutput.h:85
Forms the base class for statistics gathering within SST.
Definition: statbase.h:61
Definition: action.cc:17
bool acceptsGroups() const override
True if this StatOutput can handle StatisticGroups.
Definition: statoutputhdf5.h:43
void implStartOutputEntries(StatisticBase *statistic) override
Implementation function for the start of output.
Definition: statoutputhdf5.cc:133
void implStopOutputEntries() override
Implementation function for the end of output.
Definition: statoutputhdf5.cc:140
The class for statistics output to a comma separated file.
Definition: statoutputhdf5.h:35
void startOfSimulation() override
Indicate to Statistic Output that simulation started.
Definition: statoutputhdf5.cc:117
Parameter store.
Definition: params.h:45
void printUsage() override
Print out usage for this Statistic Output.
Definition: statoutputhdf5.cc:65
void endOfSimulation() override
Indicate to Statistic Output that simulation ended.
Definition: statoutputhdf5.cc:122
bool checkOutputParameters() override
Perform a check of provided parameters.
Definition: statoutputhdf5.cc:37
void implOutputField(fieldHandle_t fieldHandle, int32_t data) override
Implementation functions for output.
Definition: statoutputhdf5.cc:166
Definition: statgroup.h:29