From 1b45157d5d5ae008a67562733cb588116ce61186 Mon Sep 17 00:00:00 2001 From: Thomas Steinreiter Date: Mon, 21 Nov 2016 12:34:56 +0100 Subject: [PATCH] * removed identifiers starting with _ (dangerous) * removed unnecessary this pointer qualifier when accessing members --- .../src/datastructures/BarnesHutTree.cpp | 28 ++--- bhtree_mpi/src/datastructures/Body.cpp | 24 ++-- bhtree_mpi/src/datastructures/Body.hpp | 12 +- bhtree_mpi/src/datastructures/Node.cpp | 72 +++++------ bhtree_mpi/src/datastructures/Node.hpp | 6 +- bhtree_mpi/src/datastructures/Tree.cpp | 64 +++++----- bhtree_mpi/src/datastructures/Tree.hpp | 3 +- bhtree_mpi/src/simulation/MpiSimulation.cpp | 118 +++++++++--------- bhtree_mpi/src/simulation/Simulation.cpp | 12 +- 9 files changed, 169 insertions(+), 170 deletions(-) diff --git a/bhtree_mpi/src/datastructures/BarnesHutTree.cpp b/bhtree_mpi/src/datastructures/BarnesHutTree.cpp index 9b33a66..5f81a21 100644 --- a/bhtree_mpi/src/datastructures/BarnesHutTree.cpp +++ b/bhtree_mpi/src/datastructures/BarnesHutTree.cpp @@ -19,8 +19,8 @@ namespace nbody { //update upper tree ndoes according to moved particles void BarnesHutTree::update() { //iterate for updating representatives - Node* current = this->nodes->prev; - while (current != this->nodes) { + Node* current = nodes->prev; + while (current != nodes) { current->representative.id = std::numeric_limits::max(); current->representative.mass = 0.0; current->representative.position[0] = 0.0; @@ -84,11 +84,11 @@ namespace nbody { void BarnesHutTree::init(const std::vector& bodies, const Box& domain) { Node* current; - this->clean(); + clean(); if (bodies.empty()) return; //insert root node - this->nodes->insertAfter(new Node(this)); - current = this->nodes->next; + nodes->insertAfter(new Node(this)); + current = nodes->next; //assign bodies to root node current->bodies = bodies; //setup proper bounding box @@ -110,17 +110,17 @@ namespace nbody { //build tree with given domain void BarnesHutTree::build(const std::vector& bodies, const Box& domain) { - this->init(bodies, domain); + init(bodies, domain); //iterate over existing boxes and split if it contains too much bodies - BarnesHutTree::splitSubtree(this->nodes->next); - this->update(); + BarnesHutTree::splitSubtree(nodes->next); + update(); } //build tree void BarnesHutTree::build(const std::vector& bodies) { Box bb; bb.extendForBodies(bodies); - this->build(bodies, bb); + build(bodies, bb); } //merge remote refinement particles into local tree @@ -130,7 +130,7 @@ namespace nbody { Node* current; for (auto it = std::begin(bodies); it != std::end(bodies); it++) { - current = this->nodes->next; + current = nodes->next; while (!current->leaf) { Node* child = current->next; @@ -143,12 +143,12 @@ namespace nbody { current->bodies.push_back(*it); current->bodies.back().refinement = true; } - current = this->nodes->next; - while (current != this->nodes) { - this->splitNode(current); + current = nodes->next; + while (current != nodes) { + splitNode(current); current = current->next; } - this->update(); + update(); } //node splitting if required diff --git a/bhtree_mpi/src/datastructures/Body.cpp b/bhtree_mpi/src/datastructures/Body.cpp index aeb6dca..9aa7971 100644 --- a/bhtree_mpi/src/datastructures/Body.cpp +++ b/bhtree_mpi/src/datastructures/Body.cpp @@ -7,18 +7,18 @@ #include namespace nbody { - Body::Body(const std::array& _position, - const std::array& _velocity, - const std::array& _acceleration, - double _mass, - bool _refinement, - std::size_t _id) : - id(_id), - position(_position), - velocity(_velocity), - acceleration(_acceleration), - mass(_mass), - refinement(_refinement) {} + Body::Body(const std::array& position_, + const std::array& velocity_, + const std::array& acceleration_, + double mass_, + bool refinement_, + std::size_t id_) : + id(id_), + position(position_), + velocity(velocity_), + acceleration(acceleration_), + mass(mass_), + refinement(refinement_) {} void Body::resetAcceleration() { std::fill(std::begin(acceleration), std::end(acceleration), 0.0); diff --git a/bhtree_mpi/src/datastructures/Body.hpp b/bhtree_mpi/src/datastructures/Body.hpp index d1c9449..d1e26b1 100644 --- a/bhtree_mpi/src/datastructures/Body.hpp +++ b/bhtree_mpi/src/datastructures/Body.hpp @@ -15,12 +15,12 @@ namespace nbody { struct Body { Body() = default; - Body(const std::array& _position, - const std::array& _velocity, - const std::array& _acceleration, - double _mass, - bool _refinement, - std::size_t _id); + Body(const std::array& position_, + const std::array& velocity_, + const std::array& acceleration_, + double mass_, + bool refinement_, + std::size_t id_); std::size_t id{0}; std::array position{}; diff --git a/bhtree_mpi/src/datastructures/Node.cpp b/bhtree_mpi/src/datastructures/Node.cpp index 661e05c..6a4e26a 100644 --- a/bhtree_mpi/src/datastructures/Node.cpp +++ b/bhtree_mpi/src/datastructures/Node.cpp @@ -8,37 +8,37 @@ namespace nbody { Node::Node(Tree* _tree):tree(_tree) {} Box Node::getBB() const { - return this->bb; + return bb; } - void Node::setBB(const Box& bb) { - this->bb = bb; + void Node::setBB(const Box& bb_) { + bb = bb_; } //check if node needs to be splitted during tree build bool Node::isSplitable() const { bool result = true; - if (this->bodies.size() <= this->tree->maxLeafBodies) { + if (bodies.size() <= tree->maxLeafBodies) { result = false; } //this is to prevent errors with collocated particles - if (this->bb.volume() <= std::numeric_limits::epsilon()) { + if (bb.volume() <= std::numeric_limits::epsilon()) { result = false; } return result; } void Node::extendBBforBodies() { - this->bb.extendForBodies(this->bodies); + bb.extendForBodies(bodies); } void Node::extendBBtoCube() { - this->bb.extendToCube(); + bb.extendToCube(); } std::vector Node::getBodies() const { - return this->bodies; + return bodies; } void Node::insertBefore(Node* node) { @@ -60,17 +60,17 @@ namespace nbody { } bool Node::isCorrect() const { - if (this->afterSubtree == nullptr) { + if (afterSubtree == nullptr) { std::cerr << "after subtree null\n"; return false; } - if (!this->bb.isCorrectBox()) { + if (!bb.isCorrectBox()) { std::cerr << "bb wrong\n"; return false; } for (std::size_t i = 0; i < 3; i++) { - if (this->bb.min[i] > this->bb.max[i]) { - std::cerr << "bb " << i << " min " << this->bb.min[i] << " max " << this->bb.max[i] << '\n'; + if (bb.min[i] > bb.max[i]) { + std::cerr << "bb " << i << " min " << bb.min[i] << " max " << bb.max[i] << '\n'; return false; } } @@ -78,11 +78,11 @@ namespace nbody { std::cerr << "bb out of bounds\n"; return false; } - if (!this->leaf) { - Node* current = this->next; + if (!leaf) { + Node* current = next; std::size_t children = 0; - while (current != nullptr && current != this->afterSubtree) { + while (current != nullptr && current != afterSubtree) { current = current->afterSubtree; children++; } @@ -90,24 +90,24 @@ namespace nbody { std::cerr << "afterSubtree null\n"; return false; } - if (children != this->tree->numberOfChildren()) { + if (children != tree->numberOfChildren()) { std::cerr << "wrong number of children " << children << '\n'; return false; } - current = this->next; - for (std::size_t i = 0; i < this->tree->numberOfChildren(); i++) { + current = next; + for (std::size_t i = 0; i < tree->numberOfChildren(); i++) { current = current->afterSubtree; } - if (current != this->afterSubtree) { + if (current != afterSubtree) { std::cerr << "last sibling afterSubtree inconsistent\n"; return false; } } - if (!this->leaf && !this->bodies.empty()) { + if (!leaf && !bodies.empty()) { std::cerr << "non-empty inner node\n"; return false; } - if (this->leaf && this->nextSibling != nullptr && this->next != this->nextSibling) { + if (leaf && nextSibling != nullptr && next != nextSibling) { std::cerr << "wrong next sibling\n"; return false; } @@ -119,7 +119,7 @@ namespace nbody { double position[3] = {0.0, 0.0, 0.0}; double mass = 0.0; - if (this->leaf) { + if (leaf) { for (const auto& body : bodies) { mass += body.mass; for (std::size_t i = 0; i < 3; i++) { @@ -127,23 +127,23 @@ namespace nbody { } } } else { - for (Node* node = this->next; node != nullptr; node = node->nextSibling) { + for (Node* node = next; node != nullptr; node = node->nextSibling) { mass += node->representative.mass; } } for (std::size_t i = 0; i < 3; i++) { - this->representative.position[i] = position[i] / mass; + representative.position[i] = position[i] / mass; } - this->representative.mass = mass; + representative.mass = mass; } //get criterion to check if node is sufficient for force evaluation double Node::getL() const { - return this->bb.maxSidelength(); + return bb.maxSidelength(); } void Node::print(std::size_t parallelId) const { - this->bb.printBB(parallelId); + bb.printBB(parallelId); for (const auto& body : bodies) { std::cout << " "; body.print(parallelId); @@ -155,26 +155,26 @@ namespace nbody { double distance = 0.0; for (std::size_t i = 0; i < 3; i++) { - distance += (this->representative.position[i] - body.position[i]) * (this->representative.position[i] - body.position[i]); + distance += (representative.position[i] - body.position[i]) * (representative.position[i] - body.position[i]); } - return sqrt(distance) > this->getL(); + return sqrt(distance) > getL(); } //check if node is sufficient for force evaluation for all bodies in box bool Node::sufficientForBox(const Box& box) const { - return this->bb.distanceToBox(box) > this->getL(); + return bb.distanceToBox(box) > getL(); } - void Node::setBodies(const std::vector& bodies) { - this->bodies = bodies; + void Node::setBodies(const std::vector& bodies_) { + bodies = bodies_; } - void Node::setBodies(std::vector&& bodies) { - this->bodies = std::move(bodies); + void Node::setBodies(std::vector&& bodies_) { + bodies = std::move(bodies_); } //get local bodies void Node::extractLocalBodiesTo(std::vector& result) { - std::copy_if(std::begin(this->bodies), std::end(this->bodies), std::back_inserter(result), [](const Body& b) {return !b.refinement; }); - this->bodies.clear(); + std::copy_if(std::begin(bodies), std::end(bodies), std::back_inserter(result), [](const Body& b) {return !b.refinement; }); + bodies.clear(); } } // namespace nbody diff --git a/bhtree_mpi/src/datastructures/Node.hpp b/bhtree_mpi/src/datastructures/Node.hpp index f9193f0..835c477 100644 --- a/bhtree_mpi/src/datastructures/Node.hpp +++ b/bhtree_mpi/src/datastructures/Node.hpp @@ -32,7 +32,7 @@ namespace nbody { virtual void extendBBforBodies(); virtual void extendBBtoCube(); virtual Box getBB() const; - virtual void setBB(const Box& bb); + virtual void setBB(const Box& bb_); virtual std::vector getBodies() const; virtual void insertBefore(Node* node); virtual void insertAfter(Node* node); @@ -43,8 +43,8 @@ namespace nbody { virtual void print(std::size_t parallelId) const; virtual bool sufficientForBody(const Body& body) const; virtual bool sufficientForBox(const Box& box) const; - virtual void setBodies(const std::vector& bodies); - virtual void setBodies(std::vector&& bodies); + virtual void setBodies(const std::vector& bodies_); + virtual void setBodies(std::vector&& bodies_); virtual void extractLocalBodiesTo(std::vector& result); }; } // namespace nbody diff --git a/bhtree_mpi/src/datastructures/Tree.cpp b/bhtree_mpi/src/datastructures/Tree.cpp index e4e3426..7cb12c1 100644 --- a/bhtree_mpi/src/datastructures/Tree.cpp +++ b/bhtree_mpi/src/datastructures/Tree.cpp @@ -14,39 +14,39 @@ namespace nbody { parallelId(_parallelId) {} Tree::~Tree() { - this->clean(); - delete this->nodes; + clean(); + delete nodes; } - void Tree::setSimulation(Simulation* simulation) { - this->simulation = simulation; + void Tree::setSimulation(Simulation* simulation_) { + simulation = simulation_; } void Tree::clean() { //remove all nodes; refresh dummy first node - while (this->nodes->next != this->nodes) { - Node* node = this->nodes->next; + while (nodes->next != nodes) { + Node* node = nodes->next; node->unlink(); delete node; } - delete this->nodes; - this->nodes = new Node(this); + delete nodes; + nodes = new Node(this); } std::size_t Tree::numberOfNodes() const { - std::size_t nodes = 0; + std::size_t noNodes = 0; - for (Node* node = this->nodes->next; node != this->nodes; node = node->next) { - nodes++; + for (Node* node = nodes->next; node != nodes; node = node->next) { + noNodes++; } - return nodes; + return noNodes; } bool Tree::isCorrect() const { - Node* current = this->nodes->next; + Node* current = nodes->next; - while (current != this->nodes) { + while (current != nodes) { if (!current->isCorrect()) { return false; } @@ -57,10 +57,10 @@ namespace nbody { //accumulate force from the whole local tree on parameter body void Tree::accumulateForceOnto(Body& body) { - Node* n = this->nodes->next; + Node* n = nodes->next; body.resetAcceleration(); - while (n != this->nodes) { + while (n != nodes) { if (n->sufficientForBody(body)) { body.accumulateForceOntoBody(n->representative); n = n->afterSubtree; @@ -77,11 +77,11 @@ namespace nbody { //accumulate forces for whole tree (local particles) void Tree::computeForces() { - for (Node* n = this->nodes->next; n != this->nodes; n = n->next) { + for (Node* n = nodes->next; n != nodes; n = n->next) { if (n->leaf) { for (auto& b : n->bodies) { if (!b.refinement) { - this->accumulateForceOnto(b); + accumulateForceOnto(b); } } } @@ -92,28 +92,28 @@ namespace nbody { std::vector Tree::extractLocalBodies() { std::vector result; - while (this->nodes->next != this->nodes) { - if (this->nodes->next->leaf) { + while (nodes->next != nodes) { + if (nodes->next->leaf) { std::copy_if(std::begin(nodes->next->bodies), std::end(nodes->next->bodies), std::back_inserter(result), [](const Body& b) {return !b.refinement; }); } - Node* h = this->nodes->next; - this->nodes->next->unlink(); + Node* h = nodes->next; + nodes->next->unlink(); delete(h); } - this->clean(); + clean(); return result; } //get refinement particles required to compute forces within remote domains std::vector Tree::copyRefinements(const Box& domain) const { std::vector result; - Node* current = this->nodes->next; + Node* current = nodes->next; if (!current->bb.isValid()) { //empty tree means no refinements return result; } - while (current != this->nodes) { + while (current != nodes) { bool sufficient = current->sufficientForBox(domain); if (sufficient) { @@ -134,28 +134,28 @@ namespace nbody { //get bounding box of root node Box Tree::getRootBB() const { - return this->nodes->next->bb; + return nodes->next->bb; } //rebuild with predefined root node bounding box void Tree::rebuild(const Box& domain) { - this->build(this->extractLocalBodies(), domain); + build(extractLocalBodies(), domain); } void Tree::rebuild() { - this->build(this->extractLocalBodies()); + build(extractLocalBodies()); } //rebuild with predefined root node bounding box and bodies void Tree::rebuild(const Box& domain, const std::vector& bodies) { - this->build(bodies, domain); + build(bodies, domain); } //move particles according to accumulated forces Box Tree::advance() { Box bb; - for (Node* n = this->nodes->next; n != this->nodes; n = n->next) { + for (Node* n = nodes->next; n != nodes; n = n->next) { if (n->leaf) { for (auto& b : n->bodies) { if (!b.refinement) { @@ -171,7 +171,7 @@ namespace nbody { //determine local tree bounding box Box Tree::getLocalBB() const { Box result; - for (Node* n = this->nodes->next; n != this->nodes; n = n->next) { + for (Node* n = nodes->next; n != nodes; n = n->next) { if (n->leaf) { for (auto& b : n->bodies) { if (!b.refinement) { @@ -184,7 +184,7 @@ namespace nbody { } void Tree::print(std::size_t parallelId) const { - for (Node* n = this->nodes->next; n != this->nodes; n = n->next) { + for (Node* n = nodes->next; n != nodes; n = n->next) { n->bb.printBB(parallelId); if (n->leaf) { for (auto& b : n->bodies) { diff --git a/bhtree_mpi/src/datastructures/Tree.hpp b/bhtree_mpi/src/datastructures/Tree.hpp index 1416839..03b0556 100644 --- a/bhtree_mpi/src/datastructures/Tree.hpp +++ b/bhtree_mpi/src/datastructures/Tree.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include "Body.hpp" #include "Box.hpp" @@ -25,7 +24,7 @@ namespace nbody { public: Tree(std::size_t parallelId); virtual ~Tree(); - virtual void setSimulation(Simulation* simulation); + virtual void setSimulation(Simulation* simulation_); virtual void clean(); virtual void build(const std::vector& bodies) = 0; virtual void build(const std::vector& bodies, const Box& domain) = 0; diff --git a/bhtree_mpi/src/simulation/MpiSimulation.cpp b/bhtree_mpi/src/simulation/MpiSimulation.cpp index 36f99b9..09beb77 100644 --- a/bhtree_mpi/src/simulation/MpiSimulation.cpp +++ b/bhtree_mpi/src/simulation/MpiSimulation.cpp @@ -22,65 +22,65 @@ namespace nbody { bodyOffsets[3] = offsetof(Body, acceleration); bodyOffsets[4] = offsetof(Body, mass); bodyOffsets[5] = offsetof(Body, refinement); - MPI_Type_create_struct(6, bodyBlocklengths, bodyOffsets, bodyDatatypes, &this->bodyType); - MPI_Type_commit(&this->bodyType); + MPI_Type_create_struct(6, bodyBlocklengths, bodyOffsets, bodyDatatypes, &bodyType); + MPI_Type_commit(&bodyType); int boxBlocklengths[2] = { 3, 3 }; MPI_Datatype boxDatatypes[2] = { MPI_DOUBLE, MPI_DOUBLE }; MPI_Aint boxOffsets[2]; boxOffsets[0] = offsetof(Box, min); boxOffsets[1] = offsetof(Box, max); - MPI_Type_create_struct(2, boxBlocklengths, boxOffsets, boxDatatypes, &this->boxType); - MPI_Type_commit(&this->boxType); + MPI_Type_create_struct(2, boxBlocklengths, boxOffsets, boxDatatypes, &boxType); + MPI_Type_commit(&boxType); //get number of processes and own process id - MPI_Comm_size(MPI_COMM_WORLD, &this->parallelSize); - MPI_Comm_rank(MPI_COMM_WORLD, &this->parallelRank); - this->domains.reserve(this->parallelSize); - this->correctState = true; + MPI_Comm_size(MPI_COMM_WORLD, ¶llelSize); + MPI_Comm_rank(MPI_COMM_WORLD, ¶llelRank); + domains.reserve(parallelSize); + correctState = true; //parse input data if (!inputFile.empty()) { - this->correctState = this->readInputData(inputFile); + correctState = readInputData(inputFile); } else { - this->correctState = false; + correctState = false; } //broadcast current state and terminate if input file cannot be read - int mpiCorrectState = static_cast(this->correctState); + int mpiCorrectState = static_cast(correctState); MPI_Bcast(&mpiCorrectState, 1, MPI_INT, 0, MPI_COMM_WORLD); - if (!this->correctState) { + if (!correctState) { std::cerr << "Error occurred: terminating ...\n"; - MPI_Type_free(&this->bodyType); - MPI_Type_free(&this->boxType); + MPI_Type_free(&bodyType); + MPI_Type_free(&boxType); MPI_Abort(MPI_COMM_WORLD, -1); abort(); } } bool MpiSimulation::stateCorrect() { - return this->correctState; + return correctState; } MpiSimulation::~MpiSimulation() { flushSendStore(); //cleanup MPI types - MPI_Type_free(&this->bodyType); - MPI_Type_free(&this->boxType); + MPI_Type_free(&bodyType); + MPI_Type_free(&boxType); delete this->tree; - this->tree = nullptr; + tree = nullptr; } std::size_t MpiSimulation::getNumberOfProcesses() const { - return this->parallelSize; + return parallelSize; } std::size_t MpiSimulation::getProcessId() const { - return this->parallelRank; + return parallelRank; } MPI_Datatype* MpiSimulation::getDatatype() { - return &this->bodyType; + return &bodyType; } //mpi send wrapper @@ -90,7 +90,7 @@ namespace nbody { //do unblocking send auto store = std::make_unique(bodies); //TODO(steinret): ask ponweist if this could be done w/o unique_ptr - MPI_Isend(store->bodies.data(), bodySize, this->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); // TODO(steinret): use BSend here sendStores.push_back(std::move(store)); } @@ -101,9 +101,9 @@ namespace nbody { //do blocking recv; any source receive can be done with source == MPI_ANY_SOURCE MPI_Probe(source, 0, MPI_COMM_WORLD, &status); - MPI_Get_count(&status, this->bodyType, &count); + MPI_Get_count(&status, bodyType, &count); bodies.resize(count); - MPI_Recv(bodies.data(), count, this->bodyType, status.MPI_SOURCE, 0, MPI_COMM_WORLD, &status); + MPI_Recv(bodies.data(), count, bodyType, status.MPI_SOURCE, 0, MPI_COMM_WORLD, &status); //return source to determine message source for any source receives return status.MPI_SOURCE; } @@ -111,17 +111,17 @@ namespace nbody { //initial body distribution void MpiSimulation::distributeBodies() { //process 0 distributes bodies, others receive - if (this->parallelRank == 0) { + if (parallelRank == 0) { std::vector nodes; Box bb; nodes.push_back(Node(nullptr)); - nodes.front().setBodies(this->bodies); - bb.extendForBodies(this->bodies); + nodes.front().setBodies(bodies); + bb.extendForBodies(bodies); nodes.front().setBB(bb); //determine how to distribute bodies to processes //split box with most particles by halfing its longest side //until number of boxes equals number of processes - while (nodes.size() < static_cast(this->parallelSize)) { + while (nodes.size() < static_cast(parallelSize)) { std::size_t mostBodiesIndex = 0; for (std::size_t i = 1; i < nodes.size(); i++) { @@ -142,12 +142,12 @@ namespace nbody { nodes.insert(std::begin(nodes) + mostBodiesIndex, n); nodes.erase(std::begin(nodes) + mostBodiesIndex + 2); } - this->bodies = nodes[0].getBodies(); + bodies = nodes[0].getBodies(); for (std::size_t i = 1; i < nodes.size(); i++) { - this->send(nodes[i].getBodies(), i); + send(nodes[i].getBodies(), i); } } else { - this->recv(this->bodies, 0); + recv(bodies, 0); } flushSendStore(); } @@ -158,22 +158,22 @@ namespace nbody { //determine local domain size localDomain.extendForBodies(localBodies); - this->distributeDomains(localDomain); + distributeDomains(localDomain); } void MpiSimulation::distributeDomains() { - this->distributeDomains(this->bodies); + distributeDomains(bodies); } //domain distribution, all processes need to know the spatial domains of the others void MpiSimulation::distributeDomains(const Box& localDomain) { //distribute local domain sizes to all processes through collective MPI operation - this->domains[this->parallelRank] = localDomain; - MPI_Allgather(&this->domains[this->parallelRank], 1, this->boxType, &this->domains[0], 1, this->boxType, MPI_COMM_WORLD); - this->overallDomain = localDomain; + domains[parallelRank] = localDomain; + MPI_Allgather(&domains[parallelRank], 1, boxType, &domains[0], 1, boxType, MPI_COMM_WORLD); + overallDomain = localDomain; //determine overall domain size - for (std::size_t i = 0; i < static_cast(this->parallelSize); i++) { - this->overallDomain.extend(this->domains[i]); + for (std::size_t i = 0; i < static_cast(parallelSize); i++) { + overallDomain.extend(domains[i]); } } @@ -187,40 +187,40 @@ namespace nbody { //distribute bodies needed by other processes for their local simlation void MpiSimulation::distributeLETs() { //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(this->parallelSize); i++) { - if (i != static_cast(this->parallelRank)) { - std::vector refinements = this->tree->copyRefinements(this->domains[i]); + for (std::size_t i = 0; i < static_cast(parallelSize); i++) { + if (i != static_cast(parallelRank)) { + std::vector refinements = tree->copyRefinements(domains[i]); - this->send(refinements, i); + send(refinements, i); } } //receive bodies and integrate them into local tree for simulation - for (std::size_t i = 0; i < static_cast(this->parallelSize - 1); i++) { + for (std::size_t i = 0; i < static_cast(parallelSize - 1); i++) { std::vector refinements; //any source receive can be blocking, because we need to wait for data anyhow //order is not important, and receiving and merging arriving particles can be overlapped - this->recv(refinements, MPI_ANY_SOURCE); - this->tree->mergeLET(refinements); + recv(refinements, MPI_ANY_SOURCE); + tree->mergeLET(refinements); } - if (!this->tree->isCorrect()) { + if (!tree->isCorrect()) { std::cerr << "wrong tree\n"; } flushSendStore(); } void MpiSimulation::buildTree() { - this->tree = new BarnesHutTree(this->parallelRank); - this->tree->build(this->bodies, this->overallDomain); - if (!this->tree->isCorrect()) { + tree = new BarnesHutTree(parallelRank); + tree->build(bodies, overallDomain); + if (!tree->isCorrect()) { std::cerr << "wrong tree\n"; } } void MpiSimulation::rebuildTree() { //rebuild tree with moved local particles - this->tree->rebuild(this->overallDomain); + tree->rebuild(overallDomain); } //run a simulation step @@ -228,18 +228,18 @@ namespace nbody { //tree is already built here //distribute local bodies needed by remote processes - std::cout << " rank " << this->parallelRank << ": distribute local particles required for remote simulation ...\n"; - this->distributeLETs(); + std::cout << " rank " << parallelRank << ": distribute local particles required for remote simulation ...\n"; + distributeLETs(); //force computation - std::cout << " rank " << this->parallelRank << ": compute forces ...\n"; - this->tree->computeForces(); + std::cout << " rank " << parallelRank << ": compute forces ...\n"; + tree->computeForces(); //advance/move particles and distribute updated domain to other processes - std::cout << " rank " << this->parallelRank << ": move particles and redistribute simulation domains ...\n"; - this->distributeDomains(this->tree->advance()); + std::cout << " rank " << parallelRank << ": move particles and redistribute simulation domains ...\n"; + distributeDomains(tree->advance()); //rebuild tree with new particle positions - std::cout << " rank " << this->parallelRank << ": rebuild tree with new particle positions ...\n"; - this->rebuildTree(); - if (!this->tree->isCorrect()) { + std::cout << " rank " << parallelRank << ": rebuild tree with new particle positions ...\n"; + rebuildTree(); + if (!tree->isCorrect()) { std::cerr << "wrong tree\n"; } } diff --git a/bhtree_mpi/src/simulation/Simulation.cpp b/bhtree_mpi/src/simulation/Simulation.cpp index 02735c0..a71e202 100644 --- a/bhtree_mpi/src/simulation/Simulation.cpp +++ b/bhtree_mpi/src/simulation/Simulation.cpp @@ -4,17 +4,17 @@ namespace nbody { void Simulation::clearBodies() { - this->bodies.clear(); + bodies.clear(); } std::vector Simulation::getBodies() const { - return this->bodies; + return bodies; } bool Simulation::readInputData(const std::string& filename) { - if (this->getProcessId() == 0) { - this->bodies = dubinskiParse(filename); - if (this->bodies.empty()) { + if (getProcessId() == 0) { + bodies = dubinskiParse(filename); + if (bodies.empty()) { return false; } } @@ -22,7 +22,7 @@ namespace nbody { } Tree* Simulation::getTree() { - return this->tree; + return tree; } } // namespace nbody -- GitLab