Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions kaminpar-shm/refinement/balancer/overload_balancer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ std::pair<BlockID, float> OverloadBalancer::compute_best_gain(
}
});

if (best_block == kInvalidBlockID) {
best_block = from;
}

return std::make_pair(best_block, compute_relative_gain(best_gain, weight));
}

Expand Down Expand Up @@ -269,6 +273,9 @@ bool OverloadBalancer::add_to_pq(
bool OverloadBalancer::move_node_if_possible(
const NodeID node, const BlockID from, const BlockID to
) {
KASSERT(node < _p_graph->n());
KASSERT(to < _p_graph->k());

if (_p_graph->move(node, from, to, _p_ctx->max_block_weight(to))) {
if (_move_tracker != nullptr) {
_move_tracker(node, from, to);
Expand Down
7 changes: 4 additions & 3 deletions kaminpar-shm/refinement/balancer/overload_balancer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class OverloadBalancer : public Refiner {
template <typename ConcretizedGraph>
using GainCache = OnTheFlyGainCache<
ConcretizedGraph,
/*iterate_nonadjacent_blocks=*/true,
/*iterate_exact_gains=*/true>;
/*iterate_nonadjacent_blocks=*/false,
/*iterate_exact_gains=*/true,
/*iterate_source_block=*/true>;

public:
using MoveTracker = std::function<void(NodeID, BlockID, BlockID)>;
Expand All @@ -40,7 +41,7 @@ class OverloadBalancer : public Refiner {
OverloadBalancer(const OverloadBalancer &) = delete;

OverloadBalancer &operator=(OverloadBalancer &&) = delete;
OverloadBalancer(OverloadBalancer &&) noexcept = default;
OverloadBalancer(OverloadBalancer &&) noexcept = delete;

[[nodiscard]] std::string name() const final;

Expand Down
5 changes: 3 additions & 2 deletions kaminpar-shm/refinement/balancer/underload_balancer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class UnderloadBalancer : public Refiner {
template <typename ConcretizedGraph>
using GainCache = OnTheFlyGainCache<
ConcretizedGraph,
/*iterate_nonadjacent_blocks=*/true,
/*iterate_exact_gains=*/true>;
/*iterate_nonadjacent_blocks=*/false,
/*iterate_exact_gains=*/true,
/*iterate_source_block=*/true>;

public:
explicit UnderloadBalancer(const Context &ctx);
Expand Down
8 changes: 5 additions & 3 deletions kaminpar-shm/refinement/gains/on_the_fly_gain_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ template <typename GainCache> class OnTheFlyDeltaGainCache;
template <
typename GraphType,
bool iterate_nonadjacent_blocks = true,
bool iterate_exact_gains = true>
bool iterate_exact_gains = true,
bool iterate_source_block = false>
class OnTheFlyGainCache {
template <typename> friend class OnTheFlyDeltaGainCache;

Expand All @@ -32,6 +33,7 @@ class OnTheFlyGainCache {

constexpr static bool kIteratesNonadjacentBlocks = iterate_nonadjacent_blocks;
constexpr static bool kIteratesExactGains = iterate_exact_gains;
constexpr static bool kIteratesSourceBlock = iterate_source_block;

OnTheFlyGainCache(const Context & /* ctx */, NodeID /* max_n */, const BlockID preallocate_k)
: _rating_map_ets([preallocate_k] {
Expand Down Expand Up @@ -159,13 +161,13 @@ class OnTheFlyGainCache {

if constexpr (kIteratesNonadjacentBlocks) {
for (const BlockID to : p_graph.blocks()) {
if (to != from) {
if (kIteratesSourceBlock || to != from) {
lambda(to, [&] { return map[to] - conn_from; });
}
}
} else {
for (const auto [to, conn_to] : map.entries()) {
if (to != from) {
if (kIteratesSourceBlock || to != from) {
lambda(to, [&, conn_to = conn_to] { return conn_to - conn_from; });
}
}
Expand Down
Loading