From b8fc666909406ad01eb5bc9584dbd1abf2297e21 Mon Sep 17 00:00:00 2001 From: Paul Heinzlreiter Date: Wed, 13 Jul 2016 18:03:21 +0200 Subject: [PATCH] * full simulation loop --- bh_tree_mpi/datastructures/Box.cpp | 11 ++++++++ bh_tree_mpi/datastructures/Box.hpp | 1 + bh_tree_mpi/datastructures/Node.hpp | 1 - bh_tree_mpi/datastructures/Tree.cpp | 27 +++++++++++++++++++ bh_tree_mpi/datastructures/Tree.hpp | 2 ++ bh_tree_mpi/parallelization/MpiSimulation.cpp | 9 ++++--- 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/bh_tree_mpi/datastructures/Box.cpp b/bh_tree_mpi/datastructures/Box.cpp index f779a11..2e71f44 100644 --- a/bh_tree_mpi/datastructures/Box.cpp +++ b/bh_tree_mpi/datastructures/Box.cpp @@ -279,4 +279,15 @@ namespace nbody { } } } + + void Box::extend(Body extender) { + for (int i = 0; i < 3; i++) { + if (this->min[i] > extender.position[i]) { + this->min[i] = extender.position[i]; + } + if (this->max[i] < extender.position[i]) { + this->max[i] = extender.position[i]; + } + } + } } diff --git a/bh_tree_mpi/datastructures/Box.hpp b/bh_tree_mpi/datastructures/Box.hpp index 0c176b5..95a2459 100644 --- a/bh_tree_mpi/datastructures/Box.hpp +++ b/bh_tree_mpi/datastructures/Box.hpp @@ -37,6 +37,7 @@ namespace nbody { virtual vector splitLongestSide(); virtual bool contained(double* position); virtual void extend(Box extender); + virtual void extend(Body extender); }; } diff --git a/bh_tree_mpi/datastructures/Node.hpp b/bh_tree_mpi/datastructures/Node.hpp index ce22df9..6429327 100644 --- a/bh_tree_mpi/datastructures/Node.hpp +++ b/bh_tree_mpi/datastructures/Node.hpp @@ -17,7 +17,6 @@ namespace nbody { protected: Box bb; vector bodies; - vector refinements; Node* prev; Node* next; Node* nextSibling; diff --git a/bh_tree_mpi/datastructures/Tree.cpp b/bh_tree_mpi/datastructures/Tree.cpp index f0bde3e..ce494b1 100644 --- a/bh_tree_mpi/datastructures/Tree.cpp +++ b/bh_tree_mpi/datastructures/Tree.cpp @@ -149,6 +149,33 @@ namespace nbody { this->build(this->extractLocalBodies(), domain); } + void Tree::advance() { + for (Node* n = this->nodes->next; n != this->nodes; n = n->next) { + if (n->leaf) { + for (vector::iterator it = n->bodies.begin(); it != n->bodies.end(); it++) { + if (!it->refinement) { + it->integrate(); + } + } + } + } + } + + Box Tree::getLocalBB() { + Box result; + + for (Node* n = this->nodes->next; n != this->nodes; n = n->next) { + if (n->leaf) { + for (vector::iterator it = n->bodies.begin(); it != n->bodies.end(); it++) { + if (!it->refinement) { + result.extend(*it); + } + } + } + } + return result; + } + void Tree::print() { this->nodes->next->bb.print(); } diff --git a/bh_tree_mpi/datastructures/Tree.hpp b/bh_tree_mpi/datastructures/Tree.hpp index acd6efe..4a73122 100644 --- a/bh_tree_mpi/datastructures/Tree.hpp +++ b/bh_tree_mpi/datastructures/Tree.hpp @@ -35,6 +35,8 @@ namespace nbody { virtual Box getRootBB(); virtual void print(); virtual bool isCorrect(); + virtual void advance(); + virtual Box getLocalBB(); }; diff --git a/bh_tree_mpi/parallelization/MpiSimulation.cpp b/bh_tree_mpi/parallelization/MpiSimulation.cpp index c2189ab..69862fe 100644 --- a/bh_tree_mpi/parallelization/MpiSimulation.cpp +++ b/bh_tree_mpi/parallelization/MpiSimulation.cpp @@ -143,11 +143,11 @@ namespace nbody { this->comms[0].recvBlocking(0, this->bodies); } this->tree.build(this->bodies); + this->domains[this->mpiRank] = this->tree.getRootBB(); //this->tree.isCorrect(); } void MpiSimulation::distributeDomains() { - this->domains[this->mpiRank] = this->tree.getRootBB(); MPI::COMM_WORLD.Allgather(&this->domains[this->mpiRank], 1, this->boxType, &this->domains[0], 1, this->boxType); } @@ -183,13 +183,16 @@ namespace nbody { Box overallDomain; this->distributeDomains(); - this->domains[this->mpiRank].print(); + //this->domains[this->mpiRank].print(); for (unsigned int i = 0; i < this->mpiSize; i++) { overallDomain.extend(this->domains[i]); } - overallDomain.print(); + //overallDomain.print(); this->tree.rebuild(overallDomain); this->distributeLETs(); + this->tree.computeForces(); + this->tree.advance(); + this->domains[this->mpiRank] = this->tree.getLocalBB(); } } -- GitLab