SST 12.1.0
Structural Simulation Toolkit
timeLord.h
1// -*- c++ -*-
2
3// Copyright 2009-2022 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-2022, 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
24extern int main(int argc, char** argv);
25
26namespace SST {
27
28class Link;
29class Simulation;
30class Simulation_impl;
31class TimeConverter;
32class 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
42public:
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 the Time Base of the TimeLord
64 */
65 UnitAlgebra getTimeBase() const { return timeBase; }
66
67 /** Return a TimeConverter which represents Nanoseconds */
68 TimeConverter* getNano() { return nano; }
69 /** Return a TimeConverter which represents Microseconds */
70 TimeConverter* getMicro() { return micro; }
71 /** Return a 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
80private:
81 friend class SST::Simulation;
82 friend class SST::Simulation_impl;
83 friend class SST::Link;
84
85 friend int ::main(int argc, char** argv);
86
87 void init(const std::string& timeBaseString);
88
89 // Needed by the simulator to turn minPart back into a
90 // TimeConverter object.
91 TimeConverter* getTimeConverter(SimTime_t simCycles);
92
93 TimeLord() : initialized(false) {}
94 ~TimeLord();
95
96 TimeLord(TimeLord const&); // Don't Implement
97 void operator=(TimeLord const&); // Don't Implement
98
99 bool initialized;
100 std::recursive_mutex slock;
101
102 // Variables that need to be saved when serialized
103 std::string timeBaseString;
104 TimeConverterMap_t tcMap;
105 UnitAlgebra timeBase;
106
107 // double sec_factor;
108 StringToTCMap_t parseCache;
109
110 TimeConverter* nano;
111 TimeConverter* micro;
112 TimeConverter* milli;
113};
114
115} // namespace SST
116
117#endif // SST_CORE_TIMELORD_H
Main control class for a SST Simulation.
Definition: simulation_impl.h:77
Main control class for a SST Simulation.
Definition: simulation.h:35
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:27
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:38
TimeConverter * getNano()
Return a TimeConverter which represents Nanoseconds.
Definition: timeLord.h:68
TimeConverter * getMicro()
Return a TimeConverter which represents Microseconds.
Definition: timeLord.h:70
TimeConverter * getTimeConverter(const std::string &ts)
Create a new TimeConverter object using specified SI Units.
Definition: timeLord.cc:31
SimTime_t getSimCycles(const std::string &timeString, const std::string &where)
Not a Public API.
Definition: timeLord.cc:165
TimeConverter * getMilli()
Return a TimeConverter which represents Milliseconds.
Definition: timeLord.h:72
UnitAlgebra getTimeBase() const
Return the Time Base of the TimeLord.
Definition: timeLord.h:65
Performs Unit math in full precision.
Definition: unitAlgebra.h:109