SST  6.1.0
StructuralSimulationToolkit
introspector.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 SST_CORE_INTROSPECTOR_H
13 #define SST_CORE_INTROSPECTOR_H
14 
15 #include "sst/core/clock.h"
16 #include "sst/core/introspectedComponent.h"
17 //#include "sst/core/simulation.h"
18 //#include "sst/core/timeConverter.h"
19 
20 namespace SST {
21 
22 #if DBG_INTROSPECTOR
23 #define _INTROSPECTOR_DBG( fmt, args...) \
24  printf( "%d:Introspector::%s():%d: " fmt, _debug_rank, __FUNCTION__,__LINE__, ## args )
25 #else
26 #define _INTROSPECTOR_DBG( fmt, args...)
27 #endif
28 
29 
30 /**
31  * Main introspector object for the simulation.
32  * All models inherit from this.
33  * Introspection interface is a unified way to gather statistics and arbitrary data from components.
34  */
35 
36 class Introspector {
37 public:
38 
39  /** Types of boost MPI collective operations that introspector can perform.*/
40  enum collect_type { GATHER, ALLGATHER, BROADCAST, REDUCE, ALLREDUCE};
41  /** Types of funciton objects for the reduce collective.*/
43  MINIMUM,
44  MAXIMUM,
45  SUM,
46  NOT_APPLICABLE
47  };
48 
49  /** Constructor. Generally only called by the factory class.
50  @param id Unique introspector ID*/
51  Introspector();
52  virtual ~Introspector() {}
53 
54  /** Called after all components/introspectors have been constructed, but before
55  simulation time has begun. */
56  virtual void setup( ) { }
57  /** Called after simulation completes, but before objects are
58  destroyed. A good place to print out statistics. */
59  virtual void finish( ) { }
60 
61  /** Get component of a certain type indicated by CompName on this rank.
62  Name is unique so the fuction actually returns a list with only one component.
63  This function is usually used in Introspector::setup().
64  @param CompName Component's name*/
65  std::list<IntrospectedComponent*> getModelsByName(const std::string CompName);
66  /** Get component of a certain type indicated by CompType on this rank.
67  If CompType is blank, a list of all local components is returned.
68  This function is usually used in Introspector::setup().
69  @param CompType Component's type*/
70  std::list<IntrospectedComponent*> getModelsByType(const std::string CompType);
71 
72  /** Query the components indicated by "c" to retrieve components' statistics & data.
73  Return the value of the data indicated by "dataname".
74  The function is usually called by introspector-pull mechanism in Introspector::triggeredUpdate().
75  @param c Pointer to the component
76  @param dataname Name of the data */
77  template <typename typeT>
78  typeT getData(IntrospectedComponent* c, std::string dataname);
79  /** Introspector-writers will implement their own triggeredUpdate function.
80  This function calls Introspector::getData() to retrieve components' data,
81  and is a good place to manipulate the data
82  (print to screen, MPI collective communication, etc). */
83  virtual bool triggeredUpdate() { return false; }
84 
85 
86  /** Introspectors communicate among themselves with Boost MPI to exchange their integer data, invalue.
87  This function initiates a specific type of collective communicaiton indicated by ctype. The data
88  are operated based on ctype and on the MPI operation, op. An introspector type can have periodic
89  collective communication by calling this function in a member function registered with an event handler that is
90  triggered by a clock.
91  @param ctype Types of collective communication. Currently supported options are Broadcast, (all)gather,
92  and (all)reduce
93  @param invalue The local value to be communicated
94  @param op Types of the MPI operations for the (all)reduce algorithm to combine the values. Currently
95  supported options are summarize, minimum and maximum. Default is set to none
96  @param rank The rank where the introspector resides. Default is set to 0. If ctype is broadcast,
97  rank here indicates the rank that will transmitting the value*/
98  void collectInt(collect_type ctype, uint64_t invalue, mpi_operation op=NOT_APPLICABLE, int rank=0);
99  /** One time introspectors collective communication. The event handling functors that calls a given member
100  communication function is inserted into the queue and will be triggered at time specified by, time.
101  The introspector-write implements their own communication function if they want something other than
102  the basic collective operations, broadcast, (all)reduce and (all)gather.
103  @param time The simulation time when the introspectors will communicate among themselves
104  @param functor Event handling functor that invokes member communication function*/
105  void oneTimeCollect(SimTime_t time, Event::HandlerBase* functor);
106 
107 
108  /** List of components that this introspector is monitoring.*/
109  std::list<IntrospectedComponent*> MyCompList;
110  /** Minimum value of the integer values collected from all introspectors by Introspector::collectInt().*/
111  uint64_t minvalue;
112  /** Maximum value of the integer values collected from all introspectors by Introspector::collectInt().*/
113  uint64_t maxvalue;
114  /** Result value of the reduction operation in Introspector::collectInt().*/
115  uint64_t value;
116  /** Data vector that holds data collected from all introspectors by Introspector::collectInt().*/
117  /* std::vector<uint64_t> arrayvalue; */
118  uint64_t* arrayvalue;
119 
120  /** Registers a clock for this component.
121  @param freq Frequency for the clock in SI units
122  @param handler Pointer to Clock::HandlerBase which is to be invoked
123  at the specified interval
124  @param regAll Should this clock perioud be used as the default
125  time base for all of the links connected to this component
126  */
127  TimeConverter* registerClock( std::string freq, Clock::HandlerBase* handler);
128  void unregisterClock(TimeConverter *tc, Clock::HandlerBase* handler);
129 
130  SimTime_t getFreq() {return defaultTimeBase->getFactor();}
131 
132 protected:
133  /** Timebase used if no other timebase is specified for calls like
134  Component::getCurrentSimTime(). Often set by Component::registerClock()
135  function */
137 
138 private:
139 };
140 
141 template <typename typeT>
142 typeT Introspector::getData(IntrospectedComponent* c, std::string dataname)
143 {
145  std::pair<bool, IntrospectedComponent::MonitorBase*> p;
146 
147  p = c->getMonitor(dataname);
148 
149  //check if the component cares about this data
150  if (p.first){
151  monitor = p.second;
152  return any_cast<typeT>( (*monitor)());
153  }
154  else
155  return (-9999); //return an unreasonable number for now
156 }
157 
158 } // namespace SST
159 
160 #endif // SST_CORE_INTROSPECTOR_H
uint64_t minvalue
Minimum value of the integer values collected from all introspectors by Introspector::collectInt().
Definition: introspector.h:111
TimeConverter * defaultTimeBase
Timebase used if no other timebase is specified for calls like Component::getCurrentSimTime().
Definition: introspector.h:136
SimTime_t getFactor()
Return the factor used for conversions with Core Time.
Definition: timeConverter.h:50
std::pair< bool, IntrospectedComponent::MonitorBase * > getMonitor(std::string dataname)
Find monitor indicated by "dataname" from the map.
Definition: introspectedComponent.cc:142
mpi_operation
Types of funciton objects for the reduce collective.
Definition: introspector.h:42
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:25
virtual void setup()
Called after all components/introspectors have been constructed, but before simulation time has begun...
Definition: introspector.h:56
void oneTimeCollect(SimTime_t time, Event::HandlerBase *functor)
One time introspectors collective communication.
Definition: introspector.cc:191
virtual bool triggeredUpdate()
Introspector-writers will implement their own triggeredUpdate function.
Definition: introspector.h:83
Definition: action.cc:17
uint64_t maxvalue
Maximum value of the integer values collected from all introspectors by Introspector::collectInt().
Definition: introspector.h:113
typeT getData(IntrospectedComponent *c, std::string dataname)
Query the components indicated by "c" to retrieve components' statistics & data.
Definition: introspector.h:142
Definition: introspectedComponent.h:152
uint64_t value
Result value of the reduction operation in Introspector::collectInt().
Definition: introspector.h:115
Main component object for the simulation.
Definition: introspectedComponent.h:122
uint64_t * arrayvalue
Data vector that holds data collected from all introspectors by Introspector::collectInt().
Definition: introspector.h:118
Main introspector object for the simulation.
Definition: introspector.h:36
Functor classes for Clock handling.
Definition: clock.h:44
std::list< IntrospectedComponent * > MyCompList
List of components that this introspector is monitoring.
Definition: introspector.h:109
std::list< IntrospectedComponent * > getModelsByName(const std::string CompName)
Get component of a certain type indicated by CompName on this rank.
Definition: introspector.cc:46
void collectInt(collect_type ctype, uint64_t invalue, mpi_operation op=NOT_APPLICABLE, int rank=0)
Introspectors communicate among themselves with Boost MPI to exchange their integer data...
Definition: introspector.cc:75
std::list< IntrospectedComponent * > getModelsByType(const std::string CompType)
Get component of a certain type indicated by CompType on this rank.
Definition: introspector.cc:58
TimeConverter * registerClock(std::string freq, Clock::HandlerBase *handler)
Registers a clock for this component.
Definition: introspector.cc:39
Functor classes for Event handling.
Definition: event.h:86
virtual void finish()
Called after simulation completes, but before objects are destroyed.
Definition: introspector.h:59
Introspector()
Constructor.
Definition: introspector.cc:29
collect_type
Types of boost MPI collective operations that introspector can perform.
Definition: introspector.h:40