Skip to content

Commit

Permalink
use gain cache constant to determine whether entries must be recomputed
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Maas committed Sep 7, 2023
1 parent 28884a8 commit 01445f7
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion mt-kahypar/partition/deep_multilevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ void bipartition_each_block(typename TypeTraits::PartitionedHypergraph& partitio
return true;
}(), "Cut of extracted blocks does not sum up to current objective");

if ( gain_cache.isInitialized() ) {
if ( GainCache::invalidates_entries && gain_cache.isInitialized() ) {
partitioned_hg.doParallelForAllNodes([&](const HypernodeID& hn) {
gain_cache.recomputeInvalidTerms(partitioned_hg, hn);
});
Expand Down
16 changes: 10 additions & 6 deletions mt-kahypar/partition/refinement/fm/global_rollback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ namespace mt_kahypar {
});

// recompute penalty term values since they are potentially invalid
tbb::parallel_for(MoveID(0), numMoves, [&](const MoveID i) {
gain_cache.recomputeInvalidTerms(phg, move_order[i].node);
});
if constexpr (GainCache::invalidates_entries) {
tbb::parallel_for(MoveID(0), numMoves, [&](const MoveID i) {
gain_cache.recomputeInvalidTerms(phg, move_order[i].node);
});
}

sharedData.moveTracker.reset();

Expand Down Expand Up @@ -482,9 +484,11 @@ namespace mt_kahypar {
}
});

tbb::parallel_for(0U, numMoves, [&](const MoveID i) {
gain_cache.recomputeInvalidTerms(phg, move_order[i].node);
});
if constexpr (GainCache::invalidates_entries) {
tbb::parallel_for(0U, numMoves, [&](const MoveID i) {
gain_cache.recomputeInvalidTerms(phg, move_order[i].node);
});
}

tracker.reset();

Expand Down
3 changes: 1 addition & 2 deletions mt-kahypar/partition/refinement/fm/multitry_kway_fm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ namespace mt_kahypar {
return true;
}());

if (!PartitionedHypergraph::is_graph) {
// TODO: for new objective functions the recalculation might also be necessary for graphs...
if constexpr (GainCache::invalidates_entries) {
tbb::parallel_for(MoveID(0), sharedData.moveTracker.numPerformedMoves(), [&](const MoveID i) {
gain_cache.recomputeInvalidTerms(phg, sharedData.moveTracker.moveOrder[i].node);
});
Expand Down
1 change: 1 addition & 0 deletions mt-kahypar/partition/refinement/gains/cut/cut_gain_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class CutGainCache {
static constexpr GainPolicy TYPE = GainPolicy::cut;
static constexpr bool requires_notification_before_update = false;
static constexpr bool initializes_gain_cache_entry_after_batch_uncontractions = false;
static constexpr bool invalidates_entries = true;

CutGainCache() :
_is_initialized(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class GraphCutGainCache {
static constexpr GainPolicy TYPE = GainPolicy::cut_for_graphs;
static constexpr bool requires_notification_before_update = false;
static constexpr bool initializes_gain_cache_entry_after_batch_uncontractions = false;
static constexpr bool invalidates_entries = false;

using AdjacentBlocksIterator = IntegerRangeIterator<PartitionID>::const_iterator;

Expand Down
1 change: 1 addition & 0 deletions mt-kahypar/partition/refinement/gains/km1/km1_gain_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Km1GainCache {
static constexpr GainPolicy TYPE = GainPolicy::km1;
static constexpr bool requires_notification_before_update = false;
static constexpr bool initializes_gain_cache_entry_after_batch_uncontractions = false;
static constexpr bool invalidates_entries = true;

Km1GainCache() :
_is_initialized(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class SoedGainCache {
static constexpr GainPolicy TYPE = GainPolicy::soed;
static constexpr bool requires_notification_before_update = false;
static constexpr bool initializes_gain_cache_entry_after_batch_uncontractions = false;
static constexpr bool invalidates_entries = true;

SoedGainCache() :
_is_initialized(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class SteinerTreeGainCache {
static constexpr GainPolicy TYPE = GainPolicy::steiner_tree;
static constexpr bool requires_notification_before_update = true;
static constexpr bool initializes_gain_cache_entry_after_batch_uncontractions = true;
static constexpr bool invalidates_entries = true;

SteinerTreeGainCache() :
_is_initialized(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class GraphSteinerTreeGainCache {
static constexpr GainPolicy TYPE = GainPolicy::steiner_tree_for_graphs;
static constexpr bool requires_notification_before_update = true;
static constexpr bool initializes_gain_cache_entry_after_batch_uncontractions = true;
static constexpr bool invalidates_entries = false;

GraphSteinerTreeGainCache() :
_is_initialized(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace mt_kahypar {
Metrics& best_metrics,
vec<vec<Move>>& rebalance_moves_by_part) {
Metrics current_metrics = best_metrics;
const bool should_update_gain_cache = !PartitionedHypergraph::is_graph && _gain_cache.isInitialized();
const bool should_update_gain_cache = GainCache::invalidates_entries && _gain_cache.isInitialized();
_visited_he.reset();
_next_active.reset();
_gain.reset();
Expand Down Expand Up @@ -202,7 +202,7 @@ namespace mt_kahypar {
timer.stop_timer("rebalance_lp");
DBG << "[LP] Imbalance after rebalancing: " << current_metrics.imbalance << ", quality: " << current_metrics.quality;

const bool should_update_gain_cache = !PartitionedHypergraph::is_graph && _gain_cache.isInitialized();
const bool should_update_gain_cache = GainCache::invalidates_entries && _gain_cache.isInitialized();
if (current_metrics.quality > best_metrics.quality) { // rollback and stop LP
auto noop_obj_fn = [](const SynchronizedEdgeUpdate&) { };
current_metrics = best_metrics;
Expand Down

0 comments on commit 01445f7

Please sign in to comment.