From 0c7d172c1a4a8eb734b84df909e974921ac608f4 Mon Sep 17 00:00:00 2001 From: Daniel Seemaier Date: Wed, 30 Oct 2024 10:44:46 +0100 Subject: [PATCH 1/2] refactor(app): already validate -G (file must exist) and -k (must be greater than 1) via CLI11 validators --- apps/KaMinPar.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/KaMinPar.cc b/apps/KaMinPar.cc index 3ed8d1bc..7c993d0d 100644 --- a/apps/KaMinPar.cc +++ b/apps/KaMinPar.cc @@ -94,8 +94,10 @@ The output should be stored in a file and can be used by the -C,--config option. auto *gp_group = mandatory->add_option_group("Partitioning")->silent(); gp_group->add_option("-k,--k", app.k, "Number of blocks in the partition.") ->configurable(false) + ->check(CLI::Range(static_cast(2), std::numeric_limits::max())) ->required(); gp_group->add_option("-G,--graph", app.graph_filename, "Input graph in METIS format.") + ->check(CLI::ExistingFile) ->configurable(false); // Application options @@ -103,7 +105,7 @@ The output should be stored in a file and can be used by the -C,--config option. ->default_val(app.seed); cli.add_flag("-q,--quiet", app.quiet, "Suppress all console output."); cli.add_option("-t,--threads", app.num_threads, "Number of threads to be used.") - ->check(CLI::NonNegativeNumber) + ->check(CLI::PositiveNumber) ->default_val(app.num_threads); cli.add_flag("-E,--experiment", app.experiment, "Use an output format that is easier to parse."); cli.add_flag( From f8ffba193a7dae411a883d5067727c3f644fd359 Mon Sep 17 00:00:00 2001 From: Daniel Seemaier Date: Wed, 30 Oct 2024 11:37:09 +0100 Subject: [PATCH 2/2] refactor(app): only warn when partitioning graphs with more than 2^31 edges with a 32 bit edge weight build rather than crashing (only an issue for very large cuts) --- apps/KaMinPar.cc | 6 ++++++ kaminpar-dist/context_io.cc | 6 ++---- kaminpar-shm/context_io.cc | 5 ++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/KaMinPar.cc b/apps/KaMinPar.cc index 7c993d0d..36a89420 100644 --- a/apps/KaMinPar.cc +++ b/apps/KaMinPar.cc @@ -268,6 +268,12 @@ int main(int argc, char *argv[]) { shm::validate_undirected_graph(graph); } + if (static_cast(graph.m()) > + static_cast(std::numeric_limits::max())) { + LOG_WARNING << "The edge weight type is not large enough to store the sum of all edge weights. " + << "This might cause overflows for very large cuts."; + } + RECORD("partition") std::vector partition(graph.n()); RECORD_LOCAL_DATA_STRUCT(partition, partition.capacity() * sizeof(BlockID)); STOP_HEAP_PROFILER(); diff --git a/kaminpar-dist/context_io.cc b/kaminpar-dist/context_io.cc index 3ac3dd5d..f40b9fbf 100644 --- a/kaminpar-dist/context_io.cc +++ b/kaminpar-dist/context_io.cc @@ -328,8 +328,7 @@ void print(const PartitionContext &ctx, const bool root, std::ostream &out, MPI_ if (root) { out << " Number of global nodes: " << std::setw(width) << ctx.graph->global_n; - if (asserting_cast(ctx.graph->global_n) == - ctx.graph->global_total_node_weight) { + if (static_cast(ctx.graph->global_n) == ctx.graph->global_total_node_weight) { out << " (unweighted)\n"; } else { out << " (total weight: " << ctx.graph->global_total_node_weight << ")\n"; @@ -337,8 +336,7 @@ void print(const PartitionContext &ctx, const bool root, std::ostream &out, MPI_ out << " + ghost nodes: " << std::setw(width) << num_global_total_nodes - ctx.graph->global_n << "\n"; out << " Number of global edges: " << std::setw(width) << ctx.graph->global_m; - if (asserting_cast(ctx.graph->global_m) == - ctx.graph->global_total_edge_weight) { + if (static_cast(ctx.graph->global_m) == ctx.graph->global_total_edge_weight) { out << " (unweighted)\n"; } else { out << " (total weight: " << ctx.graph->global_total_edge_weight << ")\n"; diff --git a/kaminpar-shm/context_io.cc b/kaminpar-shm/context_io.cc index 0205e2e1..a359b8b1 100644 --- a/kaminpar-shm/context_io.cc +++ b/kaminpar-shm/context_io.cc @@ -13,7 +13,6 @@ #include "kaminpar-shm/kaminpar.h" -#include "kaminpar-common/asserting_cast.h" #include "kaminpar-common/console_io.h" #include "kaminpar-common/random.h" #include "kaminpar-common/strutils.h" @@ -574,13 +573,13 @@ void print(const PartitionContext &p_ctx, std::ostream &out) { const std::size_t width = size > 0 ? std::ceil(std::log10(size)) : 1; out << " Number of nodes: " << std::setw(width) << p_ctx.n; - if (asserting_cast(p_ctx.n) == p_ctx.total_node_weight) { + if (static_cast(p_ctx.n) == p_ctx.total_node_weight) { out << " (unweighted)\n"; } else { out << " (total weight: " << p_ctx.total_node_weight << ")\n"; } out << " Number of edges: " << std::setw(width) << p_ctx.m; - if (asserting_cast(p_ctx.m) == p_ctx.total_edge_weight) { + if (static_cast(p_ctx.m) == p_ctx.total_edge_weight) { out << " (unweighted)\n"; } else { out << " (total weight: " << p_ctx.total_edge_weight << ")\n";