Commit d91884a5 authored by Robert Ricci's avatar Robert Ricci
Browse files

Change the subnode stuff to do late binding of subnode name to

{p,v}node object. This way, the parent node doesn't have to be listed
before the child. Wh

I could do this to links too, but it seems to have less of a payoff -
it's easy enough to just do all the nodes, then all the links.
parent c7c3c510
...@@ -32,6 +32,35 @@ extern name_pvertex_map pname2vertex; ...@@ -32,6 +32,35 @@ extern name_pvertex_map pname2vertex;
extern name_count_map ptypes; extern name_count_map ptypes;
#define ptop_error(s) errors++;cerr << "PTOP:" << line << ": " << s << endl #define ptop_error(s) errors++;cerr << "PTOP:" << line << ": " << s << endl
#define ptop_error_noline(s) errors++;cerr << "PTOP: " << s << endl
// Used to do late binding of subnode names to pnodes, so that we're no
// dependant on their ordering in the ptop file, which can be annoying to get
// right.
// Returns the number of errors found
int bind_ptop_subnodes() {
int errors = 0;
// Iterate through all pnodes looking for ones that are subnodes
pvertex_iterator vit,vendit;
tie(vit,vendit) = vertices(PG);
for (;vit != vendit;++vit) {
tb_pnode *pnode = get(pvertex_pmap,*vit);
if (!pnode->subnode_of_name.empty()) {
if (pname2vertex.find(pnode->subnode_of_name) ==
pname2vertex.end()) {
ptop_error_noline(pnode->name << " is a subnode of a " <<
"non-existent node, " << pnode->subnode_of_name << ".");
continue;
}
pvertex parent_pv = pname2vertex[pnode->subnode_of_name];
pnode->subnode_of = get(pvertex_pmap,parent_pv);
pnode->subnode_of->has_subnode = true;
}
}
return errors;
}
int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i) int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i)
{ {
...@@ -67,25 +96,6 @@ int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i) ...@@ -67,25 +96,6 @@ int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i)
if (split_two(parsed_line[i],':',type,load,"1") != 0) { if (split_two(parsed_line[i],':',type,load,"1") != 0) {
ptop_error("Bad node line, no load for type: " << type << "."); ptop_error("Bad node line, no load for type: " << type << ".");
} }
// First, check to see if it's not actually a type, but a subnode
// relationship
if (type.compare("subnode_of") == 0) {
if (p->subnode_of) {
ptop_error("Can't be a subnode of two nodes");
continue;
}
if (pname2vertex.find(load) == pname2vertex.end()) {
ptop_error("Subnode of a non-existent node.");
}
pvertex parent_pv = pname2vertex[load];
p->subnode_of = get(pvertex_pmap,parent_pv);
p->subnode_of->has_subnode = true;
// Don't keep processing as if it were a type
continue;
}
// Check to see if this is a static type // Check to see if this is a static type
bool is_static = false; bool is_static = false;
if (type[0] == '*') { if (type[0] == '*') {
...@@ -137,8 +147,8 @@ int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i) ...@@ -137,8 +147,8 @@ int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i)
for (i=i+1; i < parsed_line.size(); ++i) { for (i=i+1; i < parsed_line.size(); ++i) {
crope flag,value; crope flag,value;
split_two(parsed_line[i],':',flag,value,"(null)"); split_two(parsed_line[i],':',flag,value,"(null)");
#ifdef TRIVIAL_LINK_BW if (flag.compare("trivial_bw") == 0) {
if (flag == crope("trivial_bw")) { // Handle trivial bandwidth spec
int trivial_bw; int trivial_bw;
if (sscanf(value.c_str(),"%i",&trivial_bw) != 1) { if (sscanf(value.c_str(),"%i",&trivial_bw) != 1) {
ptop_error("Bad bandwidth given for trivial_bw: " << value ptop_error("Bad bandwidth given for trivial_bw: " << value
...@@ -146,10 +156,19 @@ int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i) ...@@ -146,10 +156,19 @@ int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i)
trivial_bw = 0; trivial_bw = 0;
} }
p->trivial_bw = trivial_bw; p->trivial_bw = trivial_bw;
} else if (flag.compare("subnode_of") == 0) {
// Handle subnode relationships
if (!p->subnode_of_name.empty()) {
ptop_error("Can't be a subnode of two nodes");
continue;
} else {
// Just store the name for now, we'll do late binding to
// an actual pnode later
p->subnode_of_name = value;
}
} else { } else {
ptop_error("Bad flag given: " << flag << "."); ptop_error("Bad flag given: " << flag << ".");
} }
#endif
} }
pname2vertex[name] = pv; pname2vertex[name] = pv;
} }
...@@ -276,6 +295,8 @@ int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i) ...@@ -276,6 +295,8 @@ int parse_ptop(tb_pgraph &PG, tb_sgraph &SG, istream& i)
} }
} }
errors += bind_ptop_subnodes();
if (errors > 0) {exit(2);} if (errors > 0) {exit(2);}
return num_nodes; return num_nodes;
......
...@@ -35,6 +35,35 @@ extern name_list_map vclasses; ...@@ -35,6 +35,35 @@ extern name_list_map vclasses;
extern vvertex_vector virtual_nodes; extern vvertex_vector virtual_nodes;
#define top_error(s) errors++;cerr << "TOP:" << line << ": " << s << endl #define top_error(s) errors++;cerr << "TOP:" << line << ": " << s << endl
#define top_error_noline(s) errors++;cerr << "TOP: " << s << endl
// Used to do late binding of subnode names to vnodes, so that we're no
// dependant on their ordering in the top file, which can be annoying to get
// right.
// Returns the number of errors found
int bind_top_subnodes() {
int errors = 0;
// Iterate through all vnodes looking for ones that are subnodes
vvertex_iterator vit,vendit;
tie(vit,vendit) = vertices(VG);
for (;vit != vendit;++vit) {
tb_vnode *vnode = get(vvertex_pmap, *vit);
if (!vnode->subnode_of_name.empty()) {
if (vname2vertex.find(vnode->subnode_of_name)
== vname2vertex.end()) {
top_error_noline(vnode->name << " is a subnode of a " <<
"non-existent node, " << vnode->subnode_of_name << ".");
continue;
}
vvertex parent_vv = vname2vertex[vnode->subnode_of_name];
vnode->subnode_of = get(vvertex_pmap,parent_vv);
vnode->subnode_of->subnodes.push_back(vnode);
}
}
return errors;
}
int parse_top(tb_vgraph &VG, istream& i) int parse_top(tb_vgraph &VG, istream& i)
{ {
...@@ -97,16 +126,11 @@ int parse_top(tb_vgraph &VG, istream& i) ...@@ -97,16 +126,11 @@ int parse_top(tb_vgraph &VG, istream& i)
} else { } else {
if (desirename.compare("subnode_of") == 0) { if (desirename.compare("subnode_of") == 0) {
// Okay, it's not a desire, it's a subnode declaration // Okay, it's not a desire, it's a subnode declaration
if (v->subnode_of) { if (!v->subnode_of_name.empty()) {
top_error("Can only be a subnode of one node"); top_error("Can only be a subnode of one node");
}
if (vname2vertex.find(desireweight) == vname2vertex.end()) {
top_error("Bad link line, non-existent node.");
continue; continue;
} }
vvertex parent_vv = vname2vertex[desireweight]; v->subnode_of_name = desireweight;
v->subnode_of = get(vvertex_pmap,parent_vv);
v->subnode_of->subnodes.push_back(v);
} else { } else {
double gweight; double gweight;
...@@ -285,6 +309,8 @@ int parse_top(tb_vgraph &VG, istream& i) ...@@ -285,6 +309,8 @@ int parse_top(tb_vgraph &VG, istream& i)
} }
} }
errors += bind_top_subnodes();
if (errors > 0) {exit(2);} if (errors > 0) {exit(2);}
return num_nodes; return num_nodes;
......
...@@ -78,7 +78,7 @@ public: ...@@ -78,7 +78,7 @@ public:
total_bandwidth(0), my_class(NULL), total_bandwidth(0), my_class(NULL),
my_own_class(NULL), assigned_nodes(), my_own_class(NULL), assigned_nodes(),
trivial_bw(0), trivial_bw_used(0), subnode_of(NULL), trivial_bw(0), trivial_bw_used(0), subnode_of(NULL),
has_subnode(false) {;} subnode_of_name(""), has_subnode(false) {;}
class type_record { class type_record {
public: public:
...@@ -142,6 +142,8 @@ public: ...@@ -142,6 +142,8 @@ public:
tb_pnode *subnode_of; // the pnode, if any, that this node is a tb_pnode *subnode_of; // the pnode, if any, that this node is a
// subnode of // subnode of
crope subnode_of_name; // name of the pnode this node is a subnode of -
// used to do late bindind
bool has_subnode; // whether or not this node has any subnodes bool has_subnode; // whether or not this node has any subnodes
......
...@@ -66,7 +66,8 @@ public: ...@@ -66,7 +66,8 @@ public:
class tb_vnode { class tb_vnode {
public: public:
tb_vnode(): vclass(NULL), fixed(false), assigned(false), subnode_of(NULL) {;} tb_vnode(): vclass(NULL), fixed(false), assigned(false), subnode_of(NULL),
subnode_of_name("") {;}
friend ostream &operator<<(ostream &o, const tb_vnode& node) friend ostream &operator<<(ostream &o, const tb_vnode& node)
{ {
...@@ -111,6 +112,7 @@ public: ...@@ -111,6 +112,7 @@ public:
tb_vnode *subnode_of; tb_vnode *subnode_of;
typedef list<tb_vnode*> subnode_list; typedef list<tb_vnode*> subnode_list;
subnode_list subnodes; subnode_list subnodes;
crope subnode_of_name;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment