Skip to content

Commit 268f4b1

Browse files
committed
Support to dump reorderd mapping that is compatible with DBG.
1 parent 7ccdfe9 commit 268f4b1

File tree

5 files changed

+5105122
-4
lines changed

5 files changed

+5105122
-4
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*o
2+
*log
3+
*map
4+
Gorder
5+
*el

Graph.cpp

+56-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
2323
namespace Gorder
2424
{
2525

26+
string Graph::getDegree(bool deg) {
27+
return (deg ? "indegree" : "outdegree");
28+
}
29+
30+
bool Graph::indegree_gorder=1; // reordering based on indegree if 1, outdegree if 0
31+
32+
bool Graph::terminate_after_map = false; // terminate application after reordering mapping is computed
33+
34+
2635
string Graph::getFilename(){
2736
return name;
2837
}
@@ -65,6 +74,7 @@ void Graph::readGraph(const string& fullname) {
6574
vector< pair<int, int> > edges;
6675
edges.reserve(100000000);
6776

77+
#if 0
6878
while(feof(fp)!=true){
6979
if(fgets(line, 40, fp)){
7080
u=v=0;
@@ -86,6 +96,30 @@ void Graph::readGraph(const string& fullname) {
8696
edges.push_back(make_pair(u, v));
8797
}
8898
}
99+
#else
100+
ifstream ifs(fullname.c_str(), std::ifstream::in);
101+
while (ifs.good()) {
102+
u=v=0;
103+
ifs >> u >> v;
104+
if(u==v)
105+
continue;
106+
edgenum++;
107+
if(u>vsize)
108+
vsize=u;
109+
if(v>vsize)
110+
vsize=v;
111+
112+
if ( Graph::indegree_gorder ) {
113+
edges.push_back(make_pair(u, v));
114+
} else {
115+
edges.push_back(make_pair(v, u));
116+
}
117+
}
118+
if (edges[edgenum-1].first == 0 && edges[edgenum-1].second == 0) {
119+
edgenum--;
120+
edges.pop_back();
121+
}
122+
#endif
89123
vsize++;
90124

91125
fclose(fp);
@@ -141,8 +175,7 @@ void Graph::readGraph(const string& fullname) {
141175
graph[vsize].instart=edgenum;
142176
}
143177

144-
void Graph::Transform(){
145-
vector<int> order;
178+
void Graph::Transform(vector<int>& order){
146179
RCMOrder(order);
147180
if(order.size()!=vsize){
148181
cout << "order.size()!=vsize" << endl;
@@ -225,6 +258,27 @@ void Graph::writeGraph(ostream& out){
225258
}
226259

227260

261+
void Graph::PrintTwoDirectionMap(const vector<int>& rcm_order, const vector<int>& gorder_order) {
262+
string degree_type = Graph::getDegree(Graph::indegree_gorder);
263+
string f_map = name+"_gorder_"+degree_type+".map";
264+
265+
if ( rcm_order.size() != gorder_order.size() ) {
266+
cout << "Map size does not match: " << rcm_order.size() << gorder_order.size() << endl;
267+
quit();
268+
}
269+
cout << "Writing file: " << f_map << endl;
270+
ofstream out_map(f_map.c_str());
271+
out_map << vsize << endl;
272+
out_map << edgenum << endl;
273+
for (int i = 0; i < gorder_order.size() ; i++ ) {
274+
out_map << i << "\t" << gorder_order[rcm_order[i]] << endl;
275+
}
276+
if (terminate_after_map) {
277+
cout << "Exiting early as instructed!" << endl;
278+
exit(0);
279+
}
280+
}
281+
228282
void Graph::PrintReOrderedGraph(const vector<int>& order){
229283
ofstream out((name+"_Gorder.txt").c_str());
230284

Graph.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,16 @@ class Graph{
8080

8181
void GapCount();
8282
double GapCost(vector<int>& order);
83-
void Transform();
83+
void Transform(vector<int>& rcm_order);
84+
void PrintTwoDirectionMap(const vector<int>& rcm_order, const vector<int>& gorder);
8485
void GorderGreedy(vector<int>& order, int window);
8586

8687
void RCMOrder(vector<int>& order);
8788
unsigned long long LocalityScore(const int w);
89+
90+
static bool terminate_after_map;
91+
static bool indegree_gorder;
92+
static string getDegree(bool);
8893
};
8994

9095
}

0 commit comments

Comments
 (0)