SST  14.0.0
StructuralSimulationToolkit
timeLord.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2024 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-2024, 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 <string>
23 
24 extern int main(int argc, char** argv);
25 
26 namespace SST {
27 
28 class Link;
29 class Simulation;
30 class Simulation_impl;
31 class TimeConverter;
32 class UnitAlgebra;
33 
34 /**
35  Class for creating and managing TimeConverter objects
36  */
38 {
39  typedef std::map<SimTime_t, TimeConverter*> TimeConverterMap_t;
40  typedef std::map<std::string, TimeConverter*> StringToTCMap_t;
41 
42 public:
43  /**
44  Create a new TimeConverter object using specified SI Units. For
45  example, "1 Ghz" (1 Gigahertz), "2.5 ns" (2.5 nanoseconds).
46 
47  @param ts String indicating the base unit for this object. The
48  string should be a floating point number followed by a prefix,
49  and then frequency (i.e. Hz) or time unit (s). Allowable seconds
50  prefixes are: 'f' (fempto), 'p' (pico), 'n' (nano), 'u' (micro),
51  'm' (milli). Allowable frequency prefixes are 'k' (kilo), 'M'
52  (mega), and 'G' (giga).
53  */
54  TimeConverter* getTimeConverter(const std::string& ts);
55  /**
56  * Create a new TimeConverter object using the specified units.
57  *
58  * @param ts UnitAlgebra object indicating the base unit for this object.
59  */
61 
62  /**
63  * @return Time Base of the TimeLord
64  */
65  UnitAlgebra getTimeBase() const { return timeBase; }
66 
67  /** @return TimeConverter which represents Nanoseconds */
68  TimeConverter* getNano() { return nano; }
69  /** @return TimeConverter which represents Microseconds */
70  TimeConverter* getMicro() { return micro; }
71  /** @return TimeConverter which represents Milliseconds */
72  TimeConverter* getMilli() { return milli; }
73 
74  /** Not a Public API.
75  * Returns the number of raw simulation cycles given by a specified time string
76  */
77  SimTime_t getSimCycles(const std::string& timeString, const std::string& where);
78 
79  void serialize_order(SST::Core::Serialization::serializer& ser) override;
80  ImplementSerializable(SST::TimeLord)
81 
82 private:
83  friend class SST::Simulation;
84  friend class SST::Simulation_impl;
85  friend class SST::Link;
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() : initialized(false) {}
96  ~TimeLord();
97 
98  TimeLord(TimeLord const&); // Don't Implement
99  void operator=(TimeLord const&); // Don't Implement
100 
101  bool initialized;
102  std::recursive_mutex slock;
103 
104  // Variables that need to be saved when serialized
105  std::string timeBaseString;
106  TimeConverterMap_t tcMap;
107  UnitAlgebra timeBase;
108 
109  // double sec_factor;
110  StringToTCMap_t parseCache;
111 
112  TimeConverter* nano;
113  TimeConverter* micro;
114  TimeConverter* milli;
115 };
116 
117 } // namespace SST
118 
119 #endif // SST_CORE_TIMELORD_H
TimeConverter * getTimeConverter(const std::string &ts)
Create a new TimeConverter object using specified SI Units.
Definition: timeLord.cc:33
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
UnitAlgebra getTimeBase() const
Definition: timeLord.h:65
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:167
TimeConverter * getNano()
Definition: timeLord.h:68
Definition: action.cc:18
Definition: serializable.h:118
TimeConverter * getMicro()
Definition: timeLord.h:70
TimeConverter * getMilli()
Definition: timeLord.h:72
Main control class for a SST Simulation.
Definition: simulation_impl.h:70
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:37
Performs Unit math in full precision.
Definition: unitAlgebra.h:106