Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Action.C
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 // $Id: Action.C,v 1.15 2008/12/06 08:45:22 mtcampbe Exp $
24 
25 #include <typeinfo>
26 
27 #include "rocman.h"
28 #include "Action.h"
29 #include "Scheduler.h"
30 #include "roccom.h"
31 
32 Action::Action(void *p, char *name): action_name(name), attr(NULL),
33  idx(NULL), count(0), usr_ptr(p)
34 {
35 }
36 
37 Action::Action(int n, const char *at[], int *id, void *p, char *name): action_name(name), count(n), usr_ptr(p)
38 {
39  set_attr(n, at, id);
40  if (action_name == NULL) action_name = (char*)typeid(*this).name();
41 }
42 
43 Action::Action(int n, const std::string at[], int *id, void *p, char *name): action_name(name), count(n), usr_ptr(p)
44 {
45  set_attr(n, at, id);
46  if (action_name == NULL) action_name = (char*)typeid(*this).name();
47 }
48 
50 {
51  for (int i=0; i<count; i++) free(attr[i]);
52  delete [] attr;
53  delete [] idx;
54 }
55 
56 void Action::set_attr(int n, const char *at[], int *id)
57 {
58  int i;
59  count = n;
60  attr = new char *[count];
61  for (i=0; i<count; i++) attr[i] = strdup(at[i]);
62  idx = new int[count];
63  for (i=0; i<count; i++) idx[i] = id?id[i]:0;
64 }
65 
66 void Action::set_attr(int n, const std::string at[], int *id)
67 {
68  int i;
69  count = n;
70  attr = new char *[count];
71  for (i=0; i<count; i++) attr[i] = strdup(at[i].c_str());
72  idx = new int[count];
73  for (i=0; i<count; i++) idx[i] = id?id[i]:0;
74 }
75 
76 // Declare the input and ouput variables
77 void Action::declare(Scheduler& sched) {
78  //CmiAssert(count>0);
79  for ( int i=0; i<count; ++i) {
80  if ( inout[i] & IN)
81  sched.reads(this, attr[i], idx[i]);
82  if ( inout[i] & OUT)
83  sched.writes(this, attr[i], idx[i]);
84  }
85 }
86 
87 void Action::print(FILE *f)
88 {
89  fprintf(f, "node: { title:\"%s\" label:\"%s\"}\n", name(), name());
90 }
91 
92 // Obtain attribute handle of ith attribute
94  COM_assertion_msg ( attr[i]!=NULL, (std::string("Attribute \"")
95  +"\" does not exist").c_str());
96  int hdl = COM_get_attribute_handle( attr[i]);
97  COM_assertion_msg ( hdl>0, (std::string("Attribute \"")+attr[i]
98  +"\" does not exist").c_str());
99  return hdl;
100 }
101 
102 int Action::get_attribute_handle( const std::string str) {
103  int hdl = COM_get_attribute_handle( str);
104  COM_assertion_msg ( hdl>0, (std::string("Attribute \"")+str
105  +"\" does not exist").c_str());
106  return hdl;
107 }
108 
109 // Obtain attribute handle of ith attribute
111  int hdl = COM_get_attribute_handle_const( attr[i]);
112  COM_assertion_msg ( hdl>0, (std::string("Attribute \"")+attr[i]
113  +"\" does not exist").c_str());
114  return hdl;
115 }
116 
117 // SchedulerAction
118 
120  if ( sched) delete sched;
121 }
122 
123 void SchedulerAction::init(double t)
124 {
125  sched->init_actions(t);
126 }
127 
129  sched->schedule();
130 }
131 
132 void SchedulerAction::run(double t, double dt, double alpha)
133 {
134  //sched->set_alpha(alpha);
135  sched->run_actions(t, dt);
136 }
137 
139 {
141 }
142 
143 void SchedulerAction::print(FILE *f, char *container_name)
144 {
145  fprintf(f, "graph: { title: \"%s\" label: \"%s\" \n\
146  status: folded \n\
147  display_edge_labels: yes \n\
148  layoutalgorithm: tree \n\
149  scaling: maxspect \n\
150  color : red \n\
151  node.color : black \n\
152  node.textcolor : red \n\
153  node.bordercolor: black \n\
154  node.borderwidth: 1 \n\
155  edge.color : lightblue \n\
156  edge.arrowsize : 7 \n\
157  edge.thickness : 2 \n\
158  edge.fontname:\"helvO08\" \n\
159  node.label: \"no type\" \n", name(), name());
160  sched->print(f, container_name);
161  fprintf(f, "}\n");
162 }
163 
165 {
166  fprintf(f, "( ");
167  sched->print_toposort(f);
168  fprintf(f, ") ");
169 }
170 
171 
172 // UserSchedulerAction
173 
175  if ( sched) delete sched;
176 }
177 
179 {
180  sched->init_actions(t);
181 }
182 
184  sched->schedule();
185 }
186 
187 void UserSchedulerAction::run(double t, double dt, double alpha)
188 {
189  sched->set_alpha(alpha);
190  sched->run_actions(t, dt);
191 }
192 
194 {
196 }
197 
198 void UserSchedulerAction::print(FILE *f, char *container_name)
199 {
200  fprintf(f, "graph: { title: \"%s\" label: \"%s\" \n\
201  status: folded \n\
202  display_edge_labels: yes \n\
203  layoutalgorithm: tree \n\
204  scaling: maxspect \n\
205  color : red \n\
206  node.color : black \n\
207  node.textcolor : red \n\
208  node.bordercolor: black \n\
209  node.borderwidth: 1 \n\
210  edge.color : lightblue \n\
211  edge.arrowsize : 7 \n\
212  edge.thickness : 2 \n\
213  edge.fontname:\"helvO08\" \n\
214  node.label: \"no type\" \n", name(), name());
215  sched->print(f, container_name);
216  fprintf(f, "}\n");
217 }
218 
220 {
221  fprintf(f, "( ");
222  sched->print_toposort(f);
223  fprintf(f, ") ");
224 }
225 
226 
227 
228 
229 
230 
231 
232 
virtual void run(double t, double dt, double alpha)
Definition: Action.C:187
virtual ~SchedulerAction()
Definition: Action.C:119
virtual char * name()
Definition: Action.h:53
virtual void schedule()
Definition: Scheduler.C:408
#define COM_assertion_msg(EX, msg)
virtual void declare(Scheduler &)
Definition: Action.C:77
This file contains the prototypes for Roccom API.
int get_attribute_handle(int i)
Definition: Action.C:93
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
virtual void schedule()
Definition: Scheduler.C:162
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
void set_alpha(double alpha)
Definition: Scheduler.h:44
std::vector< int > inout
Definition: Action.h:42
void print_toposort(FILE *f)
Definition: Scheduler.C:302
int count
Definition: Action.h:39
virtual void print_toposort(FILE *f)
Definition: Action.C:164
void writes(Action *, const char *attr, int idx)
Definition: Scheduler.C:64
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
void print(const char *fname)
Definition: Scheduler.C:244
UserScheduler * sched
Definition: Action.h:97
void reads(Action *, const char *attr, int idx)
Definition: Scheduler.C:49
char ** attr
Definition: Action.h:37
virtual void print(FILE *f, char *container_name)
Definition: Action.C:143
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
void finalize_actions()
Definition: Scheduler.C:351
virtual void init(double t)
Definition: Action.C:123
int COM_get_attribute_handle_const(const char *waname)
Definition: roccom_c++.h:420
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
Scheduler * sched
Definition: Action.h:81
void init_actions(double t)
Definition: Scheduler.C:324
void run_actions(double t, double dt)
Definition: Scheduler.C:339
virtual void run(double t, double dt, double alpha)
Definition: Action.C:132
virtual void finalize()
Definition: Action.C:193
virtual ~UserSchedulerAction()
Definition: Action.C:174
virtual void print(FILE *f)
Definition: Action.C:87