Skip to content

Commit

Permalink
imbalance
Browse files Browse the repository at this point in the history
  • Loading branch information
Sepideh Maleki committed Feb 22, 2021
1 parent 5d1370f commit 49a59a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 61 deletions.
48 changes: 2 additions & 46 deletions lonestar/analytics/cpu/bipart/Refine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,6 @@

namespace {

// This is only used on the terminal graph (find graph)
// Should workd for hmetis

/*int calculate_cutsize(GGraph& g) {
GNodeBag bag;
galois::do_all(galois::iterate(g.getNets()),
[&](GNode n) {
auto c = g.edges(n).begin();
GNode cn = g.getEdgeDst(*c);
int part = g.getData(cn).getPart();
for (auto x : g.edges(n)) {
auto cc = g.getEdgeDst(x);
int partc = g.getData(cc).getPart();
if (partc != part) {
bag.push(n);
return;
}
}
},
galois::loopname("cutsize"));
return std::distance(bag.begin(), bag.end());
}*/

/*int calculate_cutsize(GGraph& g, std::map<GNode, unsigned> part) {
GNodeBag bag;
galois::do_all(galois::iterate(g.getNets()),
[&](GNode n) {
auto c = g.edges(n).begin();
GNode cn = g.getEdgeDst(*c);
unsigned ppart = part[cn];
for (auto x : g.edges(n, galois::MethodFlag::UNPROTECTED)) {
auto cc = g.getEdgeDst(x);
unsigned partc = part[cc];
if (partc != ppart) {
bag.push(n);
return;
}
}
},
galois::steal(), galois::loopname("cutsize"));
return std::distance(bag.begin(), bag.end());
}*/
void projectPart(MetisGraph* Graph) {
GGraph* fineGraph = Graph->getFinerGraph()->getGraph();
GGraph* coarseGraph = Graph->getGraph();
Expand Down Expand Up @@ -578,12 +534,12 @@ bool isPT(int n) {
return (ceil(log2(n)) == floor(log2(n)));
}

void refine(MetisGraph* coarseGraph, unsigned K) {
void refine(MetisGraph* coarseGraph, unsigned K, double imbalance) {
float ratio = 0.0f;
float tol = 0.0f;
bool flag = isPT(K);
if (flag) {
ratio = 55.0 / 45.0; // change if needed
ratio = (50.0f + (double) imbalance)/(50.0f - (double) imbalance);
tol = std::max(ratio, 1 - ratio) - 1;
} else {
ratio = ((float)((K + 1) / 2)) / ((float)(K / 2)); // change if needed
Expand Down
30 changes: 16 additions & 14 deletions lonestar/analytics/cpu/bipart/bipart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static cll::opt<scheduleMode> schedulingMode(
clEnumVal(MDEG, "MDEG"), clEnumVal(DEG, "DEG"),
clEnumVal(MWD, "MWD"), clEnumVal(HIS, "HIS"),
clEnumVal(RAND, "random")),
cll::init(PLD));
cll::init(RAND));

static cll::opt<bool>
mtxInput("mtxinput",
Expand Down Expand Up @@ -84,8 +84,8 @@ static cll::opt<unsigned> numPartitions(cll::Positional,
cll::init(2));
static cll::opt<double> imbalance(
"balance",
cll::desc("Fraction deviated from mean partition size (default 0.01)"),
cll::init(0.01));
cll::desc("Percentage deviated from mean partition size (default 5)"),
cll::init(5.0));

//! Flag that forces user to be aware that they should be passing in a
//! hMetis graph.
Expand Down Expand Up @@ -119,7 +119,7 @@ void Partition(MetisGraph* metisGraph, unsigned coarsenTo, unsigned K) {

galois::StatTimer T3("Refine");
T3.start();
refine(mcg, K);
refine(mcg, K, imbalance);
T3.stop();
Ctime += (T.get()/1000.0f);
Ptime += (T2.get()/1000.0f);
Expand Down Expand Up @@ -148,15 +148,17 @@ int computingCut(GGraph& g) {
}

int computingBalance(GGraph& g) {
int zero = 0, one = 0;
int max = 0;
std::vector<int> parts(numPartitions, 0);
for (size_t c = g.hedges; c < g.size(); c++) {
int part = g.getData(c).getPart();
if (part == 0)
zero++;
else
one++;
unsigned pp = g.getData(c).getPart();
parts[pp]++;
}
return std::abs(zero - one);
for (unsigned i = 0; i <numPartitions; i++) {
if (parts[i] > max)
max = parts[i];
}
return max;
}
// printGraphBeg(*graph)

Expand Down Expand Up @@ -330,7 +332,7 @@ int main(int argc, char** argv) {
std::vector<std::vector<GNode>> nodesvec(k);
// std::array<std::vector<GNode>, 100> hedgesvec;

for (int level = 1; level < num; level++) {
for (int level = 0; level < num; level++) {

for (int i = 0; i < k; i++)
nodesvec[i].clear();
Expand Down Expand Up @@ -493,8 +495,8 @@ int main(int argc, char** argv) {
std::cout<<"Edge Cut,"<<computingCut(graph)<<"\n\n";

galois::runtime::reportStat_Single("BiPart", "Edge Cut", computingCut(graph));
galois::runtime::reportStat_Single("BiPart", "zero-one",
computingBalance(graph));
//galois::runtime::reportStat_Single("BiPart", "zero-one",
// computingBalance(graph));

totalTime.stop();
if (output) {
Expand Down
2 changes: 1 addition & 1 deletion lonestar/analytics/cpu/bipart/bipart.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,6 @@ MetisGraph* coarsen(MetisGraph* fineMetisGraph, unsigned coarsenTo,
// Partitioning
void partition(MetisGraph*, unsigned);
// Refinement
void refine(MetisGraph* coarseGraph, unsigned K);
void refine(MetisGraph* coarseGraph, unsigned K, double imbalance);

#endif

0 comments on commit 49a59a6

Please sign in to comment.