Skip to content

Commit

Permalink
Merge pull request #163 from kahypar/compiletimes
Browse files Browse the repository at this point in the history
FM refactoring and compile times reduction
  • Loading branch information
N-Maas authored Oct 4, 2023
2 parents bf24f75 + f7fe3c6 commit aa1dbb0
Show file tree
Hide file tree
Showing 63 changed files with 930 additions and 1,134 deletions.
2 changes: 1 addition & 1 deletion mt-kahypar/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_subdirectory(partition)
add_subdirectory(datastructures)
add_subdirectory(io)
add_subdirectory(partition)
add_subdirectory(utils)

foreach(modtarget IN LISTS PARTITIONING_SUITE_TARGETS)
Expand Down
14 changes: 0 additions & 14 deletions mt-kahypar/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,13 @@ using TypeTraitsList = kahypar::meta::Typelist<StaticHypergraphTypeTraits
ENABLE_HIGHEST_QUALITY(template class C<DynamicPartitionedHypergraph>;) \
ENABLE_HIGHEST_QUALITY_FOR_GRAPHS(template class C<DynamicPartitionedGraph>;)

#define INSTANTIATE_CLASS_MACRO_WITH_TYPE_TRAITS(C) \
template class C(StaticHypergraphTypeTraits); \
ENABLE_GRAPHS(template class C(StaticGraphTypeTraits);) \
ENABLE_HIGHEST_QUALITY(template class C(DynamicHypergraphTypeTraits);) \
ENABLE_HIGHEST_QUALITY_FOR_GRAPHS(template class C(DynamicGraphTypeTraits);) \
ENABLE_LARGE_K(template class C(LargeKHypergraphTypeTraits);)

#define INSTANTIATE_CLASS_WITH_TYPE_TRAITS(C) \
template class C<StaticHypergraphTypeTraits>; \
ENABLE_GRAPHS(template class C<StaticGraphTypeTraits>;) \
ENABLE_HIGHEST_QUALITY(template class C<DynamicHypergraphTypeTraits>;) \
ENABLE_HIGHEST_QUALITY_FOR_GRAPHS(template class C<DynamicGraphTypeTraits>;) \
ENABLE_LARGE_K(template class C<LargeKHypergraphTypeTraits>;)

#define INSTANTIATE_CLASS_MACRO_WITH_TYPE_TRAITS_AND_OTHER_CLASS(C, Other) \
template class C(StaticHypergraphTypeTraits, Other); \
ENABLE_GRAPHS(template class C(StaticGraphTypeTraits, Other);) \
ENABLE_HIGHEST_QUALITY(template class C(DynamicHypergraphTypeTraits, Other);) \
ENABLE_HIGHEST_QUALITY_FOR_GRAPHS(template class C(DynamicGraphTypeTraits, Other);) \
ENABLE_LARGE_K(template class C(LargeKHypergraphTypeTraits, Other);)


using HighResClockTimepoint = std::chrono::time_point<std::chrono::high_resolution_clock>;

