Charades
scheduler.h
1 #ifndef _SCHEDULER_H_
2 #define _SCHEDULER_H_
3 
4 #include "scheduler.decl.h"
5 
6 #include "gvtmanager.h" // Temporary for produce/consume
7 #include "pe_queue.h"
8 #include "typedefs.h"
9 
10 extern CkGroupID scheduler_id;
11 
12 typedef Scheduler* SchedulerPtr;
13 CpvExtern(SchedulerPtr, g_scheduler);
14 
15 class Globals;
16 class LPChare;
17 class LPToken;
18 class RemoteEvent;
19 class Statistics;
20 class Trigger;
21 
22 using std::string;
23 
24 #if CMK_USING_XLC
25 typedef std::auto_ptr<Trigger> TriggerPtr;
26 #else
27 typedef std::unique_ptr<Trigger> TriggerPtr;
28 #endif
29 
36 class Scheduler : public CBase_Scheduler {
37  protected:
38  string scheduler_name;
39  bool running;
40  double start_time;
41  double end_time;
45  public:
46  // TODO: Globals may not be needed once event handling is moved to scheduler
51  Scheduler();
52 
54  virtual void groups_created();
55 
57  void start_simulation();
58  void end_simulation();
59  void finalize_complete();
60  void finalize(CkReductionMsg *m);
63  void print_progress(Time ts);
64 
66  bool schedule_next_lp();
67 
69  virtual Time get_min_time() const;
70 
72  virtual void execute();
73 
75  void register_lp(LPToken* next_token, Time next_ts) {
76  next_lps.insert(next_token, next_ts);
77  }
78  void unregister_lp(LPToken* next_token) {
79  next_lps.remove(next_token);
80  }
81  void update_next(LPToken* token, Time ts) {
82  next_lps.update(token, ts);
83  }
84 
85  // TODO: Move to distributed/optimistic
86  virtual void consume(RemoteEvent* e) {}
87  virtual void produce(RemoteEvent* e) {}
88  virtual void update_min_cancel(Time ts) {}
89 };
90 
96 class SequentialScheduler : public CBase_SequentialScheduler {
97  public:
99  void execute();
100 };
101 
109 class DistributedScheduler : public CBase_DistributedScheduler {
110  protected:
113  TriggerPtr gvt_trigger;
114  TriggerPtr print_trigger;
115 #if CMK_TRACE_ENABLED
116  TriggerPtr stat_trigger;
117 #endif
118 
119  public:
121 
123  void groups_created();
124 
126  void iteration_done();
127  void next_iteration();
128 
130  void start_balancing();
131  void balancing_complete();
132 
134  virtual void gvt_resume();
135  virtual void gvt_done(Time gvt, bool lb);
138  void consume(RemoteEvent* e) {
139  gvt_manager->consume(e);
140  }
141  void produce(RemoteEvent* e) {
142  gvt_manager->produce(e);
143  }
144 };
145 
146 #endif
virtual void execute()
Entry method for executing a scheduler iteration.
Definition: scheduler.C:117
PE-level variables which may change over time.
Definition: globals.h:76
Statistics * cumulative_stats
Cumulative stats over all intervals.
Definition: scheduler.h:49
void balancing_complete()
After load balancing completes we can do the next scheduler iteration.
Definition: scheduler.C:271
virtual void consume(RemoteEvent *e)
Methods for producing and consuming events for GVTs that need to know.
Definition: gvtmanager.h:50
Base class defining basic scheduler functionality.
Definition: scheduler.h:36
GVTManager * gvt_manager
Direct pointer to our local GVT Manager.
Definition: scheduler.h:111
TriggerPtr print_trigger
Determines when to print progress.
Definition: scheduler.h:114
Definition: pe_queue.h:15
virtual void gvt_done(Time gvt, bool lb)
Called when GVT is complete.
Definition: scheduler.C:220
Concrete type for sequential schedulers.
Definition: scheduler.h:96
A chare that encapsulates a set of LPStructs and their events.
Definition: lp.h:64
void groups_created()
Called after all group chares are created.
Definition: scheduler.C:174
bool running
True if there are active execute() messages.
Definition: scheduler.h:39
void end_simulation()
Starts stats reduction.
Definition: scheduler.C:61
A token representing a handle to an LP chare inside the scheduler queues.
Definition: lp.h:30
Concrete base class for distributed schedulers.
Definition: scheduler.h:109
void consume(RemoteEvent *e)
Methods informing the GVT Manager about incoming/outgoing events.
Definition: scheduler.h:138
void print_progress(Time ts)
Method for printing out basic info about the current progress.
Definition: scheduler.C:87
void register_lp(LPToken *next_token, Time next_ts)
Update the queue of LPs that are local to this PE.
Definition: scheduler.h:75
Statistics * stats
Statistics for current stat interval.
Definition: scheduler.h:48
void next_iteration()
Helper method for starting the next scheduler iteration.
Definition: scheduler.C:201
virtual void groups_created()
Entry method triggered by QD when all group chares are created.
Definition: scheduler.C:43
void finalize(CkReductionMsg *m)
Receives stats reduction and exits.
Definition: scheduler.C:74
void iteration_done()
Local methods for iteration control flow.
Definition: scheduler.C:185
string scheduler_name
Name of scheduler for print outs.
Definition: scheduler.h:38
TriggerPtr gvt_trigger
Determines when to compute GVT.
Definition: scheduler.h:113
double start_time
Start wall time for the simulation.
Definition: scheduler.h:40
double end_time
End wall time for the simulation.
Definition: scheduler.h:41
Globals * globals
Global variables per PE.
Definition: scheduler.h:47
Declares most types used within the simulator and by models.
void start_balancing()
Methods for load balancing synchronization.
Definition: scheduler.C:262
Definition: event.h:15
virtual Time get_min_time() const
Get the minimum time of any event on this PE.
Definition: scheduler.C:112
void start_simulation()
Methods for starting and stopping the entire simulation.
Definition: scheduler.C:52
PEQueue next_lps
queue storing LPTokens ordered by next event ts
Definition: scheduler.h:43
Definition: gvtmanager.h:14
Definition: trigger.h:8
virtual void gvt_resume()
Methods called by the GVT Manager signifying the scheduler may resume.
Definition: scheduler.C:209
Class for holding all PE level statistics for a given simulation run.
Definition: statistics.h:49
bool schedule_next_lp()
Calls execute_me() on the next LP in the queue.
Definition: scheduler.C:98