Skip to content

Commit

Permalink
par: avoid outputting empty partitions when there's weight discrepanc…
Browse files Browse the repository at this point in the history
…y between vertices

Signed-off-by: Arthur Koucher <arthurkoucher@precisioninno.com>
  • Loading branch information
AcKoucher committed Dec 18, 2024
1 parent e3ab3fb commit e7c60c3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/par/src/Partitioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,30 @@ void Partitioner::RandomPart(const HGraphPtr& hgraph,
vertices.insert(vertices.begin(), path_vertices.begin(), path_vertices.end());

if (vile_mode == false) {
std::vector<float> total_vertices_weight(hgraph->GetVertexDimensions(),
0.0f);
for (const auto& v : vertices) {
total_vertices_weight
= total_vertices_weight + hgraph->GetVertexWeights(v);
}

// try to generate balanced random partitioning
int block_id = 0;
for (const auto& v : vertices) {
solution[v] = block_id;
block_balance[block_id]
= block_balance[block_id] + hgraph->GetVertexWeights(v);
const int previous_block_id = block_id;
if (block_balance[block_id] >= lower_block_balance[block_id]) {
block_id++;
block_id = block_id % num_parts_; // adjust the block_id
if (block_balance[previous_block_id] == total_vertices_weight) {
solution[v] = block_id;
block_balance[block_id]
= block_balance[block_id] + hgraph->GetVertexWeights(v);
block_balance[previous_block_id]
= block_balance[previous_block_id] - hgraph->GetVertexWeights(v);
}
}
}
} else {
Expand All @@ -195,10 +210,11 @@ void Partitioner::RandomPart(const HGraphPtr& hgraph,
bool stop_flag = false;
for (const auto& v : vertices) {
solution[v] = block_id;
const std::vector<float> previous_block_balance = block_balance[block_id];
block_balance[block_id]
= block_balance[block_id] + hgraph->GetVertexWeights(v);
if (block_balance[block_id] >= upper_block_balance[block_id]
&& stop_flag == false) {
&& stop_flag == false && !equal(previous_block_balance, 0.0f)) {
block_id++;
solution[v] = block_id; // move the vertex to next block
if (block_id == num_parts_ - 1) {
Expand Down
11 changes: 11 additions & 0 deletions src/par/src/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ void Accumulate(std::vector<float>& a, const std::vector<float>& b)
std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::plus<float>());
}

bool equal(const std::vector<float>& vertex_weights, const float value)
{
for (const float dimension_weight : vertex_weights) {
if (dimension_weight != value) {
return false;
}
}

return true;
}

// weighted sum
std::vector<float> WeightedSum(const std::vector<float>& a,
const float a_factor,
Expand Down
2 changes: 2 additions & 0 deletions src/par/src/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ std::vector<std::string> SplitLine(const std::string& line);
// Add right vector to left vector
void Accumulate(std::vector<float>& a, const std::vector<float>& b);

bool equal(const std::vector<float>& vertex_weights, const float value);

// weighted sum
std::vector<float> WeightedSum(const std::vector<float>& a,
float a_factor,
Expand Down

0 comments on commit e7c60c3

Please sign in to comment.