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