Skip to content

Commit

Permalink
make sparsification method selectable
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Rosch committed May 13, 2024
1 parent dae52c8 commit 23563aa
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 6 deletions.
7 changes: 7 additions & 0 deletions kaminpar-cli/kaminpar_arguments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ CLI::Option_group *create_coarsening_options(CLI::App *app, Context &ctx) {
- sparsifying-clustering: like clustering with additionale edge sparsification)")
->capture_default_str();

coarsening->add_option("--c-sparsification", ctx.coarsening.algorithm)
->transform(CLI::CheckedTransformer(get_sparsification_algorithms()).description(""))
->description(R"(One of the following options:
- random: unform random sampling
- forest-fire: sampling by forest fire scores)")
->capture_default_str();

coarsening
->add_option(
"--c-contraction-limit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
namespace kaminpar::shm::sparsification {

StaticArray<EdgeWeight> UniformRandomSampler::sample(const CSRGraph &g) {
unsigned int backedges_deleted = 0;
unsigned int backedges = 0;
unsigned int frontedges = 0;
StaticArray<EdgeWeight> sample = StaticArray<EdgeWeight>(g.m());
unsigned int edges_deleted = 0;
Expand Down
4 changes: 1 addition & 3 deletions kaminpar-shm/coarsening/sparsifing_cluster_coarsener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ SparsifingClusteringCoarsener::SparsifingClusteringCoarsener(
const Context &ctx, const PartitionContext &p_ctx
)
: _clustering_algorithm(factory::create_clusterer(ctx)),
_sampling_algorithm(std::make_unique<sparsification::ForestFireSampler>(
sparsification::ForestFireSampler(0.3, 0.9, 0.01)
)),
_sampling_algorithm(factory::create_sampler(ctx)),
_c_ctx(ctx.coarsening),
_p_ctx(p_ctx) {}

Expand Down
7 changes: 7 additions & 0 deletions kaminpar-shm/context_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ std::unordered_map<std::string, CoarseningAlgorithm> get_coarsening_algorithms()
};
}

std::unordered_map<std::string, SparsificationAlgorithm> get_sparsification_algorithms() {
return {
{"forest-fire", SparsificationAlgorithm::FOREST_FIRE},
{"random", SparsificationAlgorithm::UNIFORM_RANDOM_SAMPLING}
};
}

std::ostream &operator<<(std::ostream &out, const CoarseningAlgorithm algorithm) {
switch (algorithm) {
case CoarseningAlgorithm::NOOP:
Expand Down
2 changes: 2 additions & 0 deletions kaminpar-shm/context_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ std::ostream &operator<<(std::ostream &out, CoarseningAlgorithm algorithm);

std::unordered_map<std::string, CoarseningAlgorithm> get_coarsening_algorithms();

std::unordered_map<std::string, SparsificationAlgorithm> get_sparsification_algorithms();

std::ostream &operator<<(std::ostream &out, ClusteringAlgorithm algorithm);

std::unordered_map<std::string, ClusteringAlgorithm> get_clustering_algorithms();
Expand Down
13 changes: 13 additions & 0 deletions kaminpar-shm/factories.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "kaminpar-shm/coarsening/noop_coarsener.h"

// Refinement
#include "coarsening/sparsification/ForestFireSampler.h"
#include "coarsening/sparsification/UniformRandomSampler.h"
#include "coarsening/sparsifing_cluster_coarsener.h"

#include "kaminpar-shm/refinement/adapters/mtkahypar_refiner.h"
Expand Down Expand Up @@ -87,6 +89,17 @@ std::unique_ptr<Coarsener> create_coarsener(const Context &ctx, const PartitionC
__builtin_unreachable();
}

std::unique_ptr<sparsification::Sampler> create_sampler(const Context &ctx) {
switch (ctx.coarsening.sparsification_algorithm) {
case SparsificationAlgorithm::FOREST_FIRE:
return std::make_unique<sparsification::ForestFireSampler>(0.3, 0.9, 0.01);
case SparsificationAlgorithm::UNIFORM_RANDOM_SAMPLING:
return std::make_unique<sparsification::UniformRandomSampler>(0.5);
}

__builtin_unreachable();
}

namespace {
std::unique_ptr<Refiner> create_refiner(const Context &ctx, const RefinementAlgorithm algorithm) {
switch (algorithm) {
Expand Down
4 changes: 4 additions & 0 deletions kaminpar-shm/factories.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
******************************************************************************/
#pragma once

#include "coarsening/sparsification/Sampler.h"

#include "kaminpar-shm/coarsening/clusterer.h"
#include "kaminpar-shm/coarsening/coarsener.h"
#include "kaminpar-shm/datastructures/graph.h"
Expand All @@ -23,5 +25,7 @@ std::unique_ptr<Clusterer> create_clusterer(const Context &ctx);
std::unique_ptr<Coarsener> create_coarsener(const Context &ctx, const PartitionContext &p_ctx);
std::unique_ptr<Coarsener> create_coarsener(const Context &ctx);

std::unique_ptr<sparsification::Sampler> create_sampler(const Context &ctx);

std::unique_ptr<Refiner> create_refiner(const Context &ctx);
} // namespace kaminpar::shm::factory
3 changes: 2 additions & 1 deletion kaminpar-shm/kaminpar.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ enum class CoarseningAlgorithm {
};

enum class SparsificationAlgorithm {
UniformRandomSampling
UNIFORM_RANDOM_SAMPLING,
FOREST_FIRE
};

enum class ClusteringAlgorithm {
Expand Down

0 comments on commit 23563aa

Please sign in to comment.