Skip to content

Commit

Permalink
Merge branch 'dist/debug/jet-refiner' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSeemaier committed Nov 28, 2023
2 parents 24ac42b + bd18b6e commit db8ef38
Show file tree
Hide file tree
Showing 75 changed files with 1,785 additions and 1,904 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,-modernize-use-trailing-return-type,-cppcoreguidelines-pro-bounds-pointer-arithmetic'
Checks: 'clang-diagnostic-*,clang-analyzer-*,modernize-*,-modernize-use-trailing-return-type,-cppcoreguidelines-pro-bounds-pointer-arithmetic'
WarningsAsErrors: false
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
Expand Down
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ option(KAMINPAR_BUILD_BENCHMARKS "Build benchmark binaries." OFF)
# Control how to build
######################
option(KAMINPAR_ENABLE_STATISTICS "Generate and output detailed statistics." ON)
option(KAMINPAR_ENABLE_TIMER_BARRIERS "Add additional MPI_Barrier() instructions for more accurate time measurements." ON)

option(KAMINPAR_BUILD_WITH_ASAN "Enable address sanitizer." OFF)
option(KAMINPAR_BUILD_WITH_MTUNE_NATIVE "Build with -mtune=native." ON)
Expand Down Expand Up @@ -121,6 +122,13 @@ else ()
message(STATIS "Statistics: disabled")
endif ()

if (KAMINPAR_ENABLE_TIMER_BARRIERS)
list(APPEND KAMINPAR_DEFINITIONS "-DKAMINPAR_ENABLE_TIMER_BARRIERS")
message(STATUS "Timer barriers: enabled")
else ()
message(STATUS "Timer barriers: disabled")
endif ()

