diff --git a/bhtree_mpi/src/datastructures/BarnesHutTree.cpp b/bhtree_mpi/src/datastructures/BarnesHutTree.cpp index 1bb0bf4ec120c04803ad2c73c5e20af9e612e2f3..9b33a66a53efbc2a757a5dcc345abee917870e16 100644 --- a/bhtree_mpi/src/datastructures/BarnesHutTree.cpp +++ b/bhtree_mpi/src/datastructures/BarnesHutTree.cpp @@ -5,9 +5,7 @@ #include namespace nbody { - BarnesHutTree::BarnesHutTree(std::size_t parallelId) : Tree(parallelId) { - } - + BarnesHutTree::BarnesHutTree(std::size_t parallelId) : Tree(parallelId) {} //determine octree subboxes std::vector BarnesHutTree::splitBB(const Node* node) { diff --git a/bhtree_mpi/src/datastructures/Body.cpp b/bhtree_mpi/src/datastructures/Body.cpp index 544ac5ae46e248cc9101bc0ca3c5ba1fb3952686..aeb6dca39913f338818d2dbe7d00d037c0e8f2dd 100644 --- a/bhtree_mpi/src/datastructures/Body.cpp +++ b/bhtree_mpi/src/datastructures/Body.cpp @@ -7,6 +7,19 @@ #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) {} + void Body::resetAcceleration() { std::fill(std::begin(acceleration), std::end(acceleration), 0.0); } @@ -88,28 +101,23 @@ namespace nbody { std::vector result; std::string line; std::ifstream infile(filename.c_str(), std::ifstream::in); - double mass, px, py, pz, vx, vy, vz; - std::size_t id = 0; while (std::getline(infile, line)) { std::istringstream iss(line); - Body b; + double mass, px, py, pz, vx, vy, vz; + std::size_t id = 0; //not all input files have velocity, so initialize properly vx = vy = vz = 0.0; iss >> mass >> px >> py >> pz >> vx >> vy >> vz; - b.position[0] = px; - b.position[1] = py; - b.position[2] = pz; - b.velocity[0] = vx; - b.velocity[1] = vy; - b.velocity[2] = vz; - b.acceleration[0] = 0.0; - b.acceleration[1] = 0.0; - b.acceleration[2] = 0.0; - b.refinement = false; - b.mass = mass; - b.id = id++; + Body b{ + {{px, py, pz}}, + {{vx, vy, vz}}, + {{0.0, 0.0, 0.0}}, + mass, + false, + id++ + }; result.push_back(b); } return result; diff --git a/bhtree_mpi/src/datastructures/Body.hpp b/bhtree_mpi/src/datastructures/Body.hpp index 618602da4536d22a2e81312c75add2879fc2232d..d1c94492337eff53ae08081684a24b8a754814f9 100644 --- a/bhtree_mpi/src/datastructures/Body.hpp +++ b/bhtree_mpi/src/datastructures/Body.hpp @@ -13,13 +13,21 @@ namespace nbody { std::array dv{}; }; - struct Body { //TODO(steinret): ctor - std::size_t id{}; + 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); + + std::size_t id{0}; std::array position{}; std::array velocity{}; std::array acceleration{}; - double mass{}; - bool refinement{}; + double mass{0.0}; + bool refinement{false}; void resetAcceleration(); Derivative evaluate(double dt, const Derivative& d) const; diff --git a/bhtree_mpi/src/datastructures/Box.cpp b/bhtree_mpi/src/datastructures/Box.cpp index 5467f295004f8b52f2af70f73d35b8444ad3b7b3..2181457377dddd8e6b80fe3c1158ad45ef5fef85 100644 --- a/bhtree_mpi/src/datastructures/Box.cpp +++ b/bhtree_mpi/src/datastructures/Box.cpp @@ -1,15 +1,9 @@ #include #include -#include #include #include "Box.hpp" namespace nbody { - Box::Box() { - std::fill(std::begin(min), std::end(min), std::numeric_limits::max()); - std::fill(std::begin(max), std::end(max), std::numeric_limits::min()); - } - //extend box to form cube void Box::extendToCube() { std::size_t longestSide = std::numeric_limits::max(); diff --git a/bhtree_mpi/src/datastructures/Box.hpp b/bhtree_mpi/src/datastructures/Box.hpp index 5f835748c1508d264ec6f9f317680484d9b0b112..e0c3dd332bfec356d747e045888613d31864f02e 100644 --- a/bhtree_mpi/src/datastructures/Box.hpp +++ b/bhtree_mpi/src/datastructures/Box.hpp @@ -3,14 +3,21 @@ #include #include +#include #include namespace nbody { struct Box { - std::array min{}; - std::array max{}; + using flt_lim = std::numeric_limits; + std::array min{ { + flt_lim::max(), + flt_lim::max(), + flt_lim::max() }}; + std::array max{{ + flt_lim::min(), + flt_lim::min(), + flt_lim::min() }}; - Box(); void extendToCube(); void extendForBodies(const std::vector& bodies); std::vector extractBodies(std::vector& bodies) const; diff --git a/bhtree_mpi/src/datastructures/Node.cpp b/bhtree_mpi/src/datastructures/Node.cpp index 2ea6253e478d3715cc3d70d1fbc2e15f35d55d40..661e05c6c01189de3b2cbad464e8391fc598ddc3 100644 --- a/bhtree_mpi/src/datastructures/Node.cpp +++ b/bhtree_mpi/src/datastructures/Node.cpp @@ -5,16 +5,7 @@ #include "Node.hpp" namespace nbody { - Node::Node(Tree* tree) { - this->afterSubtree = nullptr; - this->prev = this; - this->next = this; - this->leaf = true; - this->tree = tree; - this->prevSibling = nullptr; - this->nextSibling = nullptr; - this->parent = nullptr; - } + Node::Node(Tree* _tree):tree(_tree) {} Box Node::getBB() const { return this->bb; diff --git a/bhtree_mpi/src/datastructures/Node.hpp b/bhtree_mpi/src/datastructures/Node.hpp index fe5998a9b14a07651938dd7f4b581fd9e8f08e26..f9193f016aa744d71f3a8c64a488fb50000cd060 100644 --- a/bhtree_mpi/src/datastructures/Node.hpp +++ b/bhtree_mpi/src/datastructures/Node.hpp @@ -16,17 +16,17 @@ namespace nbody { protected: Box bb; std::vector bodies; - Node* prev; - Node* next; - Node* nextSibling; - Node* prevSibling; - Node* parent; - Node* afterSubtree; - bool leaf; - Tree* tree; - Body representative{}; + Node* prev{ this }; + Node* next{ this }; + Node* nextSibling{ nullptr }; + Node* prevSibling{ nullptr }; + Node* parent{ nullptr }; + Node* afterSubtree{ nullptr }; + bool leaf{ true }; + Tree* tree{ nullptr }; + Body representative; public: - Node(Tree* tree); + Node(Tree* _tree); virtual ~Node() = default; virtual bool isSplitable() const; virtual void extendBBforBodies(); diff --git a/bhtree_mpi/src/datastructures/Tree.cpp b/bhtree_mpi/src/datastructures/Tree.cpp index 9c78ec9aeafa607a5aab51791d090fa0ad2ad24f..e4e34266313f7f4d2760fb1683ed536cde927875 100644 --- a/bhtree_mpi/src/datastructures/Tree.cpp +++ b/bhtree_mpi/src/datastructures/Tree.cpp @@ -8,13 +8,10 @@ #include "Simulation.hpp" namespace nbody { - Tree::Tree(std::size_t parallelId) { - //insert dummy root node - this->nodes = new Node(this); - this->maxLeafBodies = 16; - this->parallelId = parallelId; - this->simulation = nullptr; - } + Tree::Tree(std::size_t _parallelId): + nodes(new Node(this)), //insert dummy root node + maxLeafBodies(16), + parallelId(_parallelId) {} Tree::~Tree() { this->clean(); diff --git a/bhtree_mpi/src/datastructures/Tree.hpp b/bhtree_mpi/src/datastructures/Tree.hpp index 583a19b7f48227260bb51ac60838f397fc420c4e..a1fbd6b4547ee62cb74ba1164e21379e5e36297c 100644 --- a/bhtree_mpi/src/datastructures/Tree.hpp +++ b/bhtree_mpi/src/datastructures/Tree.hpp @@ -20,9 +20,9 @@ namespace nbody { friend class ContinuousPthreadSimulation; protected: Node* nodes; - std::size_t maxLeafBodies; - std::size_t parallelId; - Simulation* simulation; + std::size_t maxLeafBodies{ 0 }; + std::size_t parallelId{ 0 }; + Simulation* simulation{ nullptr }; public: Tree(std::size_t parallelId); virtual ~Tree(); diff --git a/bhtree_mpi/src/simulation/MpiSimulation.cpp b/bhtree_mpi/src/simulation/MpiSimulation.cpp index 03aa38ea8764d7c00da79160940e8fbec3c579e8..36f99b95bbb6e4bb14dc6f2d7ab9a9e7e02372aa 100644 --- a/bhtree_mpi/src/simulation/MpiSimulation.cpp +++ b/bhtree_mpi/src/simulation/MpiSimulation.cpp @@ -12,10 +12,6 @@ namespace nbody { MpiSimulation::MpiSimulation(const std::string& inputFile) { - this->tree = nullptr; - this->bodyType = MPI_DATATYPE_NULL; - this->boxType = MPI_DATATYPE_NULL; - //create MPI datatypes for bodies and domain boxes int bodyBlocklengths[6] = { 1, 3, 3, 3, 1, 1 }; MPI_Datatype bodyDatatypes[6] = { MPI_UINT64_T, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_CXX_BOOL }; @@ -94,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); + MPI_Isend(store->bodies.data(), bodySize, this->bodyType, target, 0, MPI_COMM_WORLD, &store->request); // TODO(steinret): use BSend here sendStores.push_back(std::move(store)); } diff --git a/bhtree_mpi/src/simulation/MpiSimulation.hpp b/bhtree_mpi/src/simulation/MpiSimulation.hpp index cc85929ef59b8f429fe9514e515d09cf24387260..8e01dfe71e8c7985dbcd928a3f1e0b2531b1d34e 100644 --- a/bhtree_mpi/src/simulation/MpiSimulation.hpp +++ b/bhtree_mpi/src/simulation/MpiSimulation.hpp @@ -19,8 +19,8 @@ namespace nbody { //MPI simulation class MpiSimulation : public Simulation { protected: - MPI_Datatype bodyType; - MPI_Datatype boxType; + MPI_Datatype bodyType{MPI_DATATYPE_NULL}; + MPI_Datatype boxType{MPI_DATATYPE_NULL}; std::vector domains; Box overallDomain; std::vector> sendStores; diff --git a/bhtree_mpi/src/simulation/Simulation.cpp b/bhtree_mpi/src/simulation/Simulation.cpp index 9000e087eb81982a2442fb4d9b38402e38cd3950..02735c022afaf1881d69d22ed6169f5c1e3e2efc 100644 --- a/bhtree_mpi/src/simulation/Simulation.cpp +++ b/bhtree_mpi/src/simulation/Simulation.cpp @@ -3,13 +3,6 @@ #include "Simulation.hpp" namespace nbody { - Simulation::Simulation() { - this->parallelRank = -1; - this->parallelSize = -1; - this->correctState = false; - this->tree = nullptr; - } - void Simulation::clearBodies() { this->bodies.clear(); } diff --git a/bhtree_mpi/src/simulation/Simulation.hpp b/bhtree_mpi/src/simulation/Simulation.hpp index 412048995c5a3aa77c8904bd29ed9ca6ba9aa275..d92a2eb41d196a6ea872645f3a4c7d7198e39a9f 100644 --- a/bhtree_mpi/src/simulation/Simulation.hpp +++ b/bhtree_mpi/src/simulation/Simulation.hpp @@ -9,13 +9,12 @@ namespace nbody { //simulation superclass class Simulation { protected: - int parallelSize; - int parallelRank; - bool correctState; + int parallelSize{ -1 }; + int parallelRank{ -1 }; + bool correctState{ false }; std::vector bodies; - BarnesHutTree* tree; + BarnesHutTree* tree{ nullptr }; public: - Simulation(); virtual void clearBodies(); virtual std::vector getBodies() const; virtual std::size_t getNumberOfProcesses() const = 0;