SST/macro
event_scheduler.h
Go to the documentation of this file.
1 /*
2  * This file is part of SST/macroscale:
3  * The macroscale architecture simulator from the SST suite.
4  * Copyright (c) 2009 Sandia Corporation.
5  * This software is distributed under the BSD License.
6  * Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
7  * the U.S. Government retains certain rights in this software.
8  * For more information, see the LICENSE file in the top
9  * SST/macroscale directory.
10  */
11 
12 #ifndef SSTMAC_COMMON_event_scheduler_H_INCLUDED
13 #define SSTMAC_COMMON_event_scheduler_H_INCLUDED
14 
22 
23 #if SSTMAC_INTEGRATED_SST_CORE
25 #include <sst/core/link.h>
26 # define DeclareIntegratedComponent(comp) \
27  SST::Component* \
28  create_##comp(SST::ComponentId_t id, SST::Params& params); \
29  extern const SST::ElementInfoComponent comp##_element_info;
30 # define ImplementIntegratedComponent(comp) \
31  SST::Component* \
32  create_##comp(SST::ComponentId_t id, SST::Params& params) { \
33  return new comp(id, params); \
34  } \
35  const SST::ElementInfoComponent comp##_element_info = { \
36  #comp, \
37  "undocumented (for now) SST/macro integrated component.", \
38  NULL, \
39  create_##comp, NULL, NULL, COMPONENT_CATEGORY_SYSTEM \
40  };
41 #else
42 # define DeclareIntegratedComponent(comp)
43 # define ImplementIntegratedComponent(comp)
45 #endif
46 
47 namespace sstmac {
48 
49 /**
50  * The interface for something that can schedule messages
51  */
53 #if SSTMAC_INTEGRATED_SST_CORE
55 #endif
56  public event_handler
57 {
58 
59  public:
60  virtual
62  }
63 
64  virtual std::string
65  to_string() const {
66  return "event scheduler";
67  }
68 
69  virtual void
70  handle(event* ev);
71 
72  void
74 
75  /**
76  * @brief ipc_schedule Should only be called on stub handlers for which handler->ipc_handler() returns true
77  * @param t The time the event will run at
78  * @param handler The handler to receive the event. This should always be a stub for a real handler on a remote process.
79  * @param ev The event to deliver
80  */
81  void
83  event_handler* handler,
84  event* ev);
85 
86  /**
87  * Add an event to the event queue, where msg will get delivered to handler at time t.
88  * @param t Time at which the event should happen
89  * @param handler The handler for the event
90  * @param msg The message to deliver to the handler
91  */
92  void
94  event_handler* handler,
95  event* ev);
96 
97  void
99 
100  void
102 
103  void
104  schedule_now(event_handler* handler, event* ev);
105 
106  void
108  event_handler* handler,
109  event* ev);
110  void
112 
113  void
114  send_self_event(timestamp arrival, event* ev);
115 
116  void
118 
119  void
121 
122  void
124 
125  void
127 
128  void
130 
131  void
133 
134 #ifdef INTEGRATED_SST_CORE_CHECK
135  public:
136  void
137  set_correctly_scheduled(bool flag) {
138  correctly_scheduled_ = flag;
139  }
140  protected:
141  bool correctly_scheduled_;
142 #endif
143 
144 
145 #if SSTMAC_INTEGRATED_SST_CORE
146  public:
148  SST::ComponentId_t id,
149  SST::Params& params) : SSTIntegratedComponent(id, params)
150  {
151  global = this;
152  }
153 
154  virtual void
156 
157  timestamp
158  now() const;
159 
160  virtual void
161  init(unsigned int phase);
162 
163  static event_scheduler* global;
164 
165  private:
166  void
167  schedule(SST::Time_t delay, event_handler* handler, event* ev);
168 
169 #else
170  public:
171  /**
172  * Set the eventmanager for this scheduler. Unfortunately,
173  * this always has to be called after an event_scheduler is constructed.
174  * @param m the simulation eventmanager
175  */
176  virtual void
178 
180  event_mgr() const {
181  return eventman_;
182  }
183 
184  /**
185  * get the current time
186  * @return a timestamp
187  */
188  timestamp
189  now() const {
190  return eventman_->now();
191  }
192 
193  int
194  nthread() const {
195  return eventman_->nthread();
196  }
197 
198  protected:
199  event_scheduler();
200 
201  uint32_t seqnum_;
202 
203  private:
204  void sanity_check(timestamp t);
205 
206  void
207  multithread_schedule(int src_thread, int dst_thread,
209 
210  private:
212 #endif
213 
214 };
215 
217  public event_handler
218 {
219  public:
220  event_subscheduler() : parent_(0){}
221  /**
222  * get the current time
223  * @return a timestamp
224  */
225  timestamp now() const {
226  return parent_->now();
227  }
228 
229  virtual std::string
230  to_string() const {
231  return "event subscheduler";
232  }
233 
234  virtual void
235  handle(event* ev);
236 
237  /**
238  * Add an event to the event queue, where msg will get delivered to handler at time t.
239  * @param t Time at which the event should happen
240  * @param handler The handler for the event
241  * @param msg The message to deliver to the handler
242  */
243  void
245  event_handler* handler,
246  event* ev);
247 
248  void
250 
251  void
253 
254  void
255  schedule_now(event_handler* handler, event* ev);
256 
257  void
259  event_handler* handler,
260  event* ev);
261  void
263 
264  void
265  send_self_event(timestamp arrival, event* ev);
266 
267  void
269 
270  void
272 
273  void
275 
276  void
278 
279  void
281 
282  /**
283  * Set the eventmanager for this scheduler. Unfortunately,
284  * this always has to be called after an event_scheduler is constructed.
285  * @param m the simulation eventmanager
286  */
287  virtual void
289  parent_ = m;
290  init_thread_id(parent_->thread_id());
291  init_loc_id(parent_->event_location());
292  }
293 
295  parent() const {
296  return parent_;
297  }
298 
299  protected:
301  };
302 
303 
304 } // end of namespace sstmac
305 #endif
306 
307 
timestamp now() const
Definition: event_manager.h:87
timestamp now() const
get the current time
void schedule_now(event_queue_entry *ev)
virtual std::string to_string() const
virtual void set_event_parent(event_scheduler *m)
Set the eventmanager for this scheduler.
void ipc_schedule(timestamp t, event_handler *handler, event *ev)
ipc_schedule Should only be called on stub handlers for which handler->ipc_handler() returns true ...
void init_thread_id(int id)
Definition: event_handler.h:95
void multithread_schedule(int src_thread, int dst_thread, timestamp t, event_queue_entry *ev)
A type of logger that collects some kind of statistic and outputs to a file during or at the end of a...
Base type for implementations of an engine that is able to schedule events and advance simulation tim...
Definition: event_manager.h:47
void send_delayed_self_event_queue(timestamp delay, event_queue_entry *ev)
void init_loc_id(event_loc_id id)
Definition: event_handler.h:90
void send_now_self_event(event *ev)
virtual std::string to_string() const
void sanity_check(timestamp t)
event_scheduler * parent() const
The main interface for something that can respond to an event (sst_message).
Definition: event_handler.h:24
A basic container for time (subject to future transplant).
Definition: timestamp.h:29
void send_self_event(timestamp arrival, event *ev)
parallel_runtime * init()
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
virtual void set_event_manager(event_manager *m)
Set the eventmanager for this scheduler.
void send_now_self_event_queue(event_queue_entry *ev)
The interface for something that can schedule messages.
void send_delayed_self_event(timestamp delay, event *ev)
timestamp now() const
get the current time
event_manager * event_mgr() const
void send_self_event_queue(timestamp arrival, event_queue_entry *ev)
void register_stat(stat_collector *coll)
virtual void handle(event *ev)
event_manager * eventman_
void schedule(timestamp t, event_handler *handler, event *ev)
Add an event to the event queue, where msg will get delivered to handler at time t.
void schedule_delay(timestamp delay, event_handler *handler, event *ev)
Definition: sst_event.h:67