Skip to content

Commit 4186ef3

Browse files
committed
Flows: simplify construction of flow refiners
1 parent 788b6d1 commit 4186ef3

5 files changed

Lines changed: 9 additions & 43 deletions

File tree

mt-kahypar/partition/factories.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "mt-kahypar/partition/initial_partitioning/i_initial_partitioner.h"
3434
#include "mt-kahypar/partition/refinement/i_refiner.h"
3535
#include "mt-kahypar/partition/refinement/i_rebalancer.h"
36-
#include "mt-kahypar/partition/refinement/flows/i_flow_refiner.h"
3736
#include "mt-kahypar/partition/refinement/fm/fm_commons.h"
3837
#include "mt-kahypar/partition/refinement/fm/strategies/i_fm_strategy.h"
3938
#include "mt-kahypar/partition/refinement/gains/gain_cache_ptr.h"
@@ -64,6 +63,4 @@ using FlowSchedulerFactory = mt_kahypar::ThreadSafeFactory<FlowAlgorithm,
6463

6564
using RebalancerFactory = mt_kahypar::ThreadSafeFactory<RebalancingAlgorithm, IRebalancer* (*)(HypernodeID, const Context&, gain_cache_t)>;
6665

67-
using FlowRefinementFactory = mt_kahypar::ThreadSafeFactory<FlowAlgorithm,
68-
IFlowRefiner* (*)(const HyperedgeID, const Context&)>;
6966
} // namespace mt_kahypar

mt-kahypar/partition/refinement/flows/flow_refinement_scheduler.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#include <chrono>
3030

3131
#include "mt-kahypar/definitions.h"
32-
#include "mt-kahypar/partition/factories.h"
3332
#include "mt-kahypar/partition/metrics.h"
33+
#include "mt-kahypar/partition/refinement/flows/flow_refiner.h"
3434
#include "mt-kahypar/partition/refinement/gains/gain_definitions.h"
3535
#include "mt-kahypar/io/partitioning_output.h"
3636
#include "mt-kahypar/utils/utilities.h"
@@ -373,8 +373,7 @@ void FlowRefinementScheduler<GraphAndGainTypes>::initializeImpl(mt_kahypar_parti
373373
// Initialize Refiners
374374
for (auto& refiner: _refiner) {
375375
if ( refiner == nullptr ) {
376-
refiner = FlowRefinementFactory::getInstance().createObject(
377-
_context.refinement.flows.algorithm, _num_hyperedges, _context);
376+
refiner = constructFlowRefiner();
378377
}
379378
}
380379

@@ -407,6 +406,11 @@ void FlowRefinementScheduler<GraphAndGainTypes>::resizeDataStructuresForCurrentK
407406
}
408407
}
409408

