Skip to content

Commit 60be2cc

Browse files
committed
Flows: fix bottleneck from refiner construction
1 parent e8d7735 commit 60be2cc

3 files changed

Lines changed: 22 additions & 13 deletions

File tree

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ HyperedgeWeight FlowRefinementScheduler<GraphAndGainTypes>::runFlowSearch(Partit
219219
auto start = std::chrono::high_resolution_clock::now();
220220
if ( sub_hg.numNodes() > 0 ) {
221221
auto partitioned_hg = utils::partitioned_hg_const_cast(phg);
222+
223+
if (_refiner[refiner_idx] == nullptr) {
224+
_refiner[refiner_idx] = constructFlowRefiner();
225+
}
222226
_refiner[refiner_idx]->initialize(partitioned_hg);
223227
_refiner[refiner_idx]->updateTimeLimit(time_limit);
224228
MoveSequence sequence = _refiner[refiner_idx]->refine(partitioned_hg, sub_hg, start);
@@ -366,13 +370,6 @@ void FlowRefinementScheduler<GraphAndGainTypes>::initializeImpl(mt_kahypar_parti
366370
phg.partWeight(i), _context.partition.max_part_weights[i]);
367371
}
368372

369-
// Initialize Refiners
370-
for (auto& refiner: _refiner) {
371-
if ( refiner == nullptr ) {
372-
refiner = constructFlowRefiner();
373-
}
374-
}
375-
376373
// Initialize Quotient Graph and Scheduler
377374
_stats.reset();
378375
utils::Timer& timer = utils::Utilities::instance().getTimer(_context.utility_id);

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,18 @@ FlowProblem FlowRefiner<GraphAndGainTypes>::constructFlowHypergraph(const Partit
157157

158158
const bool sequential = _context.shared_memory.num_threads == _context.refinement.flows.num_parallel_searches;
159159
if ( sequential ) {
160-
flow_problem = _sequential_construction.constructFlowHypergraph(
160+
if ( _sequential_construction == nullptr ) {
161+
_sequential_construction = std::make_unique<SequentialConstruction<GraphAndGainTypes>>(
162+
_num_hyperedges, _flow_hg, _sequential_hfc, _context);
163+
}
164+
flow_problem = _sequential_construction->constructFlowHypergraph(
161165
phg, sub_hg, _block_0, _block_1, _whfc_to_node);
162166
} else {
163-
flow_problem = _parallel_construction.constructFlowHypergraph(
167+
if ( _parallel_construction == nullptr ) {
168+
_parallel_construction = std::make_unique<ParallelConstruction<GraphAndGainTypes>>(
169+
_num_hyperedges, _flow_hg, _parallel_hfc, _context);
170+
}
171+
flow_problem = _parallel_construction->constructFlowHypergraph(
164172
phg, sub_hg, _block_0, _block_1, _whfc_to_node);
165173
}
166174

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#pragma once
2929

30+
#include <memory>
31+
3032
#include <tbb/concurrent_vector.h>
3133

3234
#include "WHFC/algorithm/hyperflowcutter.h"
@@ -57,14 +59,15 @@ class FlowRefiner final : public IFlowRefiner {
5759
const Context& context) :
5860
_phg(nullptr),
5961
_context(context),
62+
_num_hyperedges(num_hyperedges),
6063
_block_0(kInvalidPartition),
6164
_block_1(kInvalidPartition),
6265
_flow_hg(),
6366
_sequential_hfc(_flow_hg, context.partition.seed),
6467
_parallel_hfc(_flow_hg, context.partition.seed),
6568
_whfc_to_node(),
66-
_sequential_construction(num_hyperedges, _flow_hg, _sequential_hfc, context),
67-
_parallel_construction(num_hyperedges, _flow_hg, _parallel_hfc, context) {
69+
_sequential_construction(nullptr),
70+
_parallel_construction(nullptr) {
6871
_sequential_hfc.find_most_balanced = _context.refinement.flows.find_most_balanced_cut;
6972
_sequential_hfc.timer.active = false;
7073
_sequential_hfc.forceSequential(true);
@@ -111,14 +114,15 @@ class FlowRefiner final : public IFlowRefiner {
111114
const Context& _context;
112115
using IFlowRefiner::_time_limit;
113116

117+
HyperedgeID _num_hyperedges;
114118
PartitionID _block_0;
115119
PartitionID _block_1;
116120
FlowHypergraphBuilder _flow_hg;
117121
whfc::HyperFlowCutter<whfc::SequentialPushRelabel> _sequential_hfc;
118122
whfc::HyperFlowCutter<whfc::ParallelPushRelabel> _parallel_hfc;
119123

120124
vec<HypernodeID> _whfc_to_node;
121-
SequentialConstruction<GraphAndGainTypes> _sequential_construction;
122-
ParallelConstruction<GraphAndGainTypes> _parallel_construction;
125+
std::unique_ptr<SequentialConstruction<GraphAndGainTypes>> _sequential_construction;
126+
std::unique_ptr<ParallelConstruction<GraphAndGainTypes>> _parallel_construction;
123127
};
124128
} // namespace mt_kahypar

0 commit comments

Comments
 (0)