Skip to content

Commit

Permalink
feat(shm): add example project
Browse files Browse the repository at this point in the history
  • Loading branch information
dsalwasser committed Feb 23, 2025
1 parent 9856bc2 commit f07e39f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.21)

project(
KaMinParExample
DESCRIPTION "Example project on how to use KaMinPar"
LANGUAGES C CXX
)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(DOWNLOAD_KAMINPAR "Download KaMinPar from GitHub" ON)
if(DOWNLOAD_KAMINPAR)
include(FetchContent)
# TODO: change source when merged
FetchContent_Declare(
KaMinPar
SOURCE_DIR ../../../
)
FetchContent_MakeAvailable(KaMinPar)
else()
find_package(KaMinPar 3.2.0 REQUIRED)
endif()

add_executable(KaMinParExample main.cc)
target_link_libraries(KaMinParExample PRIVATE KaMinPar::KaMinPar KaMinPar::KaMinParIO)
39 changes: 39 additions & 0 deletions examples/simple/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <cstdlib>
#include <iostream>
#include <optional>
#include <string>
#include <vector>

#include <kaminpar.h>
#include <kaminpar_io.h>

int main(int argc, char **argv) {
using namespace kaminpar;
using namespace kaminpar::shm;

if (argc != 4) {
std::cerr << "Usage: " << argv[0] << " <num-blocks> <input-file> <output-file>" << std::endl;
return EXIT_FAILURE;
}

const int num_blocks = std::stoi(argv[1]);
const char *filename = argv[2];
const char *output = argv[3];

std::optional<Graph> graph = io::read_graph(filename, io::GraphFileFormat::METIS);
if (!graph.has_value()) {
std::cerr << "Failed to read graph from file " << filename << std::endl;
return EXIT_FAILURE;
}

const NodeID num_nodes = graph->n();
std::vector<BlockID> partition(num_nodes);

KaMinPar kaminpar;
kaminpar.set_graph(std::move(graph.value()));
kaminpar.compute_partition(num_blocks, partition);

io::write_partition(output, partition);

return EXIT_SUCCESS;
}

0 comments on commit f07e39f

Please sign in to comment.