if (KAMINPAR_64BIT_NODE_IDS OR KAMINPAR_64BIT_IDS)
list(APPEND KAMINPAR_DEFINITIONS "-DKAMINPAR_64BIT_NODE_IDS")
set(KAMINPAR_SHM_NODE_ID_STR "std::uint64_t")
Expand Down Expand Up @@ -234,8 +242,6 @@ if ((KAMINPAR_BUILD_DISTRIBUTED AND KAMINPAR_BUILD_APPS) OR KAMINPAR_BUILD_BENCH
add_subdirectory(external/KaGen EXCLUDE_FROM_ALL)
endif ()

message("--------------------------------------------------------------------------------")

################################################################################
## Add targets in subdirectories ##
################################################################################
Expand Down
42 changes: 18 additions & 24 deletions kaminpar-cli/dkaminpar_arguments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ CLI::Option_group *create_refinement_options(CLI::App *app, Context &ctx) {
create_lp_refinement_options(app, ctx);
create_colored_lp_refinement_options(app, ctx);
create_jet_refinement_options(app, ctx);
create_mtkahypar_refinement_options(app, ctx);
create_node_balancer_options(app, ctx);
create_cluster_balancer_options(app, ctx);

Expand All @@ -159,25 +160,6 @@ CLI::Option_group *create_fm_refinement_options(CLI::App *app, Context &ctx) {
"--r-fm-alpha", ctx.refinement.fm.alpha, "Alpha parameter for the adaptive stopping rule."
)
->capture_default_str();
fm->add_flag(
"--r-fm-overlap-regions",
ctx.refinement.fm.overlap_regions,
"Allow search regions to overlap."
)
->capture_default_str();
fm->add_option(
"--r-fm-bound-degree",
ctx.refinement.fm.bound_degree,
"Add at most this many neighbors of a high-degree node to the search "
"region."
)
->capture_default_str();
fm->add_flag(
"--r-fm-contract-border",
ctx.refinement.fm.contract_border,
"Contract the exterior of the search graph"
)
->capture_default_str();

fm->add_flag("--r-fm-independent-seeds", ctx.refinement.fm.use_independent_seeds)
->capture_default_str();
Expand Down Expand Up @@ -613,12 +595,13 @@ CLI::Option_group *create_jet_refinement_options(CLI::App *app, Context &ctx) {

jet->add_option("--r-jet-num-iterations", ctx.refinement.jet.num_iterations)
->capture_default_str();
jet->add_option("--r-jet-min-c", ctx.refinement.jet.min_c)->capture_default_str();
jet->add_option("--r-jet-max-c", ctx.refinement.jet.max_c)->capture_default_str();
jet->add_flag("--r-jet-interpolate-c", ctx.refinement.jet.interpolate_c)->capture_default_str();
jet->add_flag("--r-jet-use-abortion-threshold", ctx.refinement.jet.use_abortion_threshold)
jet->add_option("--r-jet-num-fruitless-iterations", ctx.refinement.jet.num_fruitless_iterations)
->capture_default_str();
jet->add_option("--r-jet-abortion-threshold", ctx.refinement.jet.abortion_threshold)
jet->add_option("--r-jet-fruitless-threshold", ctx.refinement.jet.fruitless_threshold)
->capture_default_str();
jet->add_option("--r-jet-coarse-penalty-factor", ctx.refinement.jet.coarse_negative_gain_factor)
->capture_default_str();
jet->add_option("--r-jet-fine-penalty-factor", ctx.refinement.jet.fine_negative_gain_factor)
->capture_default_str();
jet->add_option("--r-jet-balancing-algorithm", ctx.refinement.jet.balancing_algorithm)
->transform(CLI::CheckedTransformer(get_balancing_algorithms()).description(""))
Expand All @@ -630,4 +613,15 @@ CLI::Option_group *create_jet_refinement_options(CLI::App *app, Context &ctx) {

return jet;
}

CLI::Option_group *create_mtkahypar_refinement_options(CLI::App *app, Context &ctx) {
auto *mtkahypar = app->add_option_group("Refinement -> MtKaHyPar");

mtkahypar->add_option("--r-mtkahypar-config", ctx.refinement.mtkahypar.config_filename)
->capture_default_str();
mtkahypar->add_flag("--r-mtkahypar-only-run-on-root", ctx.refinement.mtkahypar.only_run_on_root)
->capture_default_str();

return mtkahypar;
}
} // namespace kaminpar::dist
2 changes: 2 additions & 0 deletions kaminpar-cli/dkaminpar_arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ CLI::Option_group *create_cluster_balancer_options(CLI::App *app, Context &ctx);

CLI::Option_group *create_jet_refinement_options(CLI::App *app, Context &ctx);

CLI::Option_group *create_mtkahypar_refinement_options(CLI::App *app, Context &ctx);

CLI::Option_group *create_coarsening_options(CLI::App *app, Context &ctx);

CLI::Option_group *create_local_lp_coarsening_options(CLI::App *app, Context &ctx);
Expand Down
16 changes: 2 additions & 14 deletions kaminpar-cli/kaminpar_arguments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,21 +292,9 @@ CLI::Option_group *create_mtkahypar_refinement_options(CLI::App *app, Context &c
CLI::Option_group *create_debug_options(CLI::App *app, Context &ctx) {
auto *debug = app->add_option_group("Debug");

debug
->add_option(
"--d-dump-dir",
ctx.debug.dump_dir,
"Directory in which the dumped graphs and partitions should be stored."
)
->capture_default_str();

debug->add_flag("--d-include-num-threads-in-filename", ctx.debug.include_num_threads_in_filename)
->capture_default_str();
debug->add_flag("--d-include-seed-in-filename", ctx.debug.include_seed_in_filename)
->capture_default_str();
debug->add_flag("--d-include-epsilon-in-filename", ctx.debug.include_epsilon_in_filename)
debug->add_option("--d-dump-graph-filename", ctx.debug.dump_graph_filename)
->capture_default_str();
debug->add_flag("--d-include-k-in-filename", ctx.debug.include_k_in_filename)
debug->add_option("--d-dump-partition-filename", ctx.debug.dump_partition_filename)
->capture_default_str();

debug
Expand Down
16 changes: 16 additions & 0 deletions kaminpar-common/strutils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,20 @@ std::string &ltrim(std::string &s, const char *t) {
std::string &trim(std::string &s, const char *t) {
return ltrim(rtrim(s, t), t);
}

std::string &replace_all(std::string &str, const std::string &replace, const std::string &with) {
for (auto pos = str.find(replace); pos != std::string::npos;
pos = str.find(replace, pos + with.length())) {
str.replace(pos, replace.length(), with);
}
return str;
}

std::string &
replace_all(std::string &str, const std::vector<std::pair<std::string, std::string>> &replacements) {
for (auto &replacement : replacements) {
replace_all(str, replacement.first, replacement.second);
}
return str;
}
} // namespace kaminpar::str
5 changes: 5 additions & 0 deletions kaminpar-common/strutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ std::string implode(const Elements &elements, const std::string &separator) {
}
return ss.str();
}

std::string &replace_all(std::string &str, const std::string &replace, const std::string &with);

std::string &
replace_all(std::string &str, const std::vector<std::pair<std::string, std::string>> &replacements);
} // namespace kaminpar::str
45 changes: 30 additions & 15 deletions kaminpar-dist/coarsening/contraction/cluster_contraction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,11 @@ std::pair<NodeID, PEID> remap_gcnode(
const NoinitVector<GlobalNodeID> &pe_overload,
const NoinitVector<GlobalNodeID> &pe_underload
) {
const NodeID lcnode = static_cast<NodeID>(gcnode - current_cnode_distribution[current_owner]);
const auto lcnode = static_cast<NodeID>(gcnode - current_cnode_distribution[current_owner]);

const NodeID old_current_owner_overload =
const auto old_current_owner_overload =
static_cast<NodeID>(pe_overload[current_owner + 1] - pe_overload[current_owner]);
const NodeID old_current_owner_count = static_cast<NodeID>(
const auto old_current_owner_count = static_cast<NodeID>(
current_cnode_distribution[current_owner + 1] - current_cnode_distribution[current_owner]
);
const auto new_current_owner_count = old_current_owner_count - old_current_owner_overload;
Expand All @@ -562,10 +562,10 @@ std::pair<NodeID, PEID> remap_gcnode(
const GlobalNodeID position = pe_overload[current_owner] + lcnode;
const PEID new_owner =
static_cast<PEID>(math::find_in_distribution<GlobalNodeID>(position, pe_underload));
const NodeID old_new_owner_count = static_cast<NodeID>(
const auto old_new_owner_count = static_cast<NodeID>(
current_cnode_distribution[new_owner + 1] - current_cnode_distribution[new_owner]
);
const NodeID new_lcnode =
const auto new_lcnode =
static_cast<NodeID>(old_new_owner_count + position - pe_underload[new_owner]);
return {new_lcnode, new_owner};
}
Expand All @@ -578,10 +578,10 @@ std::pair<NodeID, PEID> remap_gcnode(
const GlobalNodeID position = pe_overload[current_owner] + lcnode - new_current_owner_count;
const PEID new_owner =
static_cast<PEID>(math::find_in_distribution<GlobalNodeID>(position, pe_underload));
const NodeID old_new_owner_count = static_cast<NodeID>(
const auto old_new_owner_count = static_cast<NodeID>(
current_cnode_distribution[new_owner + 1] - current_cnode_distribution[new_owner]
);
const NodeID new_lcnode =
const auto new_lcnode =
static_cast<NodeID>(old_new_owner_count + position - pe_underload[new_owner]);
return {new_lcnode, new_owner};
}
Expand All @@ -608,12 +608,12 @@ AssignmentShifts compute_assignment_shifts(
pe_overload.front() = 0;
pe_underload.front() = 0;

const NodeID avg_cnode_count = static_cast<NodeID>(c_n / size);
const NodeID max_cnode_count = max_cnode_imbalance * avg_cnode_count;
const auto avg_cnode_count = static_cast<NodeID>(c_n / size);
const auto max_cnode_count = static_cast<NodeID>(max_cnode_imbalance * avg_cnode_count);

// Determine overloaded PEs
tbb::parallel_for<PEID>(0, size, [&](const PEID pe) {
const NodeID cnode_count =
const auto cnode_count =
static_cast<NodeID>(current_cnode_distribution[pe + 1] - current_cnode_distribution[pe]);
pe_overload[pe + 1] = (cnode_count > max_cnode_count) ? cnode_count - max_cnode_count : 0;
pe_load[pe] = {pe, cnode_count};
Expand All @@ -633,9 +633,7 @@ AssignmentShifts compute_assignment_shifts(
PEID num_pes = 0;
BinaryMinHeap<GlobalNodeID> maxes(size);

for (PEID pe = 0; pe < size; ++pe) {
KASSERT(pe + 1 < size || size == 1);

for (PEID pe = 0; pe + 1 < size; ++pe) {
const PEID actual_pe = pe_load[pe].pe;
const GlobalNodeID pe_max =
current_node_distribution[actual_pe + 1] - current_node_distribution[actual_pe];
Expand Down Expand Up @@ -665,18 +663,35 @@ AssignmentShifts compute_assignment_shifts(
} else {
min_load = pe_load[pe].count + std::floor(1.0 * current_overload / num_pes);
plus_ones = current_overload % num_pes;
current_overload = 0;
break;
}
}

if (current_overload > 0) {
// Balancing clusters is not possible due to the constraint that no PE may gain more nodes
// vertices than it has fine nodes (this is not an inherent constraint, but the remaining
// coarsening codes requires is)
// Hacky max_cnode_imbalance increase: @todo compute actual minimum achievable cnode imbalance
// ...
const double new_max_cnode_imbalance =
1.01 * (max_cnode_count + current_overload) / avg_cnode_count;
LOG_WARNING << "Cannot achieve maximum cnode imbalance: this should only ever happen in rare "
"edge cases; increasing maximum cnode imbalance constraint from "
<< max_cnode_imbalance << " to " << new_max_cnode_imbalance;
return compute_assignment_shifts(
current_node_distribution, current_cnode_distribution, new_max_cnode_imbalance
);
}

// Determine underloaded PEs
PEID nth_underloaded = 0;
for (PEID pe = 0; pe < size; ++pe) {
const NodeID cnode_count =
const auto cnode_count =
static_cast<NodeID>(current_cnode_distribution[pe + 1] - current_cnode_distribution[pe]);

if (cnode_count <= min_load) {
const NodeID node_count =
const auto node_count =
static_cast<NodeID>(current_node_distribution[pe + 1] - current_node_distribution[pe]);

pe_underload[pe + 1] = std::min<NodeID>(min_load - cnode_count, node_count - cnode_count);
Expand Down
19 changes: 9 additions & 10 deletions kaminpar-dist/context_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ std::unordered_map<std::string, RefinementAlgorithm> get_kway_refinement_algorit
{"lp/batches", RefinementAlgorithm::BATCHED_LP},
{"lp/colors", RefinementAlgorithm::COLORED_LP},
{"fm/global", RefinementAlgorithm::GLOBAL_FM},
{"fm/local", RefinementAlgorithm::LOCAL_FM},
{"greedy-balancer/nodes", RefinementAlgorithm::GREEDY_NODE_BALANCER},
{"greedy-balancer/clusters", RefinementAlgorithm::GREEDY_CLUSTER_BALANCER},
{"jet/refiner", RefinementAlgorithm::JET_REFINER},
{"jet/balancer", RefinementAlgorithm::JET_BALANCER},
{"mtkahypar", RefinementAlgorithm::MTKAHYPAR},
};
}

Expand All @@ -136,6 +136,7 @@ std::unordered_map<std::string, RefinementAlgorithm> get_balancing_algorithms()
{"greedy-balancer/nodes", RefinementAlgorithm::GREEDY_NODE_BALANCER},
{"greedy-balancer/clusters", RefinementAlgorithm::GREEDY_CLUSTER_BALANCER},
{"jet/balancer", RefinementAlgorithm::JET_BALANCER},
{"mtkahypar", RefinementAlgorithm::MTKAHYPAR},
};
};

Expand All @@ -147,8 +148,6 @@ std::ostream &operator<<(std::ostream &out, const RefinementAlgorithm algorithm)
return out << "lp/batches";
case RefinementAlgorithm::COLORED_LP:
return out << "lp/colors";
case RefinementAlgorithm::LOCAL_FM:
return out << "fm/local";
case RefinementAlgorithm::GLOBAL_FM:
return out << "fm/global";
case RefinementAlgorithm::GREEDY_NODE_BALANCER:
Expand All @@ -159,6 +158,8 @@ std::ostream &operator<<(std::ostream &out, const RefinementAlgorithm algorithm)
return out << "jet/refiner";
case RefinementAlgorithm::JET_BALANCER:
return out << "jet/balancer";
case RefinementAlgorithm::MTKAHYPAR:
return out << "mtkahypar";
}

return out << "<invalid>";
Expand Down Expand Up @@ -464,13 +465,11 @@ void print(const RefinementContext &ctx, const ParallelContext &parallel, std::o
}
if (ctx.includes_algorithm(RefinementAlgorithm::JET_REFINER)) {
out << "Jet refinement: " << RefinementAlgorithm::JET_REFINER << "\n";
out << " Number of iterations: " << ctx.jet.num_iterations << "\n";
out << " C: [" << ctx.jet.min_c << ".." << ctx.jet.max_c << "] "
<< (ctx.jet.interpolate_c ? "interpolate" : "switch") << "\n";
out << " Abortion threshold "
<< (ctx.jet.use_abortion_threshold ? std::to_string(ctx.jet.abortion_threshold) : "disabled"
)
<< "\n";
out << " Number of iterations: max " << ctx.jet.num_iterations << ", or "
<< ctx.jet.num_fruitless_iterations << " fruitless (improvement < "
<< 100.0 * (1 - ctx.jet.fruitless_threshold) << "%)\n";
out << " Penalty factors: coarse " << ctx.jet.coarse_negative_gain_factor
<< ", fine " << ctx.jet.fine_negative_gain_factor << "\n";
out << " Balancing algorithm: " << ctx.jet.balancing_algorithm << "\n";
}
if (ctx.includes_algorithm(RefinementAlgorithm::GLOBAL_FM)) {
Expand Down
Loading

0 comments on commit db8ef38

Please sign in to comment.