SST  6.1.0
StructuralSimulationToolkit
statengine.h
1 // Copyright 2009-2016 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-2016, 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_ENGINE
13 #define _H_SST_CORE_STATISTICS_ENGINE
14 
15 #include <sst/core/sst_types.h>
16 #include <sst/core/statapi/statfieldinfo.h>
17 #include <sst/core/unitAlgebra.h>
18 
19 namespace SST {
20 class Component;
21 class Simulation;
22 namespace Statistics {
23 
24 class StatisticBase;
25 
26 /**
27  \class StatisticProcessingEngine
28 
29  An SST core component that handles timing and event processing informing
30  all registered Statistics to generate their outputs at desired rates.
31 */
32 
34 {
35 public:
36  /** Called by the Components and Subcomponent to perform a statistic Output.
37  * @param stat - Pointer to the statistic.
38  * @param EndOfSimFlag - Indicates that the output is occuring at the end of simulation.
39  */
40  void performStatisticOutput(StatisticBase* stat, bool endOfSimFlag = false);
41 
42  /** Called by the Components and Subcomponent to perform a global statistic Output.
43  * This routine will force ALL Components and Subcomponents to output their statistic information.
44  * This may lead to unexpected results if the statistic counts or data is reset on output.
45  * @param endOfSimFlag - Indicates that the output is occurring at the end of simulation.
46  */
47  void performGlobalStatisticOutput(bool endOfSimFlag = false);
48 
49 private:
50  friend class SST::Component;
51  friend class SST::Simulation;
52 
55 
56  bool addPeriodicBasedStatistic(const UnitAlgebra& freq, StatisticBase* Stat);
57  bool addEventBasedStatistic(const UnitAlgebra& count, StatisticBase* Stat);
58  void setStatisticStartTime(const UnitAlgebra& startTime, StatisticBase* Stat);
59  void setStatisticStopTime(const UnitAlgebra& stopTime, StatisticBase* Stat);
60 
61  void endOfSimulation();
62  void startOfSimulation();
63 
64  template<typename T>
65  void registerStatisticWithEngine(const ComponentId_t& compId, StatisticBase* Stat)
66  {
67  if (is_type_same<T, int32_t >::value){return addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::INT32); }
68  if (is_type_same<T, uint32_t >::value){return addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::UINT32);}
69  if (is_type_same<T, int64_t >::value){return addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::INT64); }
70  if (is_type_same<T, uint64_t >::value){return addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::UINT64);}
71  if (is_type_same<T, float >::value){return addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::FLOAT); }
72  if (is_type_same<T, double >::value){return addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::DOUBLE);}
73 
74  // If we get here, this is actually an illegal type
75  addStatisticToCompStatMap(compId, Stat, StatisticFieldInfo::UNDEFINED);
76  }
77 
78  template<typename T>
79  StatisticBase* isStatisticRegisteredWithEngine(const std::string& compName, const ComponentId_t& compId, std::string& statName, std::string& statSubId)
80  {
81  if (is_type_same<T, int32_t >::value){return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::INT32); }
82  if (is_type_same<T, uint32_t >::value){return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::UINT32);}
83  if (is_type_same<T, int64_t >::value){return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::INT64); }
84  if (is_type_same<T, uint64_t >::value){return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::UINT64);}
85  if (is_type_same<T, float >::value){return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::FLOAT); }
86  if (is_type_same<T, double >::value){return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::DOUBLE);}
87 
88  // If we get here, this is actually an illegal type
89  return isStatisticInCompStatMap(compName, compId, statName, statSubId, StatisticFieldInfo::UNDEFINED);
90  }
91 
92 private:
93  void addStatisticClock(const UnitAlgebra& freq, StatisticBase* Stat);
94  TimeConverter* registerClock(const UnitAlgebra& freq, Clock::HandlerBase* handler, int priority);
95  TimeConverter* registerStartOneShot(const UnitAlgebra& startTime, OneShot::HandlerBase* handler, int priority);
96  TimeConverter* registerStopOneShot(const UnitAlgebra& stopTime, OneShot::HandlerBase* handler, int priority);
97  bool handleStatisticEngineClockEvent(Cycle_t CycleNum, SimTime_t timeFactor);
98  void handleStatisticEngineStartTimeEvent(SimTime_t timeFactor);
99  void handleStatisticEngineStopTimeEvent(SimTime_t timeFactor);
100  StatisticBase* isStatisticInCompStatMap(const std::string& compName, const ComponentId_t& compId, std::string& statName, std::string& statSubId, StatisticFieldInfo::fieldType_t fieldType);
101  void addStatisticToCompStatMap(const ComponentId_t& compId, StatisticBase* Stat, StatisticFieldInfo::fieldType_t fieldType);
102 
103 private:
104  typedef std::vector<StatisticBase*> StatArray_t; /*!< Array of Statistics */
105  typedef std::map<SimTime_t, StatArray_t*> StatMap_t; /*!< Map of simtimes to Statistic Arrays */
106  typedef std::map<SimTime_t, Clock*> ClockMap_t; /*!< Map of simtimes to clocks */
107  typedef std::map<SimTime_t, OneShot*> OneShotMap_t; /*!< Map of times to OneShots */
108  typedef std::map<ComponentId_t, StatArray_t*> CompStatMap_t; /*!< Map of ComponentId's to StatInfo Arrays */
109 
110  StatArray_t m_EventStatisticArray; /*!< Array of Event Based Statistics */
111  StatMap_t m_PeriodicStatisticMap; /*!< Map of Array's of Periodic Based Statistics */
112  StatMap_t m_StartTimeMap; /*!< Map of Array's of Statistics that are started at a sim time */
113  StatMap_t m_StopTimeMap; /*!< Map of Array's of Statistics that are stopped at a sim time */
114  ClockMap_t m_ClockMap; /*!< Map of Clocks */
115  OneShotMap_t m_StartTimeOneShotMap; /*!< Map of OneShots for the Statistics start time */
116  OneShotMap_t m_StopTimeOneShotMap; /*!< Map of OneShots for the Statistics stop time */
117  CompStatMap_t m_CompStatMap; /*!< Map of Arrays of Statistics tied to Component Id's */
118  bool m_SimulationStarted; /*!< Flag showing if Simulation has started */
119 
120 };
121 
122 } //namespace Statistics
123 } //namespace SST
124 
125 #endif
Main control class for a SST Simulation.
Definition: simulation.h:75
Definition: statfieldinfo.h:22
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:25
Main component object for the simulation.
Definition: component.h:56
TimeConverter * registerClock(std::string freq, Clock::HandlerBase *handler)
Register a handler to be called on a set frequency.
Definition: simulation.cc:898
void performStatisticOutput(StatisticBase *stat, bool endOfSimFlag=false)
Called by the Components and Subcomponent to perform a statistic Output.
Definition: statengine.cc:141
Forms the base class for statistics gathering within SST.
Definition: statbase.h:36
Definition: action.cc:17
Functor classes for Clock handling.
Definition: clock.h:44
void performGlobalStatisticOutput(bool endOfSimFlag=false)
Called by the Components and Subcomponent to perform a global statistic Output.
Definition: statengine.cc:171
An SST core component that handles timing and event processing informing all registered Statistics to...
Definition: statengine.h:33
Performs Unit math in full precision.
Definition: unitAlgebra.h:112
fieldType_t
Supported Field Types.
Definition: statfieldinfo.h:36
Functor classes for OneShot handling.
Definition: oneshot.h:39