SST/macro
api.h
Go to the documentation of this file.
1 #ifndef sstmac_software_libraries_API_H
2 #define sstmac_software_libraries_API_H
3 
8 
10 
11 # if (defined(__MACH__) && defined(__APPLE__))
12 # define _MAC
13 #endif
14 
15 # if defined(_MAC)
16 # include <mach/mach_time.h>
17 # else
18 # include <time.h>
19 # endif
20 
21 #if defined(_MAC)
22 typedef uint64_t my_timer_t;
23 typedef double timer_c;
24 #else
25 typedef double my_timer_t;
26 typedef timespec timer_c;
27 #endif
28 
29 namespace sstmac {
30 namespace sw {
31 
32 //==============================================================================
33 // Timer
34 // A quick class to do benchmarking.
35 // Example: Timer t; t.tic(); SomeSlowOp(); t.toc("Some Message");
36 
37 class Timer
38 {
39  public:
40  Timer();
41 
42  inline void
43  tic();
44  inline void
45  toc();
46 
47  void
48  reset();
49  double
50  getTime();
51 
52  private:
54  double duration;
56  double conv_factor;
57  double elapsed_time;
58 };
59 
60 class api :
61  public library,
62  virtual public sprockit::factory_type
63 {
64  public:
65  api(const char* name,
66  software_id sid,
67  const key::category& ty) :
68  api(name, sid)
69  {
70  key_cat_ = ty;
71  }
72 
73  virtual void finalize_init(){}
74 
75  api(const char* name,
76  software_id sid) :
77  library(name, sid),
78  startcount_(0),
79  endcount_(0)
80  {
81  }
82 
83  virtual
84  ~api() {
85  if (hostcompute_) {
86  delete timer_;
87  }
88  }
89 
90  virtual void
91  init(){}
92 
93  virtual void
95 
96  virtual void
97  init_os(operating_system* os);
98 
99  timestamp
100  now() const;
101 
102  void
103  schedule(timestamp t, event_queue_entry* ev);
104 
105  void
106  schedule_delay(timestamp t, event_queue_entry* ev);
107 
108  virtual void
109  init_factory_params(sprockit::sim_parameters *params);
110 
111  //these can be used for direct execution compute modeling
112  virtual void
113  start_api_call();
114 
115  virtual void
116  end_api_call();
117 
118  protected:
122  long endcount_;
124 
125 };
126 
127 void api_lock();
128 void api_unlock();
129 
130 #define ImplementAPI(x) \
131  public: \
132  static const char* api_name;
133 
134 #define RegisterAPI(name, child_cls) \
135  SpktRegister(name, sstmac::sw::api, child_cls); \
136  const char* child_cls::api_name = name
137 
138 DeclareFactory(api,software_id);
139 
140 }
141 }
142 
143 #endif // API_H
144 
timer_c ts
Definition: api.h:55
double elapsed_time
Definition: api.h:57
void api_unlock()
virtual ~api()
Definition: api.h:84
virtual void init()
Definition: api.h:91
my_timer_t start
Definition: api.h:53
lib_compute_time * compute_
Definition: api.h:123
virtual void finalize_init()
Definition: api.h:73
api(const char *name, software_id sid, const key::category &ty)
Definition: api.h:65
api(const char *name, software_id sid)
Definition: api.h:75
double my_timer_t
Definition: api.h:25
long startcount_
Definition: api.h:121
virtual void finalize()
Definition: api.h:94
bool hostcompute_
Definition: api.h:119
A basic container for time (subject to future transplant).
Definition: timestamp.h:29
timespec timer_c
Definition: api.h:26
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
DeclareFactory(blas_kernel)
double conv_factor
Definition: api.h:56
Timer * timer_
Definition: api.h:120
double duration
Definition: api.h:54
Definition: sst_event.h:67
long endcount_
Definition: api.h:122
A wrapper for an appid, taskid pair.
Definition: software_id.h:28
void api_lock()