-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9856bc2
commit f07e39f
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |