Skip to content

Instantly share code, notes, and snippets.

@picsel2

picsel2/main.cpp Secret

Created January 31, 2023 00:21
Show Gist options
  • Save picsel2/d9691b32e93eba5a8481b706860f0ffe to your computer and use it in GitHub Desktop.
Save picsel2/d9691b32e93eba5a8481b706860f0ffe to your computer and use it in GitHub Desktop.
#include <memory>
#include <thread>
#include <vector>
#include <libkahypar.h>
char const *const ini_file =
"/home/sebastian/git/kahypar/config/cut_rKaHyPar_sea20.ini";
// Adapted example from the README to have something to hammer on
auto run_kahypar() {
kahypar_context_t *context = kahypar_context_new();
kahypar_configure_context_from_file(context, ini_file);
const kahypar_hypernode_id_t num_vertices = 7;
const kahypar_hyperedge_id_t num_hyperedges = 4;
std::unique_ptr<kahypar_hyperedge_weight_t[]> hyperedge_weights =
std::make_unique<kahypar_hyperedge_weight_t[]>(4);
// force the cut to contain hyperedge 0 and 2
hyperedge_weights[0] = 1;
hyperedge_weights[1] = 1000;
hyperedge_weights[2] = 1;
hyperedge_weights[3] = 1000;
std::unique_ptr<size_t[]> hyperedge_indices = std::make_unique<size_t[]>(5);
hyperedge_indices[0] = 0;
hyperedge_indices[1] = 2;
hyperedge_indices[2] = 6;
hyperedge_indices[3] = 9;
hyperedge_indices[4] = 12;
std::unique_ptr<kahypar_hyperedge_id_t[]> hyperedges =
std::make_unique<kahypar_hyperedge_id_t[]>(12);
// hypergraph from hMetis manual page 14
hyperedges[0] = 0;
hyperedges[1] = 2;
hyperedges[2] = 0;
hyperedges[3] = 1;
hyperedges[4] = 3;
hyperedges[5] = 4;
hyperedges[6] = 3;
hyperedges[7] = 4;
hyperedges[8] = 6;
hyperedges[9] = 2;
hyperedges[10] = 5;
hyperedges[11] = 6;
const double imbalance = 0.03;
const kahypar_partition_id_t k = 2;
kahypar_hyperedge_weight_t objective = 0;
std::vector<kahypar_partition_id_t> partition(num_vertices, -1);
kahypar_partition(num_vertices, num_hyperedges, imbalance, k,
/*vertex_weights */ nullptr, hyperedge_weights.get(),
hyperedge_indices.get(), hyperedges.get(), &objective,
context, partition.data());
kahypar_context_free(context);
}
auto main() -> int {
auto const task = [&] {
while (true) { run_kahypar(); }
};
auto threads = std::vector<std::thread>{};
for (int i = 0; i < std::thread::hardware_concurrency(); ++i) {
threads.emplace_back(task);
}
for (auto &thread: threads) { thread.join(); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment