SST/macro
event_manager.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_EVENTMANAGER_H_INCLUDED
13 #define SSTMAC_COMMON_EVENTMANAGER_H_INCLUDED
14 
17 
24 #include <sprockit/debug.h>
25 
31 
32 #include <vector>
33 
34 
35 DeclareDebugSlot(event_manager);
36 
37 namespace sstmac {
38 
39 #if SSTMAC_INTEGRATED_SST_CORE
40 #else
41 /**
42  * Base type for implementations of an engine that
43  * is able to schedule events and advance simulation time
44  * in the right order.
45  */
46 
49 {
50  friend class event_scheduler;
51  friend class native::manager;
52  friend class native::macro_manager;
53 
54  public:
55  virtual std::string
56  to_string() const {
57  return "event manager";
58  }
59 
60  bool
62  return complete_;
63  }
64 
65  virtual void
66  init_factory_params(sprockit::sim_parameters* params);
67 
69 
70  /// Goodbye.
71  virtual ~event_manager();
72 
73  /// Clear all events and set time back to a zero of your choice.
74  /// This call shall not be permitted while the event manager is running.
75  virtual void
76  clear(timestamp zero_time = timestamp(0)) = 0;
77 
78  /// Run the eventmanager.
79  /// The eventmanager shall return control when no more messages remain.
80  virtual void
81  run() = 0;
82 
83  virtual bool
84  empty() const = 0;
85 
86  timestamp
87  now() const {
88  return now_;
89  }
90 
91  void
93  stat_collector* stat,
94  bool reduce_all = true,
95  bool dump_all = false,
96  bool dump_main = true);
97 
100  stat_collector* stat,
101  bool reduce_all = true,
102  bool dump_all = false,
103  bool dump_main = true);
104 
105  virtual void
106  cancel_all_messages(event_loc_id canceled_loc) = 0;
107 
108  partition*
109  topology_partition() const;
110 
112  runtime() const;
113 
114  void
115  finish_stats();
116 
117  virtual void
118  finish_stats(stat_collector* main, const std::string& name, timestamp end);
119 
120  void
121  stop() {
122  stopped_ = true;
123  }
124 
125  /**
126  * @return The MPI rank of this event manager
127  * */
128  int
129  me() const {
130  return me_;
131  }
132 
133  /**
134  * @return The unique worker id amongst all threads on all ranks
135  */
136  int
137  worker_id() const {
138  return me_ * nthread_ + thread_id_;
139  }
140 
141  int
142  nproc() const {
143  return nproc_;
144  }
145 
146  int
147  nworker() const {
148  return nproc_ * nthread_;
149  }
150 
151 
152  // ---- These are interface functions for PDES, they should
153  // ---- only get called when running in parallel mode
154  virtual void
155  ipc_schedule(
156  timestamp t,
157  event_loc_id dst,
158  event_loc_id src,
159  uint32_t seqnum,
160  event* ev);
161 
162  virtual void
164  int srcthread,
165  int dstthread,
166  uint32_t seqnum,
167  event_queue_entry* ev);
168 
169  virtual int
170  lpid() const {
171  return -1;
172  }
173 
174  int
175  thread_id() const {
176  return thread_id_;
177  }
178 
179  int
180  nthread() const {
181  return nthread_;
182  }
183 
184  virtual event_manager*
185  ev_man_for_thread(int thread_id) const;
186 
187  virtual void
188  set_interconnect(hw::interconnect* interconn);
189 
190  static int
192 
193  virtual void
194  schedule_stop(timestamp until);
195 
196  protected:
198  rt_(rt),
199  finish_on_stop_(true),
200  stopped_(true),
201  thread_id_(0),
202  nthread_(1),
203  me_(0),
204  nproc_(1),
205  complete_(false)
206  {}
207 
208  void
209  set_now(const timestamp &ts);
210 
211  protected:
212  bool complete_;
213  bool stopped_;
217 
218  int me_;
219 
220  int nproc_;
221 
222  int nthread_;
223 
224  static std::vector<pthread_t> pthreads_;
225  static std::vector<pthread_attr_t> pthread_attrs_;
226 
227  private:
228  struct stats_entry {
230  bool dump_all;
231  bool dump_main;
233  std::list<stat_collector*> collectors;
234  stats_entry() : main_collector(0) {}
235  };
236  std::map<std::string, stats_entry> stats_;
237 
239 
240  private:
241  virtual void
242  schedule(timestamp start_time, uint32_t seqnum, event_queue_entry* event_queue_entry) = 0;
243 
244 };
245 
247 
248 #endif
249 
250 } // end of namespace sstmac
251 
252 
253 #endif
254 
timestamp now() const
Definition: event_manager.h:87
virtual void schedule(timestamp start_time, uint32_t seqnum, event_queue_entry *event_queue_entry)=0
virtual void cancel_all_messages(event_loc_id canceled_loc)=0
virtual void multithread_schedule(int srcthread, int dstthread, uint32_t seqnum, event_queue_entry *ev)
#define main
Definition: sumi.h:12
static event_manager * global
Definition: event_manager.h:68
virtual void init_factory_params(sprockit::sim_parameters *params)
virtual int lpid() const
bool dump_all
static std::vector< pthread_t > pthreads_
virtual void schedule_stop(timestamp until)
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
bool reduce_all
stat_collector * main_collector
stat_collector * register_thread_unique_stat(stat_collector *stat, bool reduce_all=true, bool dump_all=false, bool dump_main=true)
The owner of a discrete-event network simulation.
Definition: manager.h:35
static int current_thread_id()
static std::vector< pthread_attr_t > pthread_attrs_
virtual void clear(timestamp zero_time=timestamp(0))=0
Clear all events and set time back to a zero of your choice.
virtual void set_interconnect(hw::interconnect *interconn)
parallel_runtime * rt_
int worker_id() const
A basic container for time (subject to future transplant).
Definition: timestamp.h:29
virtual bool empty() const =0
bool dump_main
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
virtual ~event_manager()
Goodbye.
void register_stat(stat_collector *stat, bool reduce_all=true, bool dump_all=false, bool dump_main=true)
DeclareDebugSlot(event_manager)
virtual void run()=0
Run the eventmanager.
std::map< std::string, stats_entry > stats_
virtual event_manager * ev_man_for_thread(int thread_id) const
partition * topology_partition() const
The interface for something that can schedule messages.
stats_entry()
parallel_runtime * runtime() const
event_manager(parallel_runtime *rt)
virtual void ipc_schedule(timestamp t, event_loc_id dst, event_loc_id src, uint32_t seqnum, event *ev)
virtual std::string to_string() const
Definition: event_manager.h:56
int thread_id() const
void set_now(const timestamp &ts)
Definition: sst_event.h:67
Class for storing all the partitions given to us by METIS.
Definition: sim_partition.h:35
std::list< stat_collector * > collectors
DeclareFactory(parallel_runtime)