SST 16.0.0
Structural Simulation Toolkit
timeLord.h
1// -*- c++ -*-
2
3// Copyright 2009-2026 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-2026, 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/timeConverter.h"
20#include "sst/core/unitAlgebra.h"
21
22#include <map>
23#include <mutex>
24#include <string>
25
26extern int main(int argc, char** argv);
27
28namespace SST {
29
30class Link;
31class Simulation;
32class Simulation;
33class TimeConverter;
34class UnitAlgebra;
35class BaseComponent;
36
37/**
38 Class for creating and managing TimeConverter objects
39 */
40class TimeLord
41{
42 using StringToTCMap_t = std::map<std::string, TimeConverter>;
43
44public:
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' (femto), '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 /**
59 Create a new TimeConverter object using the specified units.
60
61 @param ts UnitAlgebra object indicating the base unit for this object.
62 */
63 TimeConverter getTimeConverter(const UnitAlgebra& ts);
64
65 /**
66 Get the global TimeBase as a UnitAlgebra
67
68 @return Timebase of the TimeLord
69 */
70 UnitAlgebra getTimeBase() const { return timebase_; }
71
72 /**
73 Get the TimeConverter representing a nanosecond
74
75 @return TimeConverter which represents Nanoseconds
76 */
77 TimeConverter getNano() { return nano_; }
78
79 /**
80 Get the TimeConverter representing a microsecond
81
82 @return TimeConverter which represents Microseconds
83 */
84 TimeConverter getMicro() { return micro_; }
85
86 /**
87 Get the TimeConverter representing a millisecond
88
89 @return TimeConverter which represents Milliseconds
90 */
91 TimeConverter getMilli() { return milli_; }
92
93 /**
94 Not a Public API.
95
96 Returns the number of raw simulation cycles given by a specified time string
97 */
98 SimTime_t getSimCycles(const std::string& timeString, const std::string& where);
99
100private:
101 friend class SST::Simulation;
102 friend class SST::Simulation;
103 friend class SST::Link;
104 friend class SST::BaseComponent;
105 friend class SST::TimeConverter;
106
107 friend int ::main(int argc, char** argv);
108
109 void init(const std::string& timebase_string);
110
111 // Needed by the simulator to turn minPart back into a
112 // TimeConverter object.
113 TimeConverter getTimeConverter(SimTime_t simCycles);
114
115 SimTime_t getFactorForTime(const std::string& time);
116 SimTime_t getFactorForTime(const UnitAlgebra& time);
117
118 TimeLord() :
119 initialized_(false)
120 {}
121 ~TimeLord();
122
123 TimeLord(const TimeLord&) = delete; // Don't Implement
124 TimeLord& operator=(const TimeLord&) = delete; // Don't Implement
125
126 bool initialized_;
127 std::recursive_mutex slock_;
128
129 std::string timebase_string_;
130 // TimeConverterMap_t tc_map_;
131 UnitAlgebra timebase_;
132
133 // double sec_factor;
134 StringToTCMap_t parse_cache_;
135
136 TimeConverter nano_;
137 TimeConverter micro_;
138 TimeConverter milli_;
139};
140
141} // namespace SST
142
143#endif // SST_CORE_TIMELORD_H
Main component object for the simulation.
Definition baseComponent.h:67
Main control class for a SST Simulation.
Definition simulation.h:121
A class to convert between a component's view of time and the core's view of time.
Definition timeConverter.h:31
Class for creating and managing TimeConverter objects.
Definition timeLord.h:41
TimeConverter getTimeConverter(const std::string &ts)
Create a new TimeConverter object using specified SI Units.
Definition timeLord.cc:34
TimeConverter getMilli()
Get the TimeConverter representing a millisecond.
Definition timeLord.h:91
TimeConverter getMicro()
Get the TimeConverter representing a microsecond.
Definition timeLord.h:84
TimeConverter getNano()
Get the TimeConverter representing a nanosecond.
Definition timeLord.h:77
SimTime_t getSimCycles(const std::string &timeString, const std::string &where)
Not a Public API.
Definition timeLord.cc:106
UnitAlgebra getTimeBase() const
Get the global TimeBase as a UnitAlgebra.
Definition timeLord.h:70
Performs Unit math in full precision.
Definition unitAlgebra.h:107