409+
template<typename GraphAndGainTypes>
410+
std::unique_ptr<IFlowRefiner> FlowRefinementScheduler<GraphAndGainTypes>::constructFlowRefiner() {
411+
return std::make_unique<FlowRefiner<GraphAndGainTypes>>(_num_hyperedges, _context);
412+
}
413+
410414
namespace {
411415

412416
template<typename PartitionedHypergraph, typename GainCache, typename F>

mt-kahypar/partition/refinement/flows/flow_refinement_scheduler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class FlowRefinementScheduler final : public IRefiner {
118118

119119
void resizeDataStructuresForCurrentK();
120120

121+
std::unique_ptr<IFlowRefiner> constructFlowRefiner();
122+
121123
template<typename F>
122124
HyperedgeWeight runFlowSearch(PartitionedHypergraph& phg,
123125
utils::Timer& timer,

mt-kahypar/partition/registries/register_refinement_algorithms.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include "mt-kahypar/partition/refinement/fm/strategies/unconstrained_strategy.h"
4444
#include "mt-kahypar/partition/refinement/flows/do_nothing_refiner.h"
4545
#include "mt-kahypar/partition/refinement/flows/flow_refinement_scheduler.h"
46-
#include "mt-kahypar/partition/refinement/flows/flow_refiner.h"
4746
#include "mt-kahypar/partition/refinement/gains/gain_definitions.h"
4847
#include "mt-kahypar/partition/refinement/rebalancing/simple_rebalancer.h"
4948
#include "mt-kahypar/partition/refinement/rebalancing/advanced_rebalancer.h"
@@ -103,11 +102,6 @@ using AdvancedRebalancerDispatcher = kahypar::meta::StaticMultiDispatchFactory<
103102
IRebalancer,
104103
kahypar::meta::Typelist<GraphAndGainTypesList>>;
105104

106-
using FlowRefinementDispatcher = kahypar::meta::StaticMultiDispatchFactory<
107-
FlowRefiner,
108-
IFlowRefiner,
109-
kahypar::meta::Typelist<GraphAndGainTypesList>>;
110-
111105

112106
#define REGISTER_DISPATCHED_LP_REFINER(id, dispatcher, ...) \
113107
kahypar::meta::Registrar<LabelPropagationFactory> register_ ## dispatcher( \
@@ -213,23 +207,6 @@ using FlowRefinementDispatcher = kahypar::meta::StaticMultiDispatchFactory<
213207
return new refiner(num_hypernodes, context, gain_cache); \
214208
})
215209

216-
#define REGISTER_DISPATCHED_FLOW_REFINER(id, dispatcher, ...) \
217-
kahypar::meta::Registrar<FlowRefinementFactory> register_ ## dispatcher( \
218-
id, \
219-
[](const HyperedgeID num_hyperedges, const Context& context) { \
220-
return dispatcher::create( \
221-
std::forward_as_tuple(num_hyperedges, context), \
222-
__VA_ARGS__ \
223-
); \
224-
})
225-
226-
#define REGISTER_FLOW_REFINER(id, refiner, t) \
227-
kahypar::meta::Registrar<FlowRefinementFactory> JOIN(register_ ## refiner, t)( \
228-
id, \
229-
[](const HyperedgeID num_Hyperedges, const Context& context) -> IFlowRefiner* { \
230-
return new refiner(num_Hyperedges, context); \
231-
})
232-
233210

234211
kahypar::meta::PolicyBase& getGraphAndGainTypesPolicy(mt_kahypar_partition_type_t partition_type, GainPolicy gain_policy) {
235212
switch ( partition_type ) {
@@ -287,11 +264,6 @@ void register_refinement_algorithms() {
287264
AdvancedRebalancerDispatcher,
288265
getGraphAndGainTypesPolicy(context.partition.partition_type, context.partition.gain_policy));
289266
REGISTER_REBALANCER(RebalancingAlgorithm::do_nothing, DoNothingRefiner, 5);
290-
291-
REGISTER_DISPATCHED_FLOW_REFINER(FlowAlgorithm::flow_cutter,
292-
FlowRefinementDispatcher,
293-
getGraphAndGainTypesPolicy(context.partition.partition_type, context.partition.gain_policy));
294-
REGISTER_FLOW_REFINER(FlowAlgorithm::do_nothing, DoNothingFlowRefiner, 6);
295267
}
296268

297269
} // namespace mt_kahypar

tests/partition/refinement/flow_refiner_mock.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,4 @@ class FlowRefinerMock final : public IFlowRefiner {
110110
RefineFunc _refine_func;
111111
};
112112

113-
#define REGISTER_FLOW_REFINER(id, refiner, t) \
114-
static kahypar::meta::Registrar<FlowRefinementFactory> JOIN(register_ ## refiner, t)( \
115-
id, \
116-
[](const HyperedgeID num_hyperedges, const Context& context) -> IFlowRefiner* { \
117-
return new refiner(num_hyperedges, context); \
118-
})
119-
120-
REGISTER_FLOW_REFINER(FlowAlgorithm::mock, FlowRefinerMock, 1);
121-
122113
} // namespace mt_kahypar

0 commit comments

Comments
 (0)