Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Action.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 _ACTION_H_
24 #define _ACTION_H_
25 
26 #include <vector>
27 #include <cstring>
28 
29 class Scheduler;
30 class UserScheduler;
31 
32 class Action
33 {
34 protected:
35  enum { IN=1, OUT=2, INOUT=3 };
36  char *action_name;
37  char **attr;
38  int *idx;
39  int count;
40  void *usr_ptr;
41 
42  std::vector<int> inout;
43 public:
44  Action(void *p=0, char *name=NULL);
45  Action(int n, const char *at[], int *i=NULL, void *p=0, char *name=NULL);
46  Action(int n, const std::string at[], int *i=NULL, void *p=0, char *name=NULL);
47 
48  virtual ~Action();
49  virtual void declare(Scheduler &);
50  virtual void init(double t) { /* printf("Rocstar: Action %s init. \n", name());*/ }
51  virtual void run(double t, double dt, double alpha) {/* printf("Action %s runs. \n", name()); */}
52  virtual void finalize() { /* printf("Rocstar: Action %s finalized. \n", name()); */ }
53  virtual inline char *name() { return action_name; }
54  inline void set_name(const char *name) { action_name = strdup(name); }
55  virtual void print(FILE *f);
56  virtual void print_toposort(FILE *f) { fprintf(f, "%s ", name()); }
57  virtual void schedule() {} // do nothing
58 
59 protected:
60  // Obtain attribute handle of ith attribute
61  int get_attribute_handle( int i);
62  int get_attribute_handle_const( int i);
63  int get_attribute_handle( const std::string str);
64 
65  // set attributes
66  void set_attr(int n, const std::string at[], int *id=NULL);
67  void set_attr(int n, const char * at[], int *id=NULL);
68 
69  // Set I/O properties of arguments
70  void set_io( int n, const int *io)
71  { inout.clear(); inout.insert( inout.end(), io, io+n); if (count==0) count=n; }
72 
73  void set_io( const char *io); // TODO
74  int get_io(int i) { return inout[i]; }
75 };
76 
77 // a list of subactions managed by a sub-scheduler
78 class SchedulerAction: public Action
79 {
80 private:
82 public:
83  SchedulerAction(Scheduler *s, int n, const char *at[], int i[], void *p=0, char *name=NULL): Action(n, at, i, p, name), sched(s) {}
84  virtual ~SchedulerAction();
85  virtual void declare(Scheduler &) = 0;
86  virtual void init(double t);
87  virtual void run(double t, double dt, double alpha);
88  virtual void finalize();
89  virtual void print(FILE *f, char *container_name);
90  virtual void print_toposort(FILE *f);
91  virtual void schedule();
92 };
93 
95 {
96 private:
98 public:
99  UserSchedulerAction(UserScheduler *s, int n, const char *at[], int i[], void *p=0, char *name=NULL): Action(n, at, i, p, name), sched(s) {}
100  virtual ~UserSchedulerAction();
101 // virtual void declare(Scheduler &) = 0;
102  virtual void init(double t);
103  virtual void run(double t, double dt, double alpha);
104  virtual void finalize();
105  virtual void print(FILE *f, char *container_name);
106  virtual void print_toposort(FILE *f);
107  virtual void schedule();
108 };
109 
110 
111 #endif
112 
113 
114 
115 
116 
117 
virtual void run(double t, double dt, double alpha)
Definition: Action.C:187
virtual void print_toposort(FILE *f)
Definition: Action.h:56
virtual ~SchedulerAction()
Definition: Action.C:119
virtual char * name()
Definition: Action.h:53
virtual void init(double t)
Definition: Action.h:50
double s
Definition: blastest.C:80
virtual void declare(Scheduler &)
Definition: Action.C:77
int get_attribute_handle(int i)
Definition: Action.C:93
virtual void finalize()
Definition: Action.h:52
virtual void schedule()
Definition: Action.C:128
virtual void print_toposort(FILE *f)
Definition: Action.C:219
int get_attribute_handle_const(int i)
Definition: Action.C:110
Definition: Action.h:32
std::vector< int > inout
Definition: Action.h:42
virtual void declare(Scheduler &)=0
int count
Definition: Action.h:39
virtual void print_toposort(FILE *f)
Definition: Action.C:164
virtual ~Action()
Definition: Action.C:49
char * action_name
Definition: Action.h:36
virtual void schedule()
Definition: Action.C:183
int * idx
Definition: Action.h:38
virtual void run(double t, double dt, double alpha)
Definition: Action.h:51
UserScheduler * sched
Definition: Action.h:97
char ** attr
Definition: Action.h:37
virtual void print(FILE *f, char *container_name)
Definition: Action.C:143
void set_io(int n, const int *io)
Definition: Action.h:70
blockLoc i
Definition: read.cpp:79
virtual void init(double t)
Definition: Action.C:178
const NT & n
virtual void finalize()
Definition: Action.C:138
virtual void init(double t)
Definition: Action.C:123
virtual void schedule()
Definition: Action.h:57
void set_name(const char *name)
Definition: Action.h:54
virtual void print(FILE *f, char *container_name)
Definition: Action.C:198
Action(void *p=0, char *name=NULL)
Definition: Action.C:32
void set_attr(int n, const std::string at[], int *id=NULL)
Definition: Action.C:66
UserSchedulerAction(UserScheduler *s, int n, const char *at[], int i[], void *p=0, char *name=NULL)
Definition: Action.h:99
Scheduler * sched
Definition: Action.h:81
void * usr_ptr
Definition: Action.h:40
virtual void run(double t, double dt, double alpha)
Definition: Action.C:132
virtual void finalize()
Definition: Action.C:193
SchedulerAction(Scheduler *s, int n, const char *at[], int i[], void *p=0, char *name=NULL)
Definition: Action.h:83
virtual ~UserSchedulerAction()
Definition: Action.C:174
virtual void print(FILE *f)
Definition: Action.C:87
int get_io(int i)
Definition: Action.h:74