SST  15.1.0
StructuralSimulationToolkit
timeLord.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2025 NTESS. Under the terms
4 // of Contract DE-NA0003525 with NTESS, the U.S.
5 // Government retains certain rights in this software.
6 //
7 // Copyright (c) 2009-2025, NTESS
8 // All rights reserved.
9 //
10 // This file is part of the SST software package. For license
11 // information, see the LICENSE file in the top level directory of the
12 // distribution.
13 
14 #ifndef SST_CORE_TIMELORD_H
15 #define SST_CORE_TIMELORD_H
16 
17 #include "sst/core/sst_types.h"
18 #include "sst/core/threadsafe.h"
19 #include "sst/core/unitAlgebra.h"
20 
21 #include <map>
22 #include <mutex>
23 #include <string>
24 
25 extern int main(int argc, char** argv);
26 
27 namespace SST {
28 
29 class Link;
30 class Simulation;
31 class Simulation_impl;
32 class TimeConverter;
33 class UnitAlgebra;
34 class BaseComponent;
35 
36 /**
37  Class for creating and managing TimeConverter objects
38  */
39 class TimeLord
40 {
41  using TimeConverterMap_t = std::map<SimTime_t, TimeConverter*>;
42  using StringToTCMap_t = std::map<std::string, TimeConverter*>;
43 
44 public:
45  /**
46  Create a new TimeConverter object using specified SI Units. For
47  example, "1 Ghz" (1 Gigahertz), "2.5 ns" (2.5 nanoseconds).
48 
49  @param ts String indicating the base unit for this object. The
50  string should be a floating point number followed by a prefix,
51  and then frequency (i.e. Hz) or time unit (s). Allowable seconds
52  prefixes are: 'f' (fempto), 'p' (pico), 'n' (nano), 'u' (micro),
53  'm' (milli). Allowable frequency prefixes are 'k' (kilo), 'M'
54  (mega), and 'G' (giga).
55  */
56  TimeConverter* getTimeConverter(const std::string& ts);
57  /**
58  * Create a new TimeConverter object using the specified units.
59  *
60  * @param ts UnitAlgebra object indicating the base unit for this object.
61  */
63 
64  /**
65  * @return Time Base of the TimeLord
66  */
67  UnitAlgebra getTimeBase() const { return timeBase; }
68 
69  /** @return TimeConverter which represents Nanoseconds */
70  TimeConverter* getNano() { return nano; }
71  /** @return TimeConverter which represents Microseconds */
72  TimeConverter* getMicro() { return micro; }
73  /** @return TimeConverter which represents Milliseconds */
74  TimeConverter* getMilli() { return milli; }
75 
76  /** Not a Public API.
77  * Returns the number of raw simulation cycles given by a specified time string
78  */
79  SimTime_t getSimCycles(const std::string& timeString, const std::string& where);
80 
81 private:
82  friend class SST::Simulation;
83  friend class SST::Simulation_impl;
84  friend class SST::Link;
85  friend class SST::BaseComponent;
86 
87  friend int ::main(int argc, char** argv);
88 
89  void init(const std::string& timeBaseString);
90 
91  // Needed by the simulator to turn minPart back into a
92  // TimeConverter object.
93  TimeConverter* getTimeConverter(SimTime_t simCycles);
94 
95  TimeLord() :
96  initialized(false)
97  {}
98  ~TimeLord();
99 
100  TimeLord(const TimeLord&) = delete; // Don't Implement
101  TimeLord& operator=(const TimeLord&) = delete; // Don't Implement
102 
103  bool initialized;
104  std::recursive_mutex slock;
105 
106  std::string timeBaseString;
107  TimeConverterMap_t tcMap;
108  UnitAlgebra timeBase;
109 
110  // double sec_factor;
111  StringToTCMap_t parseCache;
112 
113  TimeConverter* nano;
114  TimeConverter* micro;
115  TimeConverter* milli;
116 };
117 
118 } // namespace SST
119 
120 #endif // SST_CORE_TIMELORD_H
TimeConverter * getTimeConverter(const std::string &ts)
Create a new TimeConverter object using specified SI Units.
Definition: timeLord.cc:33
UnitAlgebra getTimeBase() const
Definition: timeLord.h:67
A class to convert between a component&#39;s view of time and the core&#39;s view of time.
Definition: timeConverter.h:27
SimTime_t getSimCycles(const std::string &timeString, const std::string &where)
Not a Public API.
Definition: timeLord.cc:166
TimeConverter * getNano()
Definition: timeLord.h:70
Definition: action.cc:18
TimeConverter * getMicro()
Definition: timeLord.h:72
TimeConverter * getMilli()
Definition: timeLord.h:74
Main control class for a SST Simulation.
Definition: simulation_impl.h:122
Main component object for the simulation.
Definition: baseComponent.h:64
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:39
Performs Unit math in full precision.
Definition: unitAlgebra.h:105
virtual void init(unsigned int UNUSED(phase))
Used during the init phase.
Definition: baseComponent.h:110