diff --git a/bhtree_mpi/src/datastructures/BarnesHutTree.cpp b/bhtree_mpi/src/datastructures/BarnesHutTree.cpp index 64d72ac647c96571e6f3376931ec23c4c6a7387d..d1000a7e7f84190b4b7daf3709ebfa83f96d84fb 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 8133f2a4e2335dfb4d14c432560c0b358620768c..35f1921ab1d434c61397515f7afdb6e5ae206aab 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 835c477c9b48899dd9386f59bc935fd53428bbc1..4ffb17f3a2faa2163e310a8215fdf166c7d39f98 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 09beb77aca7c2f5ad92b9c61c12e19ee9e9e522f..9c6fbc29790ea5c17fe4c445a5f77a107f7b5b49 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 8e01dfe71e8c7985dbcd928a3f1e0b2531b1d34e..8fd932805a3880d6f7e15b9dc88f31d4ef90e338 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);