diff --git a/src/utils/Partitioner.cpp b/src/utils/Partitioner.cpp index 4f53d322f5e52c130122ccc3966270e7220d34d7..9ef628245f73b3be4f6ecd875ae5dd255821027b 100644 --- a/src/utils/Partitioner.cpp +++ b/src/utils/Partitioner.cpp @@ -15,8 +15,10 @@ Partitioner::partition(const CRSGraph& graph) case PartitionerLibrary::ptscotch: { return PTScotchPartitioner::partition(graph); } + // LCOV_EXCL_START default: { throw UnexpectedError("invalid partition library"); } + // LCOV_EXCL_STOP } } diff --git a/src/utils/PartitionerOptions.hpp b/src/utils/PartitionerOptions.hpp index e4157f7659cac94ef8b4c7cd02a54d289156d4a8..b17180e0b78e612c314f64bad878c7136ff328bc 100644 --- a/src/utils/PartitionerOptions.hpp +++ b/src/utils/PartitionerOptions.hpp @@ -29,7 +29,7 @@ name(const PartitionerLibrary library) case PartitionerLibrary::PT__end: { } } - throw UnexpectedError("Linear system library name is not defined!"); + throw UnexpectedError("Partitioner library name is not defined!"); } template <typename PartitionerEnumType> @@ -43,7 +43,9 @@ getPartitionerEnumFromName(const std::string& enum_name) return PartitionerEnumType{enum_value}; } } - throw NormalError(std::string{"could not find '"} + enum_name + "' associate type!"); + // LCOV_EXCL_START + throw UnexpectedError(std::string{"could not find '"} + enum_name + "' associate type!"); + // LCOV_EXCL_STOP } class PartitionerOptions diff --git a/tests/test_Partitioner.cpp b/tests/test_Partitioner.cpp index 78a427f6d31fd35f27519498a0382e681f3421c4..3638a3926c9487cef416b4f91118c1920ab6006e 100644 --- a/tests/test_Partitioner.cpp +++ b/tests/test_Partitioner.cpp @@ -11,8 +11,6 @@ TEST_CASE("Partitioner", "[utils]") { SECTION("one graph split to all") { - Partitioner partitioner; - std::vector<int> entries_vector; std::vector<int> neighbors_vector; @@ -70,17 +68,54 @@ TEST_CASE("Partitioner", "[utils]") CRSGraph graph{entries, neighbors}; - Array<int> partitioned = partitioner.partition(graph); + SECTION("ParMETIS") + { + PartitionerOptions partitioner_options; + partitioner_options.library() = PartitionerLibrary::parmetis; + Partitioner partitioner{partitioner_options}; - REQUIRE((partitioned.size() + 1) == entries.size()); + Array<int> partitioned = partitioner.partition(graph); - if (parallel::rank() == 0) { - std::set<int> assigned_ranks; - for (size_t i = 0; i < partitioned.size(); ++i) { - assigned_ranks.insert(partitioned[i]); + REQUIRE((partitioned.size() + 1) == entries.size()); + +#ifdef PUGS_HAS_PARMETIS + if (parallel::rank() == 0) { + std::set<int> assigned_ranks; + for (size_t i = 0; i < partitioned.size(); ++i) { + assigned_ranks.insert(partitioned[i]); + } + + REQUIRE(assigned_ranks.size() == parallel::size()); } +#else // PUGS_HAS_PARMETIS + REQUIRE(min(partitionned == 0)); + REQUIRE(max(partitionned == 0)); +#endif // PUGS_HAS_PARMETIS + } - REQUIRE(assigned_ranks.size() == parallel::size()); + SECTION("PTScotch") + { + PartitionerOptions partitioner_options; + partitioner_options.library() = PartitionerLibrary::ptscotch; + Partitioner partitioner{partitioner_options}; + + Array<int> partitioned = partitioner.partition(graph); + + REQUIRE((partitioned.size() + 1) == entries.size()); + +#ifdef PUGS_HAS_PTSCOTCH + if (parallel::rank() == 0) { + std::set<int> assigned_ranks; + for (size_t i = 0; i < partitioned.size(); ++i) { + assigned_ranks.insert(partitioned[i]); + } + + REQUIRE(assigned_ranks.size() == parallel::size()); + } +#else // PUGS_HAS_PTSCOTCH + REQUIRE(min(partitionned == 0)); + REQUIRE(max(partitionned == 0)); +#endif // PUGS_HAS_PTSCOTCH } } } diff --git a/tests/test_PartitionerOptions.cpp b/tests/test_PartitionerOptions.cpp new file mode 100644 index 0000000000000000000000000000000000000000..67c016221239758914d6f457775c72d36eee1dc2 --- /dev/null +++ b/tests/test_PartitionerOptions.cpp @@ -0,0 +1,18 @@ +#include <catch2/catch_all.hpp> +#include <catch2/catch_test_macros.hpp> + +#include <utils/PartitionerOptions.hpp> + +// clazy:excludeall=non-pod-global-static + +TEST_CASE("PartitionerOptions", "[utils]") +{ + SECTION("name") + { + REQUIRE(name(PartitionerLibrary::parmetis) == "ParMetis"); + REQUIRE(name(PartitionerLibrary::ptscotch) == "PTScotch"); + REQUIRE_THROWS_WITH(PartitionerLibrary::PT__end, "unexpected error: Partitioner library name is not defined!"); + + WARN("not finished"); + } +}