52 ActionList::iterator aitem;
54 if ((*aitem)->action() == a)
break;
56 printf(
"ERROR: action '%s' not registered to scheduler. \n", a->
name());
59 (*aitem)->read_attr.push_back(strdup(attr));
60 (*aitem)->read_idx.push_back(idx);
61 (*aitem)->input.push_back(NULL);
67 ActionList::iterator aitem =
actions.begin();
68 for (; aitem !=
actions.end(); aitem++)
69 if ((*aitem)->action() == a)
break;
71 printf(
"ERROR: action '%s' not registered to scheduler. \n", a->
name());
74 (*aitem)->write_attr.push_back(strdup(attr));
75 (*aitem)->write_idx.push_back(idx);
76 (*aitem)->output.push_back(NULL);
85 while (pool.size()!=0) {
87 ActionList::iterator act = pool.end()-1;
88 for (; act>=pool.begin(); act--)
90 if ((*act)->fullfilled()== 1) {
95 if (act < pool.begin()) {
96 printf(
"Loop detected!\n");
103 if (item->
n_read() == 0) {
104 roots.push_back(item);
107 for (
unsigned int i=0;
i<item->
n_read();
i++) {
108 if (item->
input[
i] == NULL) {
110 ActionList::iterator a = pool.end()-1;
111 for (; a>=pool.begin(); a--) {
116 (*a)->output[inIdx] = item;
120 if (a < pool.begin()) {
121 printf(
"Error: can not find matching input for action %s of attr:%s index:%d. \n", (*a)->name(), item->
read_attr[
i], item->
read_idx[
i]);
131 unsigned int idx = 1;
132 while (idx<pool.size()) {
136 for (
unsigned int i=0;
i<item->
n_read();
i++) {
137 for (
int j=idx-1;
j>=0;
j--) {
142 aitem->
output[inIdx] = item;
149 for (idx=0; idx<pool.size(); idx++) {
152 for (
unsigned int i=0;
i<item->
n_read();
i++)
153 if (item->
input[
i] != NULL) {
157 if (isroot)
roots.push_back(item);
164 MAN_DEBUG(1, (
"Scheduler::schedule called.\n"));
180 printf(
"Topological sort:\n");
200 for (i=0; i<aitem->
n_read(); i++) {
202 fprintf(f,
"edge: { sourcename: \"%s\" targetname: \"%s\" label: \"%s,%d\"}\n", aitem->
input[i]->name(), aitem->
name(), aitem->
read_attr[
i], aitem->
read_idx[
i]);
204 for (i=0; i<aitem->
n_write(); i++)
210 if (
actions.size() == 0)
return NULL;
212 std::string sched_name = container_name;
213 sched_name = sched_name +
"-" +
name();
214 fprintf(f,
"graph: { title: \"%s\" label: \"%s\" \n\
216 display_edge_labels: yes \n\
217 layoutalgorithm: tree \n\
218 scaling: maxspect \n\
220 node.color : lightblue \n\
221 node.textcolor : black \n\
222 node.bordercolor: black \n\
223 node.borderwidth: 1 \n\
224 edge.color : lightblue \n\
225 edge.arrowsize : 7 \n\
226 edge.thickness : 2 \n\
227 edge.fontname:\"helvO08\" \n\
228 node.label: \"no type\" \n", sched_name.c_str(), sched_name.c_str());
231 for (i=0; i<
actions.size(); i++)
234 for (i=0; i<
roots.size(); i++) {
240 return strdup(sched_name.c_str());
246 FILE *f =
fopen(fname,
"w");
248 fprintf(f,
"graph: { title: \"DependenceTree\" \n\
249 display_edge_labels: yes \n\
250 layoutalgorithm: tree \n\
251 scaling: maxspect \n\
252 node.color : green \n\
253 node.textcolor : black \n\
254 node.bordercolor: black \n\
255 node.borderwidth: 1 \n\
256 edge.color : blue \n\
257 edge.arrowsize : 7 \n\
258 edge.thickness : 2 \n\
259 edge.fontname:\"helvO08\" \n\
260 node.label: \"no type\" \n");
262 print(f,
"scheduler");
273 ActionList::iterator aitem = pool.begin();
274 for (; aitem!=pool.end(); aitem++) {
275 if ((*aitem)->n_read() == 0) {
break; }
278 for (
unsigned int i=0;
i<(*aitem)->n_read();
i++) {
281 ActionList::iterator
s;
282 for (s =
sort.begin(); s!=
sort.end(); ++
s)
283 if ((*s)->action() == in->
action())
break;
284 if (s ==
sort.end()) { flag = 0;
break; }
288 if (aitem != pool.end()) {
289 sort.push_back(*aitem);
296 if (pool.size() != 0) {
297 printf(
"ERROR in sorting!\n");
304 for (
unsigned int i=0;
i<
sort.size();
i++)
sort[
i]->action()->print_toposort(f);
310 ActionList::iterator aitem;
316 for (i=0; i<item->
n_read(); i++)
319 for (i=0; i<item->
n_write(); i++)
331 ActionList::iterator aitem;
332 for (aitem =
sort.begin(); aitem!=
sort.end(); aitem++)
343 ActionList::iterator aitem;
344 for (aitem =
sort.begin(); aitem!=
sort.end(); aitem++)
354 if (
sort.size()==0)
return;
356 ActionList::iterator aitem;
357 for (aitem =
sort.end()-1; aitem>=
sort.begin(); aitem--)
370 if (
output[
i] == NULL)
return 0;
376 for (
unsigned int i=0;
i<n_read();
i++)
377 if (
strcasecmp(attr, read_attr[
i]) == 0 && idx == read_idx[
i])
return i;
383 for (
unsigned int i=0;
i<n_write();
i++)
392 fprintf(f,
"=========== Action %s =============\n",
name());
393 for (i=0; i<n_read(); i++)
394 printf(
"reads: %s %d \n", read_attr[i], read_idx[i]);
395 for (i=0; i<n_write(); i++)
396 printf(
"writes: %s %d \n",
write_attr[i], write_idx[i]);
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
virtual void init(double t)
std::string scheduler_name
void print_helper(FILE *f, ActionItem *aitem)
#define COM_assertion_msg(EX, msg)
virtual void declare(Scheduler &)
This file contains the prototypes for Roccom API.
virtual void add_action(Action *)
int fclose(std::FILE *file)
Close a file, and check for possible errors.
void print_toposort(FILE *f)
void writes(Action *, const char *attr, int idx)
void print(const char *fname)
virtual void run(double t, double dt, double alpha)
void reads(Action *, const char *attr, int idx)
static void write_attr(std::ostream &os, const COM::Attribute *attr, int i)
int strcasecmp(const char *const s1, const char *const s2)
Compare two C-strings, ignoring the case.
vector< ActionItem * > ActionList
vector< const char * > read_attr
int hasOutput(const char *attr, int idx)
int hasInput(const char *attr, int idx)
virtual void add_action(Action *)
void init_actions(double t)
void run_actions(double t, double dt)
std::FILE * fopen(const char *const path, const char *const mode)
Open a file, and check for possible errors.
virtual void print(FILE *f)