From 9273bae19ead854620113b77a9a3e82b014f5709 Mon Sep 17 00:00:00 2001 From: Thomas Steinreiter Date: Mon, 21 Nov 2016 14:59:04 +0100 Subject: [PATCH] * use range for * do squared comparison instead of sqrt * remove unused Node::parent * forwarding reference optimization for MPI send --- bhtree_mpi/src/datastructures/BarnesHutTree.cpp | 6 +++--- bhtree_mpi/src/datastructures/Node.cpp | 2 +- bhtree_mpi/src/datastructures/Node.hpp | 1 - bhtree_mpi/src/simulation/MpiSimulation.cpp | 10 +++++----- bhtree_mpi/src/simulation/MpiSimulation.hpp | 4 ++-- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/bhtree_mpi/src/datastructures/BarnesHutTree.cpp b/bhtree_mpi/src/datastructures/BarnesHutTree.cpp index 64d72ac..d1000a7 100644 --- a/bhtree_mpi/src/datastructures/BarnesHutTree.cpp +++ b/bhtree_mpi/src/datastructures/BarnesHutTree.cpp @@ -128,18 +128,18 @@ namespace nbody { //put all new bodies into fitting leaves, walk through tree and split Node* current; - for (auto it = std::begin(bodies); it != std::end(bodies); it++) { + for (auto& b : bodies) { current = nodes->next; while (!current->leaf) { Node* child = current->next; - while (child != nullptr && !child->getBB().contained(it->position)) { + while (child != nullptr && !child->getBB().contained(b.position)) { child = child->nextSibling; } //TODO(pheinzlr): check for child == nullptr? current = child; } - current->bodies.push_back(*it); + current->bodies.push_back(b); current->bodies.back().refinement = true; } current = nodes->next; diff --git a/bhtree_mpi/src/datastructures/Node.cpp b/bhtree_mpi/src/datastructures/Node.cpp index 8133f2a..35f1921 100644 --- a/bhtree_mpi/src/datastructures/Node.cpp +++ b/bhtree_mpi/src/datastructures/Node.cpp @@ -157,7 +157,7 @@ namespace nbody { for (std::size_t i = 0; i < 3; i++) { distance += (representative.position[i] - body.position[i]) * (representative.position[i] - body.position[i]); } - return sqrt(distance) > getL(); // TODO(steinret): do squared comparison + return distance > std::pow(getL(), 2.0); } //check if node is sufficient for force evaluation for all bodies in box diff --git a/bhtree_mpi/src/datastructures/Node.hpp b/bhtree_mpi/src/datastructures/Node.hpp index 835c477..4ffb17f 100644 --- a/bhtree_mpi/src/datastructures/Node.hpp +++ b/bhtree_mpi/src/datastructures/Node.hpp @@ -20,7 +20,6 @@ namespace nbody { Node* next{ this }; Node* nextSibling{ nullptr }; Node* prevSibling{ nullptr }; - Node* parent{ nullptr }; Node* afterSubtree{ nullptr }; bool leaf{ true }; Tree* tree{ nullptr }; diff --git a/bhtree_mpi/src/simulation/MpiSimulation.cpp b/bhtree_mpi/src/simulation/MpiSimulation.cpp index 09beb77..9c6fbc2 100644 --- a/bhtree_mpi/src/simulation/MpiSimulation.cpp +++ b/bhtree_mpi/src/simulation/MpiSimulation.cpp @@ -84,13 +84,13 @@ namespace nbody { } //mpi send wrapper - void MpiSimulation::send(const std::vector& bodies, int target) { + void MpiSimulation::send(std::vector&& bodies, int target) { const auto bodySize = bodies.size(); //do unblocking send - auto store = std::make_unique(bodies); //TODO(steinret): ask ponweist if this could be done w/o unique_ptr + auto store = std::make_unique(std::move(bodies)); //TODO(steinret): ask ponweist if this could be done w/o unique_ptr - MPI_Isend(store->bodies.data(), bodySize, bodyType, target, 0, MPI_COMM_WORLD, &store->request); // TODO(steinret): use BSend here + MPI_Isend(store->bodies.data(), bodySize, bodyType, target, 0, MPI_COMM_WORLD, &store->request); sendStores.push_back(std::move(store)); } @@ -189,9 +189,9 @@ namespace nbody { //send out locally essential trees (local bodies needed by remote simulations, determined by remote domain size) for (std::size_t i = 0; i < static_cast(parallelSize); i++) { if (i != static_cast(parallelRank)) { - std::vector refinements = tree->copyRefinements(domains[i]); + auto refinements = tree->copyRefinements(domains[i]); - send(refinements, i); + send(std::move(refinements), i); } } diff --git a/bhtree_mpi/src/simulation/MpiSimulation.hpp b/bhtree_mpi/src/simulation/MpiSimulation.hpp index 8e01dfe..8fd9328 100644 --- a/bhtree_mpi/src/simulation/MpiSimulation.hpp +++ b/bhtree_mpi/src/simulation/MpiSimulation.hpp @@ -13,7 +13,7 @@ namespace nbody { struct SendStore { std::vector bodies; MPI_Request request{ MPI_REQUEST_NULL }; - SendStore(const std::vector& b):bodies(b) {}; + SendStore(std::vector&& b):bodies(std::move(b)) {}; }; //MPI simulation @@ -26,7 +26,7 @@ namespace nbody { std::vector> sendStores; void flushSendStore(); - virtual void send(const std::vector& bodies, int target); + virtual void send(std::vector&& bodies, int target); virtual int recv(std::vector& bodies, int source); public: MpiSimulation(const std::string& inputFile); -- GitLab