Expand Down
5 changes: 0 additions & 5 deletions mt-kahypar/io/command_line_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,6 @@ namespace mt_kahypar {
po::value<size_t>((initial_partitioning ? &context.initial_partitioning.refinement.fm.multitry_rounds :
&context.refinement.fm.multitry_rounds))->value_name("<size_t>")->default_value(10),
"Number of FM rounds within one level of the multilevel hierarchy.")
((initial_partitioning ? "i-r-fm-perform-moves-global" : "r-fm-perform-moves-global"),
po::value<bool>((initial_partitioning ? &context.initial_partitioning.refinement.fm.perform_moves_global :
&context.refinement.fm.perform_moves_global))->value_name("<bool>")->default_value(false),
"If true, then all moves performed during FM are immediately visible to other searches.\n"
"Otherwise, only move sequences that yield an improvement are applied to the global view of the partition.")
((initial_partitioning ? "i-r-fm-seed-nodes" : "r-fm-seed-nodes"),
po::value<size_t>((initial_partitioning ? &context.initial_partitioning.refinement.fm.num_seed_nodes :
&context.refinement.fm.num_seed_nodes))->value_name("<size_t>")->default_value(25),
Expand Down
1 change: 0 additions & 1 deletion mt-kahypar/io/sql_plottools_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ std::string serialize(const PartitionedHypergraph& hypergraph,
<< " sync_lp_use_active_node_set=" << context.refinement.deterministic_refinement.use_active_node_set;
oss << " fm_algorithm=" << context.refinement.fm.algorithm
<< " fm_multitry_rounds=" << context.refinement.fm.multitry_rounds
<< " fm_perform_moves_global=" << std::boolalpha << context.refinement.fm.perform_moves_global
<< " fm_rollback_parallel=" << std::boolalpha << context.refinement.fm.rollback_parallel
<< " fm_rollback_sensitive_to_num_moves=" << std::boolalpha << context.refinement.fm.iter_moves_on_recalc
<< " fm_rollback_balance_violation_factor=" << context.refinement.fm.rollback_balance_violation_factor
Expand Down
8 changes: 7 additions & 1 deletion mt-kahypar/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
template<bool T = EXPR> \
std::enable_if_t<!T, TYPE>

#if defined(__GNUC__) || defined(__clang__)
#if (defined(__GNUC__) || defined(__clang__)) && defined(NDEBUG)
#define MT_KAHYPAR_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline)) inline
#else
#define MT_KAHYPAR_ATTRIBUTE_ALWAYS_INLINE
Expand Down Expand Up @@ -121,6 +121,9 @@

// In windows unisgned long != size_t
#define UL(X) (size_t) X
#ifdef STR
#undef STR
#endif
#define STR(X) std::to_string(X)
#define STREAM2STR(X) static_cast<std::stringstream>(X).str();

Expand All @@ -133,6 +136,9 @@
#define BOLD "\033[1m"
#define END "\033[0m"
#define INFO(msg) LOG << CYAN << "[INFO]" << END << msg
#ifdef WARNING
#undef WARNING
#endif
#define WARNING(msg) LOG << YELLOW << "[WARNING]" << END << msg
#define ERR(msg) LOG << RED << "[ERROR]" << END << msg; std::exit(-1)

Expand Down
2 changes: 1 addition & 1 deletion mt-kahypar/partition/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_subdirectory(mapping)
add_subdirectory(registries)

set(PartitionSources
deep_multilevel.cpp
partitioner.cpp
partitioner_facade.cpp
multilevel.cpp
Expand All @@ -14,7 +15,6 @@ set(PartitionSources
conversion.cpp
metrics.cpp
recursive_bipartitioning.cpp
deep_multilevel.cpp
)

foreach(modtarget IN LISTS PARTITIONING_SUITE_TARGETS)
Expand Down
4 changes: 4 additions & 0 deletions mt-kahypar/partition/coarsening/multilevel_uncoarsener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ namespace mt_kahypar {
improvement_found = false;
const HyperedgeWeight metric_before = _current_metrics.quality;

if ( _rebalancer && _context.refinement.rebalancer != RebalancingAlgorithm::do_nothing ) {
_rebalancer->initialize(phg);
}

if ( _label_propagation && _context.refinement.label_propagation.algorithm != LabelPropagationAlgorithm::do_nothing ) {
_timer.start_timer("initialize_lp_refiner", "Initialize LP Refiner");
_label_propagation->initialize(phg);
Expand Down
3 changes: 3 additions & 0 deletions mt-kahypar/partition/coarsening/nlevel_uncoarsener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ namespace mt_kahypar {
// Initialize Refiner
mt_kahypar_partitioned_hypergraph_t phg =
utils::partitioned_hg_cast(*_uncoarseningData.partitioned_hg);
if ( _rebalancer ) {
_rebalancer->initialize(phg);
}
if ( _label_propagation ) {
_label_propagation->initialize(phg);
}
Expand Down
1 change: 1 addition & 0 deletions mt-kahypar/partition/coarsening/nlevel_uncoarsener.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "mt-kahypar/partition/refinement/i_refiner.h"
#include "mt-kahypar/partition/coarsening/coarsening_commons.h"
#include "mt-kahypar/datastructures/streaming_vector.h"
#include "mt-kahypar/utils/progress_bar.h"

namespace mt_kahypar {

Expand Down
20 changes: 15 additions & 5 deletions mt-kahypar/partition/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ namespace mt_kahypar {
str << " Algorithm: " << params.algorithm << std::endl;
if ( params.algorithm != LabelPropagationAlgorithm::do_nothing ) {
str << " Maximum Iterations: " << params.maximum_iterations << std::endl;
str << " Unconstrained: " << std::boolalpha << params.unconstrained << std::endl;
str << " Rebalancing: " << std::boolalpha << params.rebalancing << std::endl;
str << " HE Size Activation Threshold: " << std::boolalpha << params.hyperedge_size_activation_threshold << std::endl;
str << " Relative Improvement Threshold: " << params.relative_improvement_threshold << std::endl;
}
return str;
}
Expand All @@ -134,7 +136,6 @@ namespace mt_kahypar {
out << " Algorithm: " << params.algorithm << std::endl;
if ( params.algorithm != FMAlgorithm::do_nothing ) {
out << " Multitry Rounds: " << params.multitry_rounds << std::endl;
out << " Perform Moves Globally: " << std::boolalpha << params.perform_moves_global << std::endl;
out << " Parallel Global Rollbacks: " << std::boolalpha << params.rollback_parallel << std::endl;
out << " Rollback Bal. Violation Factor: " << params.rollback_balance_violation_factor << std::endl;
out << " Num Seed Nodes: " << params.num_seed_nodes << std::endl;
Expand All @@ -144,6 +145,19 @@ namespace mt_kahypar {
out << " Release Nodes: " << std::boolalpha << params.release_nodes << std::endl;
out << " Time Limit Factor: " << params.time_limit_factor << std::endl;
}
if ( params.algorithm == FMAlgorithm::unconstrained_fm ) {
out << " Unconstrained Rounds: " << params.unconstrained_rounds << std::endl;
out << " Threshold Border Node Inclusion: " << params.treshold_border_node_inclusion << std::endl;
out << " Minimum Imbalance Penalty Factor: " << params.imbalance_penalty_min << std::endl;
out << " Maximum Imbalance Penalty Factor: " << params.imbalance_penalty_max << std::endl;
out << " Start Upper Bound for Unc.: " << params.unconstrained_upper_bound << std::endl;
out << " Final Upper Bound for Unc.: " << params.unconstrained_upper_bound_min << std::endl;
out << " Unc. Minimum Improvement Factor: " << params.unconstrained_min_improvement << std::endl;
out << " Activate Unc. Dynamically: " << std::boolalpha << params.activate_unconstrained_dynamically << std::endl;
if ( params.activate_unconstrained_dynamically ) {
out << " Penalty for Activation Test: " << params.penalty_for_activation_test << std::endl;
}
}
out << std::flush;
return out;
}
Expand Down Expand Up @@ -525,7 +539,6 @@ namespace mt_kahypar {
// initial partitioning -> refinement -> fm
initial_partitioning.refinement.fm.algorithm = FMAlgorithm::kway_fm;
initial_partitioning.refinement.fm.multitry_rounds = 5;
initial_partitioning.refinement.fm.perform_moves_global = false;
initial_partitioning.refinement.fm.rollback_parallel = true;
initial_partitioning.refinement.fm.rollback_balance_violation_factor = 1;
initial_partitioning.refinement.fm.num_seed_nodes = 25;
Expand Down Expand Up @@ -553,7 +566,6 @@ namespace mt_kahypar {
refinement.fm.algorithm = FMAlgorithm::unconstrained_fm;
refinement.fm.multitry_rounds = 10;
refinement.fm.unconstrained_rounds = 8;
refinement.fm.perform_moves_global = false;
refinement.fm.rollback_parallel = true;
refinement.fm.rollback_balance_violation_factor = 1.0;
refinement.fm.treshold_border_node_inclusion = 0.7;
Expand Down Expand Up @@ -756,7 +768,6 @@ namespace mt_kahypar {
// initial partitioning -> refinement -> fm
initial_partitioning.refinement.fm.algorithm = FMAlgorithm::kway_fm;
initial_partitioning.refinement.fm.multitry_rounds = 5;
initial_partitioning.refinement.fm.perform_moves_global = false;
initial_partitioning.refinement.fm.rollback_parallel = false;
initial_partitioning.refinement.fm.rollback_balance_violation_factor = 1;
initial_partitioning.refinement.fm.num_seed_nodes = 5;
Expand Down Expand Up @@ -786,7 +797,6 @@ namespace mt_kahypar {
// refinement -> fm
refinement.fm.algorithm = FMAlgorithm::kway_fm;
refinement.fm.multitry_rounds = 10;
refinement.fm.perform_moves_global = false;
refinement.fm.rollback_parallel = false;
refinement.fm.rollback_balance_violation_factor = 1.25;
refinement.fm.num_seed_nodes = 5;
Expand Down
10 changes: 4 additions & 6 deletions mt-kahypar/partition/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ std::ostream & operator<< (std::ostream& str, const CoarseningParameters& params
struct LabelPropagationParameters {
LabelPropagationAlgorithm algorithm = LabelPropagationAlgorithm::do_nothing;
size_t maximum_iterations = 1;
bool unconstrained = false;
bool rebalancing = true;
bool execute_sequential = false;
bool unconstrained = false;
size_t hyperedge_size_activation_threshold = std::numeric_limits<size_t>::max();
double relative_improvement_threshold = -1.0;
};
Expand All @@ -152,25 +152,23 @@ struct FMParameters {
double min_improvement = -1.0;
double time_limit_factor = std::numeric_limits<double>::max();

bool perform_moves_global = false;
bool rollback_parallel = true;
bool iter_moves_on_recalc = false;
bool shuffle = true;
mutable bool obey_minimal_parallelism = false;
bool release_nodes = true;

double treshold_border_node_inclusion = 0.75;
double unconstrained_upper_bound = 0.0;

// unconstrained
size_t unconstrained_rounds = 1;
double treshold_border_node_inclusion = 0.75;
double imbalance_penalty_min = 0.2;
double imbalance_penalty_max = 1.0;
double unconstrained_upper_bound = 0.0;
double unconstrained_upper_bound_min = 0.0;
double unconstrained_min_improvement = -1.0;

bool activate_unconstrained_dynamically = false;
double penalty_for_activation_test = 0.5;
double unconstrained_min_improvement = -1.0;
};

std::ostream& operator<<(std::ostream& out, const FMParameters& params);
Expand Down
Loading

0 comments on commit aa1dbb0

Please sign in to comment.