Skip to content

Commit

Permalink
more fixeS
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSeemaier committed Nov 27, 2024
1 parent 4115356 commit aa1e208
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 37 deletions.
3 changes: 3 additions & 0 deletions kaminpar-shm/partitioning/deep/deep_multilevel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ PartitionedGraph DeepMultilevelPartitioner::initial_partition(const Graph *graph
}();
ENABLE_TIMERS();

// @todo for communities
_current_p_ctx = create_kway_context(_input_ctx, p_graph);
DBG << debug::describe_partition_state(p_graph, _current_p_ctx);

Expand Down Expand Up @@ -346,6 +347,8 @@ void DeepMultilevelPartitioner::extend_partition(PartitionedGraph &p_graph, cons
_bipartitioner_pool
);
_current_p_ctx = create_kway_context(_input_ctx, p_graph);
DBG << "Partition state after partial extend completion to " << k_prime << " blocks:";
DBG << debug::describe_partition_state(p_graph, _current_p_ctx);
}

if (_input_ctx.partitioning.use_lazy_subgraph_memory) {
Expand Down
97 changes: 62 additions & 35 deletions kaminpar-shm/partitioning/deep/vcycle_deep_multilevel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,49 @@ namespace {

SET_DEBUG(true);

std::vector<BlockWeight> compute_max_block_weights(
const BlockID current_k,
const PartitionContext &input_p_ctx,
const std::vector<BlockWeight> &next_block_weights
) {
const int level = math::floor_log2(current_k);
const BlockID expanded_blocks = current_k - (1 << level);

std::vector<BlockWeight> max_block_weights(current_k);
if (current_k == input_p_ctx.k) {
for (BlockID b = 0; b < current_k; ++b) {
max_block_weights[b] = input_p_ctx.max_block_weight(b);
}
} else {
BlockID cur_begin = 0;
for (BlockID b = 0; b < current_k; ++b) {
const BlockID num_sub_blocks = [&] {
if (b < 2 * expanded_blocks) {
const BlockID next_k =
std::min<BlockID>(math::ceil2(current_k), next_block_weights.size());
return partitioning::compute_final_k(b, next_k, next_block_weights.size());
} else {
return partitioning::compute_final_k(
b - expanded_blocks, math::floor2(current_k), next_block_weights.size()
);
}
}();

const BlockID cur_end = cur_begin + num_sub_blocks;
max_block_weights[b] = std::accumulate(
next_block_weights.begin() + cur_begin, next_block_weights.begin() + cur_end, 0
);

DBG << "block " << b << ": aggregate weight for " << num_sub_blocks << " of "
<< next_block_weights.size() << " blocks when partitioning for the " << current_k
<< " v-cycle = " << max_block_weights[b];

cur_begin = cur_end;
}
}
return max_block_weights;
}

} // namespace

VcycleDeepMultilevelPartitioner::VcycleDeepMultilevelPartitioner(
Expand All @@ -38,42 +81,26 @@ PartitionedGraph VcycleDeepMultilevelPartitioner::partition() {
Context ctx = _input_ctx;
ctx.partitioning.mode = PartitioningMode::DEEP;

for (const BlockID current_k : steps) {
{
const int level = math::floor_log2(current_k);
const BlockID expanded_blocks = current_k - (1 << level);
std::vector<std::vector<BlockWeight>> vcycle_block_weights;

std::vector<BlockWeight> max_block_weights(current_k);
if (current_k == _input_ctx.partition.k) {
for (BlockID b = 0; b < current_k; ++b) {
max_block_weights[b] = _input_ctx.partition.max_block_weight(b);
}
} else {
BlockID cur_begin = 0;
for (BlockID b = 0; b < current_k; ++b) {
const BlockID num_sub_blocks = [&] {
if (b < 2 * expanded_blocks) {
const BlockID next_k = std::min(math::ceil2(current_k), _input_ctx.partition.k);
return partitioning::compute_final_k(b, next_k, _input_ctx.partition.k);
} else {
return partitioning::compute_final_k(
b - expanded_blocks, math::floor2(current_k), _input_ctx.partition.k
);
}
}();

const BlockID cur_end = cur_begin + num_sub_blocks;
max_block_weights[b] =
_input_ctx.partition.total_unrelaxed_max_block_weights(cur_begin, cur_end);

DBG << "block " << b << ": aggregate weight for " << num_sub_blocks << " of "
<< _input_ctx.partition.k << " blocks when partitioning for the " << current_k
<< " v-cycle = " << max_block_weights[b];

cur_begin = cur_end;
}
}
ctx.partition.setup(_input_graph, std::move(max_block_weights));
for (auto it = steps.rbegin(); it != steps.rend(); ++it) {
const BlockID current_k = *it;
if (vcycle_block_weights.empty()) {
vcycle_block_weights.push_back(compute_max_block_weights(current_k, _input_ctx.partition, {})
);
} else {
auto &prev_block_weights = vcycle_block_weights.back();
vcycle_block_weights.push_back(
compute_max_block_weights(current_k, _input_ctx.partition, prev_block_weights)
);
}
}

std::size_t i = 0;
for (const BlockID _ : steps) {
{
ctx.partition.set_epsilon(-1.0);
ctx.partition.setup(_input_graph, std::move(vcycle_block_weights[i++]));
}

if (communities.empty()) {
Expand Down
6 changes: 4 additions & 2 deletions kaminpar-shm/partitioning/helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ void complete_partial_extend_partition(
SCOPED_TIMER("Initial partitioning");
const BlockID current_k = p_graph.k();

DBG << "Complete partial extend_partition() for k=" << current_k << " to k=" << input_ctx.partition.k;

if (current_k == input_ctx.partition.k || math::is_power_of_2(current_k)) {
return;
}
Expand Down Expand Up @@ -484,9 +486,9 @@ void complete_partial_extend_partition(
subgraph,
subgraph_partitions[b],
0,
b,
prev_b,
subgraph_k,
p_graph.k(),
prev_current_k,
input_ctx,
{.nodes_start_pos = 0, .edges_start_pos = 0},
subgraph_memory,
Expand Down

0 comments on commit aa1e208

Please sign in to comment.