From 96fd363a789d79753396c404e52b904446043aa1 Mon Sep 17 00:00:00 2001 From: Stephan Schulz <stephan.schulz-x2q@rub.de> Date: Wed, 25 Nov 2020 15:03:55 +0100 Subject: [PATCH] change all getter to returning functions except getWork(std::vector) --- example/ALL_test.cpp | 12 ++++------- include/ALL.hpp | 40 ++++++++---------------------------- include/ALL_Histogram.hpp | 6 +++--- include/ALL_LB.hpp | 6 +++--- include/ALL_Staggered.hpp | 6 +++--- include/ALL_Tensor.hpp | 6 +++--- include/ALL_Unstructured.hpp | 6 +++--- include/ALL_Voronoi.hpp | 12 +++++------ 8 files changed, 34 insertions(+), 60 deletions(-) diff --git a/example/ALL_test.cpp b/example/ALL_test.cpp index 9614b51..5342087 100644 --- a/example/ALL_test.cpp +++ b/example/ALL_test.cpp @@ -1212,9 +1212,8 @@ int main(int argc, char **argv) { int n_transfer[2]; int n_recv[2 * MAX_NEIG]; int offset_neig[2]; - std::vector<int> neighbors; + std::vector<int> neighbors = lb_obj.getNeighbors(); int *nNeighbors; - lb_obj.getNeighbors(neighbors); nNeighbors = neighbors.data(); offset_neig[0] = 0; @@ -1832,10 +1831,8 @@ int main(int argc, char **argv) { case ALL::LB_t::VORONOI: { // get neighbor information int nNeighbors = lb_obj.getNNeighbors(); - std::vector<double> neighbor_vertices; - std::vector<int> neighbors; - lb_obj.getNeighborVertices(neighbor_vertices); - lb_obj.getNeighbors(neighbors); + std::vector<double> neighbor_vertices = lb_obj.getNeighborVertices(); + std::vector<int> neighbors = lb_obj.getNeighbors(); // compute voronoi cells @@ -2278,8 +2275,7 @@ int main(int argc, char **argv) { if (chosen_method == ALL::LB_t::HISTOGRAM) { int *nNeighbors; - std::vector<int> neighbors; - lb_obj.getNeighbors(neighbors); + std::vector<int> neighbors = lb_obj.getNeighbors(); nNeighbors = neighbors.data(); int n_neig = 0; for (int j = 0; j < 3; ++j) { diff --git a/include/ALL.hpp b/include/ALL.hpp index 3934338..1debe74 100644 --- a/include/ALL.hpp +++ b/include/ALL.hpp @@ -431,55 +431,33 @@ public: void getWork(std::vector<W> &result) { result = balancer->getWork(); } /// method to get the work provided to the method - /// @param[out] result to store the work to if only a scalar was used, if an - /// array was used to provide work only the first value will be returned - void getWork(W &result) { result = balancer->getWork().at(0); } + /// @result scalar work or first value of vector work + W getWork() { return balancer->getWork().at(0); } /// method to get the number of neigbors the local domain has /// @result int the number of neighbors the local domain has in total int getNNeighbors() { - std::vector<int> neig; - try { - balancer->getNeighbors(neig); - } catch (CustomException &e) { - std::cout << e.what() << std::endl; - MPI_Abort(MPI_COMM_WORLD, -1); - } - return neig.size(); + return balancer->getNeighbors().size(); } /// method to provide a list of the ranks of the neighbors the local domain /// has in all directions - /// @param[out] neig a reference to a std::vector<int> object, which the - /// neighbors will be stored in - void getNeighbors(std::vector<int> &neig) { - try { - balancer->getNeighbors(neig); - } catch (CustomException &e) { - std::cout << e.what() << std::endl; - MPI_Abort(MPI_COMM_WORLD, -1); - } + /// @result vector if neighboring ranks + std::vector<int> &getNeighbors() { + return balancer->getNeighbors(); } /// method to provide a list of neighboring vertices, e.g. required for /// VORONOI - /// @param[out] nv a reference to a vector object, which the + /// @result vector of neighboring vertices /// neighboring vertices are stored in - void getNeighborVertices(std::vector<T> &nv) { + std::vector<T> &getNeighborVertices() { switch (method) { - case LB_t::TENSOR: - break; - case LB_t::STAGGERED: - break; - case LB_t::UNSTRUCTURED: - break; #ifdef ALL_VORONOI_ACTIVE case LB_t::VORONOI: - ((Voronoi_LB<T, W> *)balancer.get())->getNeighborVertices(nv); + return ((Voronoi_LB<T, W> *)balancer.get())->getNeighborVertices(); break; #endif - case LB_t::HISTOGRAM: - break; default: break; } diff --git a/include/ALL_Histogram.hpp b/include/ALL_Histogram.hpp index 3f26614..f7c93f9 100644 --- a/include/ALL_Histogram.hpp +++ b/include/ALL_Histogram.hpp @@ -92,7 +92,7 @@ public: // neighbors /// method to provide a list of neighbors by MPI rank /// @param [out] list the std::vector the list of neighbors is stored to - void getNeighbors(std::vector<int> &list) override; + std::vector<int> &getNeighbors() override; /// method to set method specific data /// @param data pointer to an array of integers (int) containing the number of @@ -666,8 +666,8 @@ template <class T, class W> void Histogram_LB<T, W>::find_neighbors() { // provide list of neighbors template <class T, class W> -void Histogram_LB<T, W>::getNeighbors(std::vector<int> &ret) { - ret = neighbors; +std::vector<int> &Histogram_LB<T, W>::getNeighbors() { + return neighbors; } }//namespace ALL diff --git a/include/ALL_LB.hpp b/include/ALL_LB.hpp index 33ac701..3e2e363 100644 --- a/include/ALL_LB.hpp +++ b/include/ALL_LB.hpp @@ -63,9 +63,9 @@ public: virtual void balance(const int step) = 0; /// abstract definition of the method to get the neighbors of the local domain - /// @param[out] list reference to std::vector<int> to store the MPI ranks of - /// the neighbors to - virtual void getNeighbors(std::vector<int> &list) = 0; + /// @result std::vector<int> to store the MPI ranks of the neighbors + /// to + virtual std::vector<int> &getNeighbors() = 0; /// method to update the vertices used for the balancing step, overwrites old /// set of vertices diff --git a/include/ALL_Staggered.hpp b/include/ALL_Staggered.hpp index e1c125e..ea36482 100644 --- a/include/ALL_Staggered.hpp +++ b/include/ALL_Staggered.hpp @@ -85,7 +85,7 @@ public: /// method to provide a list of the neighbors of the local domain /// @param[out] list reference to a std::vector of integers where the list of /// neighbors will be assigned to - virtual void getNeighbors(std::vector<int> &list) override; + virtual std::vector<int> &getNeighbors() override; /// method to set specific data structures (unused for staggered grid method) /// @param[in] data pointer to the data structure @@ -619,8 +619,8 @@ template <class T, class W> void Staggered_LB<T, W>::find_neighbors() { // provide list of neighbors template <class T, class W> -void Staggered_LB<T, W>::getNeighbors(std::vector<int> &ret) { - ret = neighbors; +std::vector<int> &Staggered_LB<T, W>::getNeighbors() { + return neighbors; } }//namespace ALL diff --git a/include/ALL_Tensor.hpp b/include/ALL_Tensor.hpp index b470832..c5ca109 100644 --- a/include/ALL_Tensor.hpp +++ b/include/ALL_Tensor.hpp @@ -86,7 +86,7 @@ public: /// method to provide a list of the neighbors of the local domain /// @param[out] list reference to a std::vector of integers where the list of /// neighbors will be assigned to - virtual void getNeighbors(std::vector<int> &list) override; + virtual std::vector<int> &getNeighbors() override; /// method to set specific data structures (unused for tensor grid method) /// @param[in] data pointer to the data structure @@ -247,8 +247,8 @@ template <class T, class W> void Tensor_LB<T, W>::balance(int) { // provide list of neighbors template <class T, class W> -void Tensor_LB<T, W>::getNeighbors(std::vector<int> &ret) { - ret = neighbors; +std::vector<int> &Tensor_LB<T, W>::getNeighbors() { + return neighbors; } }//namespace ALL diff --git a/include/ALL_Unstructured.hpp b/include/ALL_Unstructured.hpp index 08dcec5..67f66c4 100644 --- a/include/ALL_Unstructured.hpp +++ b/include/ALL_Unstructured.hpp @@ -110,7 +110,7 @@ public: /// method to provide a list of the neighbors of the local domain /// @param[out] list reference to a std::vector of integers where the list of /// neighbors will be assigned to - virtual void getNeighbors(std::vector<int> &list) override; + virtual std::vector<int> &getNeighbors() override; /// method to set specific data structures (unused for tensor grid method) /// @param[in] data pointer to the data structure @@ -149,8 +149,8 @@ template <class T, class W> Unstructured_LB<T, W>::~Unstructured_LB() {} // provide list of neighbors template <class T, class W> -void Unstructured_LB<T, W>::getNeighbors(std::vector<int> &ret) { - ret = neighbors; +std::vector<int> &Unstructured_LB<T, W>::getNeighbors() { + return neighbors; } template <class T, class W> void Unstructured_LB<T, W>::setup() { diff --git a/include/ALL_Voronoi.hpp b/include/ALL_Voronoi.hpp index d9abb94..3c7ed96 100644 --- a/include/ALL_Voronoi.hpp +++ b/include/ALL_Voronoi.hpp @@ -94,7 +94,7 @@ public: /// method to provide a list of the neighbors of the local domain /// @param[out] list reference to a std::vector of integers where the list of /// neighbors will be assigned to - virtual void getNeighbors(std::vector<int> &list) override; + virtual std::vector<int> &getNeighbors() override; /// method to set specific data structures (unused for tensor grid method) /// @param[in] data pointer to the data structure @@ -102,7 +102,7 @@ public: /// method to get a list of the vertices of the neighboring domains /// @param[out] ret list of vertices of neighboring domains - void getNeighborVertices(std::vector<T> &ret); + std::vector<T> &getNeighborVertices(); private: // MPI values @@ -552,14 +552,14 @@ void Voronoi_LB<T, W>::balance(int known_unused loadbalancing_step) { // provide list of neighbors template <class T, class W> -void Voronoi_LB<T, W>::getNeighbors(std::vector<int> &ret) { - ret = neighbors; +std::vector<int> &Voronoi_LB<T, W>::getNeighbors() { + return neighbors; } // provide list of neighbor vertices template <class T, class W> -void Voronoi_LB<T, W>::getNeighborVertices(std::vector<T> &ret) { - ret = neighbor_vertices; +std::vector<T> &Voronoi_LB<T, W>::getNeighborVertices() { + return neighbor_vertices; } }//namespace ALL -- GitLab