Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Scheduler.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 #ifndef _SCHEDULER_H_
24 #define _SCHEDULER_H_
25 
26 using namespace std;
27 #include <vector>
28 
29 class Scheduler
30 {
31  friend class SchedulerAction;
32  friend class UserSchedulerAction;
33 public:
34  Scheduler();
35  virtual ~Scheduler() {}
36  virtual void add_action(Action *);
37  void reads(Action *, const char *attr, int idx);
38  void writes(Action *, const char *attr, int idx);
39  virtual void schedule();
40  void init_actions(double t);
41  void restarting(double t) { inited = 0; } // clear init state for restarting
42  void run_actions(double t, double dt);
43  void finalize_actions();
44  void set_alpha(double alpha) { alphaT = alpha; }
45  void print(const char *fname); // called by user
46  char * print(FILE *f, const char *container_name); // print a scheduler to file
47  void printDDG(FILE *f);
48  bool isEmpty() { return actions.size() == 0; }
49  const char *name() { return scheduler_name.c_str(); }
50  void set_name(const char* name) { scheduler_name = name; }
51 protected:
52  std::string scheduler_name;
53 
54  struct ActionItem;
55  typedef vector< ActionItem* > ActionList;
56 
57  struct ActionItem {
59  vector <const char *> read_attr;
60  vector <int> read_idx;
61  vector <const char *> write_attr;
62  vector <int> write_idx;
63  ActionList input; // read_n
64  ActionList output; // write_n
65  int print_flag; // for print
66 
67  ActionItem(Action *a): myaction(a) {}
68  inline unsigned int n_write() { return write_attr.size(); }
69  inline unsigned int n_read() { return read_attr.size(); }
70  inline char *name() { return myaction->name(); }
71  inline Action * action() { return myaction; }
72  int fullfilled(); // all output action identified
73  int hasInput(const char *attr, int idx);
74  int hasOutput(const char *attr, int idx);
75  void print(FILE *f);
76  };
77 
78  ActionList actions; // all actions registered
79  ActionList roots; // forest
80  ActionList sort; // topological sort order
81 
82  double alphaT; //
83 
84  int scheduled; // flag: if has been scheduled
85  int inited; // flag: true if init called
86 protected:
87  void buildDDG();
88 private:
89  void topological_sort();
90  void sanityCheck();
91  void print_helper(FILE *f, ActionItem *aitem);
92  void print_toposort(FILE *f);
93  void printActions(); // for debugging
94 };
95 
96 // user specify the order of actions
97 class UserScheduler: public Scheduler
98 {
99 public:
100  virtual void add_action(Action *);
101  virtual void schedule();
102 };
103 
104 typedef void (Scheduler::* Scheduler_voidfn1_t)(double);
105 
106 #endif
107 
108 
109 
110 
111 
112 
double alphaT
Definition: Scheduler.h:82
virtual char * name()
Definition: Action.h:53
ActionList roots
Definition: Scheduler.h:79
std::string scheduler_name
Definition: Scheduler.h:52
void set_name(const char *name)
Definition: Scheduler.h:50
unsigned int n_write()
Definition: Scheduler.h:68
ActionList actions
Definition: Scheduler.h:78
vector< int > write_idx
Definition: Scheduler.h:62
ActionList input
Definition: Scheduler.h:63
ActionList output
Definition: Scheduler.h:64
void set_alpha(double alpha)
Definition: Scheduler.h:44
vector< int > read_idx
Definition: Scheduler.h:60
Definition: Action.h:32
vector< const char * > write_attr
Definition: Scheduler.h:61
bool isEmpty()
Definition: Scheduler.h:48
ActionItem(Action *a)
Definition: Scheduler.h:67
virtual void schedule()
Definition: Action.C:183
int * idx
Definition: Action.h:38
int scheduled
Definition: Scheduler.h:84
char ** attr
Definition: Action.h:37
static void write_attr(std::ostream &os, const COM::Attribute *attr, int i)
vector< ActionItem * > ActionList
Definition: Scheduler.h:54
vector< const char * > read_attr
Definition: Scheduler.h:59
virtual ~Scheduler()
Definition: Scheduler.h:35
unsigned int n_read()
Definition: Scheduler.h:69
void restarting(double t)
Definition: Scheduler.h:41
void(Scheduler::* Scheduler_voidfn1_t)(double)
Definition: Scheduler.h:104
Action * action()
Definition: Scheduler.h:71
virtual void print(FILE *f, char *container_name)
Definition: Action.C:198
const char * name()
Definition: Scheduler.h:49
int inited
Definition: Scheduler.h:85
ActionList sort
Definition: Scheduler.h:80