Skip to content

Commit

Permalink
Hand change_size to strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
T3C42 committed Dec 3, 2024
1 parent 345678d commit deb196d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
10 changes: 5 additions & 5 deletions mt-kahypar/dynamic/dynamic_partitioner.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace mt_kahypar::dyn {
ds::StaticHypergraph& hypergraph_s = utils::cast<ds::StaticHypergraph>(hypergraph);

// If the number of changes is not specified or is greater than the number of changes in the file, we process all the changes
size_t changes_size = context.dynamic.max_changes == 0 ? changes.size() : std::min((size_t) context.dynamic.max_changes, changes.size());
size_t max_changes = context.dynamic.max_changes == 0 ? changes.size() : std::min((size_t) context.dynamic.max_changes, changes.size());

DynamicStrategy* strategy;

Expand All @@ -35,13 +35,13 @@ namespace mt_kahypar::dyn {

try {

std::cout << "Processing " << context.dynamic.max_changes << " changes" << std::endl;
std::cout << "Processing " << max_changes << " changes" << std::endl;

for (size_t i = 0; i < changes_size; ++i) {
for (size_t i = 0; i < max_changes; ++i) {
Change& change = changes[i];
strategy->partition(hypergraph_s, context, change);
strategy->partition(hypergraph_s, context, change, max_changes);
if (!context.dynamic.server && *(&strategy->history.back().valid)) {
print_progress_bar(i, context.dynamic.max_changes, &strategy->history);
print_progress_bar(i, max_changes, &strategy->history);
}
log_km1_live(i, context, strategy->history.back());
}
Expand Down
2 changes: 1 addition & 1 deletion mt-kahypar/dynamic/dynamic_strategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace mt_kahypar::dyn {
* The strategy should partition the hypergraph according to the change.
* The strategy should update the history vector with the result of the partitioning.
*/
virtual void partition(ds::StaticHypergraph &hypergraph, Context &context, Change change) = 0;
virtual void partition(ds::StaticHypergraph &hypergraph, Context &context, Change change, size_t changes_size) = 0;

/*
* A Strategy can print final statistics after the last partitioning step.
Expand Down
2 changes: 1 addition & 1 deletion mt-kahypar/dynamic/strategies/connectivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace mt_kahypar::dyn {
}
public:

void partition(ds::StaticHypergraph& hypergraph, Context& context, Change change) override {
void partition(ds::StaticHypergraph& hypergraph, Context& context, Change change, size_t changes_size) override {

//on first call, initialize partitioned_hypergraph_s
if (!partitioned_hypergraph_s) {
Expand Down
3 changes: 2 additions & 1 deletion mt-kahypar/dynamic/strategies/lokalFM.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace mt_kahypar::dyn {
std::unique_ptr<IRebalancer> _rebalancer;

void repartition(ds::StaticHypergraph& hypergraph_s, Context& context) {
std::cout << "Repartitioning" << std::endl;
partitioned_hypergraph_s = partition_hypergraph_km1(hypergraph_s, context);
_gain_cache = GainCachePtr::constructGainCache(context);
_rebalancer = RebalancerFactory::getInstance().createObject(
Expand Down Expand Up @@ -74,7 +75,7 @@ namespace mt_kahypar::dyn {

public:

void partition(ds::StaticHypergraph& hypergraph, Context& context, Change change) override {
void partition(ds::StaticHypergraph& hypergraph, Context& context, Change change, size_t changes_size) override {

//on first call, initialize partitioned_hypergraph_s
if (!partitioned_hypergraph_s) {
Expand Down
2 changes: 1 addition & 1 deletion mt-kahypar/dynamic/strategies/never_repartition.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace mt_kahypar::dyn {
}
public:

void partition(ds::StaticHypergraph& hypergraph, Context& context, Change change) override {
void partition(ds::StaticHypergraph& hypergraph, Context& context, Change change, size_t changes_size) override {

//on first call, initialize partitioned_hypergraph_s
if (!partitioned_hypergraph_s) {
Expand Down
8 changes: 6 additions & 2 deletions mt-kahypar/dynamic/strategies/repartition.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ namespace mt_kahypar::dyn {
private:
size_t skipped_changes = 0;
size_t initial_num_enabled_nodes = 0;
size_t step_size = 0;
public:

void partition(ds::StaticHypergraph& hypergraph, Context& context, Change change) override {
void partition(ds::StaticHypergraph& hypergraph, Context& context, Change change, size_t changes_size) override {

process_change(hypergraph, context, change);
PartitionResult partition_result = *new PartitionResult();
Expand All @@ -23,7 +24,10 @@ namespace mt_kahypar::dyn {
}
}

auto step_size = static_cast<size_t>(context.dynamic.step_size_pct * context.dynamic.max_changes);
if (step_size == 0) {
size_t max_changes = context.dynamic.max_changes == 0 ? changes_size : std::min((size_t) context.dynamic.max_changes, changes_size);
step_size = static_cast<size_t>(context.dynamic.step_size_pct * max_changes);
}

if (skipped_changes < step_size) {
partition_result.valid = false;
Expand Down

0 comments on commit deb196d

Please sign in to comment.