Commit d00c4b75 authored by Christopher Alfeld's avatar Christopher Alfeld

Converted to use aribitary types.

parent 9b3790fd
#ifndef __COMON_H
#define __COMON_H
class tb_type {
public:
char *name;
int max;
};
const int MAX_PNODES = 1024; // maximum # of physical nodes
typedef enum {TYPE_UNKNOWN, TYPE_PC, TYPE_DNARD, TYPE_DELAY, TYPE_DELAY_PC,
TYPE_SWITCH} nodeType;
enum {MAX_TYPES = 5};
#endif
......
......@@ -36,7 +36,6 @@ int parse_ptop(tb_pgraph &PG, istream& i)
char n1[32], n2[32];
int size, num;
int n=1;
int j;
char *snext;
char *snode;
char *scur;
......@@ -64,18 +63,15 @@ int parse_ptop(tb_pgraph &PG, istream& i)
string s(snode);
no1 = PG.new_node();
PG[no1].name=strdup(snode);
PG[no1].current_type = TYPE_UNKNOWN;
PG[no1].typed = false;
PG[no1].max_load = 0;
PG[no1].current_load = 0;
PG[no1].pnodes_used=0;
for (j = 0 ; j < MAX_TYPES; ++j) {
PG[no1].types[j].name = NULL;
PG[no1].types[j].max = 0;
}
while ((scur = strsep(&snext," ")) != NULL) {
char *t,*load=scur;
int iload;
t = strsep(&load,":");
string stype(t);
if (load) {
if (sscanf(load,"%d",&iload) != 1) {
fprintf(stderr,"Bad load specifier: %s\n",load);
......@@ -84,25 +80,13 @@ int parse_ptop(tb_pgraph &PG, istream& i)
} else {
iload=1;
}
if (strcmp(t,"pc") == 0) {
PG[no1].types[TYPE_PC].name = "pc";
PG[no1].types[TYPE_PC].max = iload;
} else if (strcmp(t,"dnard") == 0) {
PG[no1].types[TYPE_DNARD].name = "dnard";
PG[no1].types[TYPE_DNARD].max = iload;
} else if (strcmp(t,"delay") == 0) {
PG[no1].types[TYPE_DELAY].name = "delay";
PG[no1].types[TYPE_DELAY].max = iload;
} else if (strcmp(t,"delay_pc") == 0) {
// this is an unsuported type. Have types of both
// delay and pc.
fprintf(stderr,"Unsupported type: delay_pc\n");
} else if (strcmp(scur,"switch") == 0) {
if (strcmp(t,"switch") == 0) {
isswitch = 1;
PG[no1].types[TYPE_SWITCH].name = "switch";
PG[no1].types[TYPE_SWITCH].max = 1;
PG[no1].types.insert(stype,1);
PG[no1].the_switch = no1;
switch_index[no1] = switchi++;
} else {
PG[no1].types.insert(stype,iload);
}
}
if (! isswitch)
......@@ -148,7 +132,7 @@ int parse_ptop(tb_pgraph &PG, istream& i)
else
PG[ed1].dstmac = NULL;
}
#define ISSWITCH(n) (PG[n].types[TYPE_SWITCH].max == 1)
#define ISSWITCH(n) (PG[n].types.lookup("switch") != nil)
if (ISSWITCH(node1) &&
! ISSWITCH(node2))
PG[node2].the_switch = node1;
......
......@@ -50,26 +50,9 @@ int parse_top(tb_vgraph &G, istream& i)
G[no1].posistion = 0;
G[no1].no_connections=0;
nmap.insert(s1, no1);
if (!strcmp(type, "delay")) {
G[no1].type = TYPE_DELAY;
}
else if (!strcmp(type, "pc")) {
G[no1].type = TYPE_PC;
}
else if (!strcmp(type, "switch")) {
fprintf(stderr,"Can not have switch's in top file\n");
G[no1].type = TYPE_UNKNOWN;
}
else if (!strcmp(type, "dnard")) {
G[no1].type = TYPE_DNARD;
}
else {
fprintf(stderr,"Unknown type in top file: %s\n",type);
G[no1].type = TYPE_UNKNOWN;
}
G[no1].type=string(type);
}
}
else if (!strncmp(inbuf, "link", 4)) {
} else if (!strncmp(inbuf, "link", 4)) {
r=sscanf(inbuf, "link %s %s %s %d", lname, n1, n2,&bw);
if (r < 2) {
fprintf(stderr, "bad link line: %s\n", inbuf);
......
......@@ -15,8 +15,9 @@ public:
return i;
}
tb_type types[MAX_TYPES]; // array of types, with counts of max
nodeType current_type; // the current type of the node
dictionary<string,int> types; // contains max nodes for each type
string current_type;
bool typed; // has it been typed
int max_load; // maxmium load for current type
int current_load; // how many vnodes are assigned to this pnode
char *name;
......
......@@ -92,7 +92,7 @@ void init_score()
}
forall_nodes(n,PG) {
tb_pnode &pn=PG[n];
pn.current_type=TYPE_UNKNOWN;
pn.typed=false;
pn.current_load=0;
pn.pnodes_used=0;
}
......@@ -221,7 +221,7 @@ void remove_node(node n)
}
}
// revert pnode type
pnoder.current_type=TYPE_UNKNOWN;
pnoder.typed=false;
} else if (pnoder.current_load >= pnoder.max_load) {
#ifdef SCORE_DEBUG
fprintf(stderr," reducing penalty, new load = %d (>= %d)\n",pnoder.current_load,pnoder.max_load);
......@@ -255,14 +255,15 @@ int add_node(node n,int ploc)
#ifdef SCORE_DEBUG
fprintf(stderr,"SCORE: add_node(%s,%s[%d])\n",
vnoder.name,pnoder.name,ploc);
fprintf(stderr," vnode type = %d pnode switch = %s\n",vnoder.type,
(pnoder.the_switch ? PG[pnoder.the_switch].name : "No switch"));
fprintf(stderr," vnode type = ");
cerr << vnoder.type << " pnode switch = ";
cerr << (pnoder.the_switch ? PG[pnoder.the_switch].name : "No switch");
cerr << endl;
#endif
// set up pnode
// figure out type
if (pnoder.current_type == TYPE_UNKNOWN) {
if (!pnoder.typed) {
#ifdef SCORE_DEBUG
fprintf(stderr," virgin pnode\n");
#endif
......@@ -271,7 +272,8 @@ int add_node(node n,int ploc)
// Remove higher level checks?
pnoder.max_load=0;
pnoder.current_type=vnoder.type;
pnoder.max_load = pnoder.types[vnoder.type].max;
pnoder.typed=true;
pnoder.max_load = pnoder.types.access(vnoder.type);
if (pnoder.max_load == 0) {
// didn't find a type
......@@ -281,8 +283,9 @@ int add_node(node n,int ploc)
return 1;
}
#ifdef SCORE_DEBUG
fprintf(stderr," matching type found (%d, max = %d)\n",
pnoder.current_type,pnoder.max_load);
fprintf(stderr," matching type found (");
cerr << pnoder.current_type << ", max = " << pnoder.max_load;
cerr << ")" << endl;
#endif
} else {
#ifdef SCORE_DEBUG
......@@ -387,7 +390,7 @@ int add_node(node n,int ploc)
fprintf(stderr," could not find path - no connection\n");
#endif
// XXX - this is a hack for the moment
pnoder.current_type = TYPE_UNKNOWN;
pnoder.typed = false;
return 1;
// couldn't find path.
......
......@@ -17,7 +17,7 @@ public:
int posistion; // index into pnode array
int no_connections; // how many unfulfilled connections from this node
nodeType type; // type of the node
string type;
char *name; // string name of the node
};
......
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