diff --git a/src/utils/CRSGraph.hpp b/src/utils/CRSGraph.hpp index 18300f47a38acdced4bd0753c4cb18cad6dffb17..59b74ab57b16db757e95d1b74e72b4e296bfc026 100644 --- a/src/utils/CRSGraph.hpp +++ b/src/utils/CRSGraph.hpp @@ -6,8 +6,8 @@ class CRSGraph { private: - Array<int> m_entries; - Array<int> m_neighbors; + Array<const int> m_entries; + Array<const int> m_neighbors; public: size_t @@ -17,29 +17,30 @@ class CRSGraph return m_entries.size() - 1; } - const Array<int>& + const Array<const int>& entries() const { return m_entries; } - const Array<int>& + const Array<const int>& neighbors() const { return m_neighbors; } - CRSGraph& operator=(CRSGraph&&) = default; - CRSGraph& operator=(const CRSGraph&) = default; + CRSGraph& operator=(CRSGraph&&) = delete; + CRSGraph& operator=(const CRSGraph&) = delete; CRSGraph(const Array<int>& entries, const Array<int>& neighbors) : m_entries(entries), m_neighbors(neighbors) { Assert(m_entries.size() > 0); + Assert(static_cast<size_t>(m_entries[m_entries.size() - 1]) == m_neighbors.size()); } - CRSGraph() = default; - CRSGraph(CRSGraph&&) = default; - CRSGraph(const CRSGraph&) = default; + CRSGraph() = delete; + CRSGraph(CRSGraph&&) = delete; + CRSGraph(const CRSGraph&) = delete; ~CRSGraph() = default; }; diff --git a/src/utils/Partitioner.cpp b/src/utils/Partitioner.cpp index 4e6a45e1c20480d666e017670eea6795f5f08f0f..7a7eb2d9071bd9466611379efa3a950bb3c65d7c 100644 --- a/src/utils/Partitioner.cpp +++ b/src/utils/Partitioner.cpp @@ -57,11 +57,14 @@ Partitioner::partition(const CRSGraph& graph) part = Array<int>(local_number_of_nodes); std::vector<int> vtxdist{0, local_number_of_nodes}; - const Array<int>& entries = graph.entries(); - const Array<int>& neighbors = graph.neighbors(); + const Array<const int>& entries = graph.entries(); + const Array<const int>& neighbors = graph.neighbors(); + + int* entries_ptr = const_cast<int*>(&(entries[0])); + int* neighbors_ptr = const_cast<int*>(&(neighbors[0])); int result = - ParMETIS_V3_PartKway(&(vtxdist[0]), &(entries[0]), &(neighbors[0]), NULL, NULL, &wgtflag, &numflag, &ncon, &npart, + ParMETIS_V3_PartKway(&(vtxdist[0]), entries_ptr, neighbors_ptr, NULL, NULL, &wgtflag, &numflag, &ncon, &npart, &(tpwgts[0]), &(ubvec[0]), &(options[0]), &edgecut, &(part[0]), &parmetis_comm); if (result == METIS_ERROR) { throw UnexpectedError("Metis Error"); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 81d7553d5552133c35147fed3aa28c1fa571e2a1..ff217a345d59a413ec999a2c3a96dd13f47a439d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -52,6 +52,7 @@ add_executable (unit_tests test_CG.cpp test_ContinueProcessor.cpp test_ConcatExpressionProcessor.cpp + test_CRSGraph.cpp test_CRSMatrix.cpp test_DataVariant.cpp test_DoWhileProcessor.cpp diff --git a/tests/test_CRSGraph.cpp b/tests/test_CRSGraph.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1759dd213ba9cfa90915410cb9549a1be0be7a67 --- /dev/null +++ b/tests/test_CRSGraph.cpp @@ -0,0 +1,44 @@ +#ifndef TEST_CRS_GRAPH_HPP +#define TEST_CRS_GRAPH_HPP + +#include <catch2/catch.hpp> + +#include <utils/CRSGraph.hpp> + +// clazy:excludeall=non-pod-global-static + +TEST_CASE("CRSGraph", "[utils]") +{ + Array<int> entries{5}; + Array<int> neighbors{9}; + + entries[0] = 0; + neighbors[0] = 0; + neighbors[1] = 1; + + entries[1] = 2; + neighbors[2] = 1; + neighbors[3] = 3; + + entries[2] = 4; + neighbors[4] = 2; + neighbors[5] = 1; + neighbors[6] = 3; + + entries[3] = 7; + neighbors[7] = 0; + neighbors[8] = 1; + + entries[4] = 9; + + CRSGraph graph(entries, neighbors); + + REQUIRE(graph.numberOfNodes() == 4); + + REQUIRE(entries.size() == graph.entries().size()); + REQUIRE(&entries[0] == &graph.entries()[0]); + REQUIRE(neighbors.size() == graph.neighbors().size()); + REQUIRE(&neighbors[0] == &graph.neighbors()[0]); +} + +#endif // TEST_CRS_GRAPH_HPP