Commit e2b34994 authored by Jonathon Duerig's avatar Jonathon Duerig

This is the version of prepass which dispatches its sub-graphs by directly...

This is the version of prepass which dispatches its sub-graphs by directly exec'ing the sub-programs that need to be run and using pipes to communicate.
parent 0ea70beb
......@@ -14,7 +14,7 @@
Partition::Partition(int newNumber)
: address(0)
, isTree(true)
, isTree(false)
, lanCount(0)
, hostCount(0)
{
......@@ -25,8 +25,8 @@ Partition::Partition(int newNumber)
void Partition::setNumber(int newNumber)
{
// TODO: Assign a real address. Not just the LAN number.
address = newNumber;
// TODO: Assign a real address. Not just the partition number.
// address = newNumber;
number = newNumber;
}
......@@ -63,7 +63,7 @@ void Partition::addLan(int lanNumber)
lanToOrder[lanNumber] = lanCount;
orderToLan[lanCount] = lanNumber;
++lanCount;
isTree = isTree && g::allLans[lanNumber].isTreeRoot;
// isTree = isTree && g::allLans[lanNumber].isTreeRoot;
g::allLans[lanNumber].partition = number;
// Add one to the count of every host we touch. If two or more
// LANs touch a host, then that host is sent to the children
......@@ -80,28 +80,57 @@ void Partition::addLan(int lanNumber)
//-----------------------------------------------------------------------------
template <class T>
void auto_assign(auto_ptr<T> & left, auto_ptr<T> right)
{
left = right;
}
//-----------------------------------------------------------------------------
void Partition::dispatch(void)
{
if (lanCount <= 1)
{
map<int, int>::iterator pos = lanToOrder.begin();
map<int, int>::iterator limit = lanToOrder.end();
for (; pos != limit; ++pos)
{
g::allLans[pos->first].assignment = pos->second;
}
return;
}
mapHosts();
auto_ptr<FileT> pipe;
ostringstream saver;
string commandLine;
if (isTree)
{
auto_assign(pipe, coprocess(g::treeCommand[0], &(g::treeCommand[0]),
NULL));
for (int i = 0; i < g::treeCommand.size(); ++i)
{
if (g::treeCommand[i] == NULL)
{
commandLine += "(null)";
}
else
{
commandLine += g::treeCommand[i];
commandLine += ' ';
}
}
}
else
{
auto_assign(pipe, coprocess(g::generalCommand[0],
&(g::generalCommand[0]), NULL));
for (int i = 0; i < g::generalCommand.size(); ++i)
{
if (g::treeCommand[i] == NULL)
{
commandLine += "(null)";
}
else
{
commandLine += g::generalCommand[i];
commandLine += ' ';
}
}
}
printGraph(saver);
printGraph(pipe->input());
pipe->closeIn();
getNumbering(pipe->output());
......@@ -109,20 +138,41 @@ void Partition::dispatch(void)
int error = wait3(&childReturn, 0, NULL);
if (error == -1)
{
// throw StringError(string("Waiting for child failed: ")
// + strerror(errno));
cerr << "Waiting for child failed: " << strerror(errno) << endl;
throw;
}
if (childReturn != 0)
{
cerr << "Error in partition " << number << ": ";
parseError(pipe->error());
cerr << endl << "Command line: " << commandLine << endl;
cerr << "---Begin subfile---" << endl;
cerr << saver.str();
cerr << "---End subfile---" << endl;
throw;
}
}
//-----------------------------------------------------------------------------
int Partition::getLanCount(void)
{
return lanCount;
}
//-----------------------------------------------------------------------------
void Partition::setTree(void)
{
isTree = true;
}
//-----------------------------------------------------------------------------
void Partition::parseError(istream & error)
{
cerr << "Error in partition " << number << ": ";
string outside;
string inside;
bool done;
......@@ -191,7 +241,7 @@ void Partition::parseError(istream & error)
getline(error, outside, '$');
done = !error;
}
throw;
// throw;
}
//-----------------------------------------------------------------------------
......@@ -227,6 +277,11 @@ void Partition::printGraph(ostream & output)
void Partition::getNumbering(istream & input)
{
string temp;
input >> temp;
input >> temp;
input >> temp;
input >> temp;
int assignedNumber = 0;
int order = 0;
input >> assignedNumber;
......
......@@ -23,6 +23,8 @@ public:
// the lan number to the mappings.
void addLan(int lanNumber);
void dispatch(void);
int getLanCount(void);
void setTree(void);
private:
struct OrderCount
{
......@@ -31,10 +33,10 @@ private:
int count;
};
private:
void parseError(std::istream & input);
void mapHosts(void);
void printGraph(std::ostream & output);
void getNumbering(std::istream & input);
void parseError(std::istream & error);
private:
int number;
int address;
......
This diff is collapsed.
......@@ -15,7 +15,9 @@
#include <vector>
#include <list>
#include <map>
#include <set>
#include <cstdlib>
#include <memory>
#include <signal.h>
#include <sys/wait.h>
......@@ -24,25 +26,26 @@ struct Lan
{
Lan() : number(0),
partition(-1),
assignment(0)/*,
isNamingPoint(false),
isTreeRoot(false),
parentIndex(0),
assignment(0),
time (0) {}
time (0)*/ {}
// This is the index of the LAN in the great LAN array.
int number;
// The partition index number of the LAN.
int partition;
// A list of host keys used by the LAN.
std::list<std::string> hosts;
// The address assigned to this LAN. Used as part of the IP address.
int assignment;
/*
// Whether this LAN names a partition or not.
bool isNamingPoint;
// Whether this LAN is part of a tree or a cycle.
bool isTreeRoot;
// The index of the parent of this LAN in the DFS tree.
int parentIndex;
// The address assigned to this LAN. Used as part of the IP address.
int assignment;
// The time that this LAN was visited in the DFS tree.
int time;
// This is the hostname that is the edge currently being explored
......@@ -55,13 +58,79 @@ struct Lan
// current host we are exploring. Previously explored hosts will
// never be touched again.
std::string forwardEdge;
*/
};
struct Pred
{
enum Visited
{
// This is the initial value. Not touched at all.
INITIAL,
// This interface has been visited, but is not a source.
VISIT,
// This interface has been the source of a traversal.
SOURCE
};
Pred() : value(INITIAL) {}
Visited value;
};
struct Host
{
Host() {}
Host() : time(0), forwardEdge(0) {}
// bool touched;
std::string name;
// The int is the index of a Lan.
std::list<int> lans;
int time;
int forwardEdge;
// A mapping from lan number to label number. Each label
// represents an equivalence class of edges.
std::map<int, int> edgeLabels;
typedef std::map<int, int>::iterator EdgeIterator;
typedef std::map<int,
std::list<EdgeIterator> >::iterator PartitionIterator;
// A mapping from equivalence class labels to lists of pointers
// back to edgeLabels. If a is the size of the first set, and b is
// the size of the second set, and n is the number of total edges
// incident upon this host, then this data structure makes merging
// sets O(min(a,b)*log(n)). Actually, that is only true if STL is
// smart about the list splice operation and size. If it isn't
// smart, then we can only achieve O((a + b)*log(n)).
std::map<int, std::list< EdgeIterator > > partitionLists;
// std::map<int, Pred> sources;
};
class StringException : public std::exception
{
public:
explicit StringException(std::string const & error)
: message(error)
{
}
virtual char const * what() const throw()
{
return message.c_str();
}
virtual void addToMessage(char const * addend)
{
message += addend;
}
virtual void addToMessage(string const & addend)
{
addToMessage(addend.c_str());
}
private:
std::string message;
};
struct ComponentVertex
{
ComponentVertex() : number(0) {}
int number;
std::set<int> neighbors;
};
class Partition;
......@@ -70,11 +139,16 @@ namespace g
{
extern std::map<std::string, Host> allHosts;
extern std::vector<Lan> allLans;
extern std::vector<Partition> allPartitions;
extern std::map<int, Partition> allPartitions;
// extern std::map<int, ComponentVertex> partitionGraph;
// pair<source, dest>, edgeNumber
extern std::map< pair<int, int>, int > partitionEdges;
extern std::vector<char*> treeCommand;
extern std::vector<char*> generalCommand;
extern bool useNeato;
extern bool printSize;
}
void init(void);
......@@ -84,10 +158,22 @@ void parseInput(void);
void addLan(int bits, int weights, vector<string> const & nodes);
void breakGraph(void);
void makePartitionGraph(void);
void insertPartitionEdge(int source, int dest, int edgeNumber);
void findNumbers(void);
void numberPartitions(void);
void printError(std::istream & error);
void printPartitionGraph(std::ostream & output);
void getPartitionAddresses(std::istream & input);
void ouputAddresses(void);
void normalOutput(void);
void neatoOutput(void);
void sizeOutput(void);
class FileT;
void auto_assign(std::auto_ptr<FileT> & left, std::auto_ptr<FileT> right);
#endif
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