diff --git a/bhtree_mpi/src/datastructures/BarnesHutTree.cpp b/bhtree_mpi/src/datastructures/BarnesHutTree.cpp index 8cc66d5acfb37c77caacaeced38079aa300f0d36..61e6ecca277e297bcad99c0bfabcc57fe796630e 100644 --- a/bhtree_mpi/src/datastructures/BarnesHutTree.cpp +++ b/bhtree_mpi/src/datastructures/BarnesHutTree.cpp @@ -6,8 +6,6 @@ #include namespace nbody { - using namespace std; - BarnesHutTree::BarnesHutTree(int parallelId) : Tree(parallelId) { } @@ -15,7 +13,7 @@ namespace nbody { } //determine octree subboxes - vector BarnesHutTree::splitBB(Node* node) { + std::vector BarnesHutTree::splitBB(Node* node) { return octreeSplit(node->getBB()); } @@ -64,11 +62,11 @@ namespace nbody { //split tree node into sub-boxes during tree build void BarnesHutTree::split(Node* current) { - vector subboxes = BarnesHutTree::splitBB(current); + std::vector subboxes = BarnesHutTree::splitBB(current); current->leaf = false; Node* after = current->next; - for (vector::iterator it = subboxes.begin(); it != subboxes.end(); it++) { + for (std::vector::iterator it = subboxes.begin(); it != subboxes.end(); it++) { Node* child = new Node(current->tree); child->parent = current; @@ -88,7 +86,7 @@ namespace nbody { } //initialize tree for build process - void BarnesHutTree::init(vector bodies, Box domain) { + void BarnesHutTree::init(std::vector bodies, Box domain) { Node* current; this->clean(); @@ -116,7 +114,7 @@ namespace nbody { } //build tree with given domain - void BarnesHutTree::build(vector bodies, Box domain) { + void BarnesHutTree::build(std::vector bodies, Box domain) { this->init(bodies, domain); //iterate over existing boxes and split if it contains too much bodies BarnesHutTree::splitSubtree(this->nodes->next); @@ -124,7 +122,7 @@ namespace nbody { } //build tree - void BarnesHutTree::build(vector bodies) { + void BarnesHutTree::build(std::vector bodies) { Box bb; initBox(bb); @@ -134,11 +132,11 @@ namespace nbody { //merge remote refinement particles into local tree //(this are remote particles from other processes needed for force computation on local particles) - void BarnesHutTree::mergeLET(vector bodies) { + void BarnesHutTree::mergeLET(std::vector bodies) { //put all new bodies into fitting leaves, walk through tree and split Node* current; - for (vector::iterator it = bodies.begin(); it != bodies.end(); it++) { + for (std::vector::iterator it = bodies.begin(); it != bodies.end(); it++) { current = this->nodes->next; while (!current->leaf) { Node* child = current->next; diff --git a/bhtree_mpi/src/datastructures/BarnesHutTree.hpp b/bhtree_mpi/src/datastructures/BarnesHutTree.hpp index 2d1db8c814c6000c6b4a40082fc06822a6f77687..544aacdd3eee0b858714d19a39e7737161882efe 100644 --- a/bhtree_mpi/src/datastructures/BarnesHutTree.hpp +++ b/bhtree_mpi/src/datastructures/BarnesHutTree.hpp @@ -5,23 +5,21 @@ #include "Box.hpp" namespace nbody { - using namespace std; - class Node; class BarnesHutTree : public Tree { protected: - static vector splitBB(Node* node); + static std::vector splitBB(Node* node); static bool splitNode(Node* current); virtual void update(); - virtual void init(vector bodies, Box domain); + virtual void init(std::vector bodies, Box domain); static void split(Node* current); public: BarnesHutTree(int parallelId); virtual ~BarnesHutTree(); - virtual void build(vector bodies); - virtual void build(vector bodies, Box domain); - virtual void mergeLET(vector bodies); + virtual void build(std::vector bodies); + virtual void build(std::vector bodies, Box domain); + virtual void mergeLET(std::vector bodies); virtual int numberOfChildren(); static void splitSubtree(Node* root); }; diff --git a/bhtree_mpi/src/datastructures/Body.cpp b/bhtree_mpi/src/datastructures/Body.cpp index 066d2e37ba5458135ec8183c0fa034d5aa5e0b4f..3564ba3152c383d39abf191ee46acf1718a0e0b3 100644 --- a/bhtree_mpi/src/datastructures/Body.cpp +++ b/bhtree_mpi/src/datastructures/Body.cpp @@ -12,10 +12,8 @@ #include namespace nbody { - using namespace std; - void resetAcceleration(Body& body) { - fill(body.acceleration.begin(), body.acceleration.end(), 0.0); + std::fill(body.acceleration.begin(), body.acceleration.end(), 0.0); } //helper method for intergration @@ -73,35 +71,35 @@ namespace nbody { } bool validDouble(double val) { - return !isnan(val) && isfinite(val); + return !std::isnan(val) && std::isfinite(val); } bool validBody(Body body) { - if (!all_of(body.position.begin(), body.position.end(), validDouble)) return false; - if (!all_of(body.velocity.begin(), body.velocity.end(), validDouble)) return false; - if (!all_of(body.acceleration.begin(), body.acceleration.end(), validDouble)) return false; + if (!std::all_of(body.position.begin(), body.position.end(), validDouble)) return false; + if (!std::all_of(body.velocity.begin(), body.velocity.end(), validDouble)) return false; + if (!std::all_of(body.acceleration.begin(), body.acceleration.end(), validDouble)) return false; if (!validDouble(body.mass)) return false; return body.mass >= 0.0; } void printBody(int parallelId, Body body) { - cout << parallelId << " " << body.id << " Position: " << body.position[0] << " " << body.position[1] << " " << body.position[2] << endl; - cout << parallelId << " " << body.id << " Velocity: " << body.velocity[0] << " " << body.velocity[1] << " " << body.velocity[2] << endl; - cout << parallelId << " " << body.id << " Acceleration: " << body.acceleration[0] << " " << body.acceleration[1] << " " << body.acceleration[2] << endl; - cout << parallelId << " " << body.id << " Mass: " << body.mass << endl; - cout << parallelId << " " << body.id << " Refinement: " << body.refinement << endl << endl; + std::cout << parallelId << " " << body.id << " Position: " << body.position[0] << " " << body.position[1] << " " << body.position[2] << std::endl; + std::cout << parallelId << " " << body.id << " Velocity: " << body.velocity[0] << " " << body.velocity[1] << " " << body.velocity[2] << std::endl; + std::cout << parallelId << " " << body.id << " Acceleration: " << body.acceleration[0] << " " << body.acceleration[1] << " " << body.acceleration[2] << std::endl; + std::cout << parallelId << " " << body.id << " Mass: " << body.mass << std::endl; + std::cout << parallelId << " " << body.id << " Refinement: " << body.refinement << std::endl << std::endl; } //parse input files - vector dubinskiParse(string filename) { - vector result; - string line; - ifstream infile(filename.c_str(), ifstream::in); + std::vector dubinskiParse(std::string filename) { + std::vector result; + std::string line; + std::ifstream infile(filename.c_str(), std::ifstream::in); double mass, px, py, pz, vx, vy, vz; unsigned long id = 0; while (std::getline(infile, line)) { - istringstream iss(line); + std::istringstream iss(line); Body b; //not all input files have velocity, so initialize properly @@ -125,13 +123,13 @@ namespace nbody { } - void printBodies(int parallelId, vector bodies) { - for (vector::iterator it = bodies.begin(); it != bodies.end(); it++) { + void printBodies(int parallelId, std::vector bodies) { + for (std::vector::iterator it = bodies.begin(); it != bodies.end(); it++) { printBody(parallelId, *it); } } - bool valid(vector bodies) { + bool valid(std::vector bodies) { return all_of(bodies.begin(), bodies.end(), validBody); } } diff --git a/bhtree_mpi/src/datastructures/Body.hpp b/bhtree_mpi/src/datastructures/Body.hpp index e0855a1fb64c72e9047e2d9a70bbabd8f564481a..c1db17231510869de9aefffeb369c7f94f6f77ca 100644 --- a/bhtree_mpi/src/datastructures/Body.hpp +++ b/bhtree_mpi/src/datastructures/Body.hpp @@ -6,20 +6,18 @@ #include namespace nbody { - using namespace std; - static const double timestep = 1.0; typedef struct DerivativeStruct { - array dx; - array dv; + std::array dx; + std::array dv; } Derivative; typedef struct BodyStruct { unsigned long id; - array position; - array velocity; - array acceleration; + std::array position; + std::array velocity; + std::array acceleration; double mass; int refinement; } Body; @@ -30,9 +28,9 @@ namespace nbody { void accumulateForceOntoBody(Body& to, Body from); bool validBody(Body body); void printBody(int parallelId, Body body); - void printBodies(int parallelId, vector bodies); - bool valid(vector bodies); - vector dubinskiParse(string filename); + void printBodies(int parallelId, std::vector bodies); + bool valid(std::vector bodies); + std::vector dubinskiParse(std::string filename); } #endif diff --git a/bhtree_mpi/src/datastructures/Box.cpp b/bhtree_mpi/src/datastructures/Box.cpp index c06943262079c01cd8bfa67905dd6e2fe4467e94..12bcbe5ea55f29c0b2933f5c2bee5338549dfa86 100644 --- a/bhtree_mpi/src/datastructures/Box.cpp +++ b/bhtree_mpi/src/datastructures/Box.cpp @@ -5,11 +5,9 @@ #include "Box.hpp" namespace nbody { - using namespace std; - void initBox(Box& box) { - fill(box.min.begin(), box.min.end(), FLT_MAX); - fill(box.max.begin(), box.max.end(), FLT_MIN); + std::fill(box.min.begin(), box.min.end(), FLT_MAX); + std::fill(box.max.begin(), box.max.end(), FLT_MIN); } //extend box to form cube @@ -37,19 +35,19 @@ namespace nbody { } //extend for bodies - void extendForBodies(Box& box, vector bodies) { - for (vector::iterator it = bodies.begin(); it != bodies.end(); it++) { + void extendForBodies(Box& box, std::vector bodies) { + for (std::vector::iterator it = bodies.begin(); it != bodies.end(); it++) { for (int i = 0; i < 3; i++) { - box.min[i] = min(it->position[i], box.min[i]); - box.max[i] = max(it->position[i], box.max[i]); + box.min[i] = std::min(it->position[i], box.min[i]); + box.max[i] = std::max(it->position[i], box.max[i]); } } } //extract bodies within box - vector extractBodies(Box box, vector& bodies) { - vector result; - vector::iterator it = bodies.begin(); + std::vector extractBodies(Box box, std::vector& bodies) { + std::vector result; + std::vector::iterator it = bodies.begin(); while (it != bodies.end()) { if (it->position[0] >= box.min[0] && it->position[0] <= box.max[0] && @@ -65,10 +63,10 @@ namespace nbody { } //copy bodies within box - vector copyBodies(Box box, vector bodies) { - vector result; + std::vector copyBodies(Box box, std::vector bodies) { + std::vector result; - for (vector::iterator it = bodies.begin(); it != bodies.end(); it++) { + for (std::vector::iterator it = bodies.begin(); it != bodies.end(); it++) { if (it->position[0] >= box.min[0] && it->position[0] <= box.max[0] && it->position[1] >= box.min[1] && it->position[1] <= box.max[1] && it->position[2] >= box.min[2] && it->position[2] <= box.max[2]) { @@ -118,7 +116,7 @@ namespace nbody { return -1.0; } for (int i = 0; i < 3; i++) { - maxVal = max(box.max[i] - box.min[i], maxVal); + maxVal = std::max(box.max[i] - box.min[i], maxVal); } return maxVal; } @@ -126,7 +124,7 @@ namespace nbody { bool isCorrectBox(Box box) { for (int i = 0; i < 3; i++) { if (box.max[i] < box.min[i]) { - cout << "inverted bb" << endl; + std::cout << "inverted bb" << std::endl; return false; } } @@ -143,15 +141,15 @@ namespace nbody { } void printBB(int parallelId, Box box) { - cout << parallelId << ": min "; + std::cout << parallelId << ": min "; for (int i = 0; i < 3; i++) { - cout << ": " << box.min[i] << " "; + std::cout << ": " << box.min[i] << " "; } - cout << parallelId << ": max "; + std::cout << parallelId << ": max "; for (int i = 0; i < 3; i++) { - cout << box.max[i] << " "; + std::cout << box.max[i] << " "; } - cout << endl; + std::cout << std::endl; } //check for box/sphere overlap @@ -227,8 +225,8 @@ namespace nbody { } //determine octree subboxes - vector octreeSplit(Box box) { - vector result; + std::vector octreeSplit(Box box) { + std::vector result; if (!isValid(box)) { return result; @@ -251,8 +249,8 @@ namespace nbody { } //split box into two across longest side - vector splitLongestSide(Box box) { - vector result; + std::vector splitLongestSide(Box box) { + std::vector result; int longestIndex = -1; double longestSide = -1.0; @@ -274,7 +272,7 @@ namespace nbody { } //check for position in box - bool contained(Box box, array position) { + bool contained(Box box, std::array position) { if (!isValid(box)) { return false; } diff --git a/bhtree_mpi/src/datastructures/Box.hpp b/bhtree_mpi/src/datastructures/Box.hpp index 930ef658ab0ee9748865ae9bb081d091d2998cec..dfeffd168714e3086c0e339497fcb6702e5742d7 100644 --- a/bhtree_mpi/src/datastructures/Box.hpp +++ b/bhtree_mpi/src/datastructures/Box.hpp @@ -6,18 +6,16 @@ #include namespace nbody { - using namespace std; - typedef struct _Box { - array min; - array max; + std::array min; + std::array max; } Box; void initBox(Box& box); void extendToCube(Box& box); - void extendForBodies(Box& box, vector bodies); - vector extractBodies(Box box, vector& bodies); - vector copyBodies(Box box, vector bodies); + void extendForBodies(Box& box, std::vector bodies); + std::vector extractBodies(Box box, std::vector& bodies); + std::vector copyBodies(Box box, std::vector bodies); bool isContained(Body body, Box box); bool isContained(Box inner, Box outer); double volume(Box box); @@ -28,9 +26,9 @@ namespace nbody { bool overlapsSphere(Box box, double* sphereCenter, double sphereRadius); double distanceToPosition(Box box, double* position); double distanceToBox(Box box1, Box box2); - vector octreeSplit(Box box); - vector splitLongestSide(Box box); - bool contained(Box box, array position); + std::vector octreeSplit(Box box); + std::vector splitLongestSide(Box box); + bool contained(Box box, std::array position); void extend(Box& box, Box extender); void extend(Box& box, Body extender); } diff --git a/bhtree_mpi/src/datastructures/Node.cpp b/bhtree_mpi/src/datastructures/Node.cpp index 8b46cd2976f7113d04bcf8ab599036bd691bd46d..21921ffb3d581f7a2471473f71628061bdaf2b37 100644 --- a/bhtree_mpi/src/datastructures/Node.cpp +++ b/bhtree_mpi/src/datastructures/Node.cpp @@ -5,8 +5,6 @@ #include "Node.hpp" namespace nbody { - using namespace std; - Node::Node(Tree* tree) { initBox(this->bb); this->afterSubtree = nullptr; @@ -53,7 +51,7 @@ namespace nbody { extendToCube(this->bb); } - vector Node::getBodies() { + std::vector Node::getBodies() { return this->bodies; } @@ -77,22 +75,22 @@ namespace nbody { bool Node::isCorrect() { if (this->afterSubtree == NULL) { - cerr << "after subtree null" << endl; + std::cerr << "after subtree null" << std::endl; return false; } if (!isCorrectBox(this->bb)) { - cerr << "bb wrong" << endl; + std::cerr << "bb wrong" << std::endl; return false; } for (int i = 0; i < 3; i++) { if (this->bb.min[i] > this->bb.max[i]) { - cerr << "bb " << i << " min " << this->bb.min[i] << " max " << this->bb.max[i] << endl; + std::cerr << "bb " << i << " min " << this->bb.min[i] << " max " << this->bb.max[i] << std::endl; return false; } } - for (vector::iterator it = this->bodies.begin(); it != this->bodies.end(); it++) { + for (std::vector::iterator it = this->bodies.begin(); it != this->bodies.end(); it++) { if (!isContained(*it, this->bb)) { - cerr << "bb out of bounds" << endl; + std::cerr << "bb out of bounds" << std::endl; return false; } } @@ -105,11 +103,11 @@ namespace nbody { children++; } if (current == NULL) { - cerr << "afterSubtree null" << endl; + std::cerr << "afterSubtree null" << std::endl; return false; } if (children != this->tree->numberOfChildren()) { - cerr << "wrong number of children " << children << endl; + std::cerr << "wrong number of children " << children << std::endl; return false; } current = this->next; @@ -117,16 +115,16 @@ namespace nbody { current = current->afterSubtree; } if (current != this->afterSubtree) { - cerr << "last sibling afterSubtree inconsistent" << endl; + std::cerr << "last sibling afterSubtree inconsistent" << std::endl; return false; } } if (!this->leaf && this->bodies.size() > 0) { - cerr << "non-empty inner node" << endl; + std::cerr << "non-empty inner node" << std::endl; return false; } if (this->leaf && this->nextSibling != NULL && this->next != this->nextSibling) { - cerr << "wrong next sibling" << endl; + std::cerr << "wrong next sibling" << std::endl; return false; } return true; @@ -138,7 +136,7 @@ namespace nbody { double mass = 0.0; if (this->leaf) { - for (vector::iterator it = this->bodies.begin(); it != this->bodies.end(); it++) { + for (std::vector::iterator it = this->bodies.begin(); it != this->bodies.end(); it++) { mass += it->mass; for (int i = 0; i < 3; i++) { position[i] += it->position[i] * it->mass; @@ -162,8 +160,8 @@ namespace nbody { void Node::print(int parallelId) { printBB(parallelId, this->bb); - for (vector::iterator it = this->bodies.begin(); it != this->bodies.end(); it++) { - cout << " "; + for (std::vector::iterator it = this->bodies.begin(); it != this->bodies.end(); it++) { + std::cout << " "; printBody(parallelId, *it); } } @@ -183,14 +181,14 @@ namespace nbody { return distanceToBox(this->bb, box) > this->getL(); } - void Node::setBodies(vector bodies) { + void Node::setBodies(std::vector bodies) { this->bodies = bodies; } //get local bodies - void Node::extractLocalBodiesTo(vector& bodies) { - vector result; - vector::iterator it = this->bodies.begin(); + void Node::extractLocalBodiesTo(std::vector& bodies) { + std::vector result; + std::vector::iterator it = this->bodies.begin(); while (it != this->bodies.end()) { if (!it->refinement) { diff --git a/bhtree_mpi/src/datastructures/Node.hpp b/bhtree_mpi/src/datastructures/Node.hpp index e0dcaa600c4b776ca1342cbd5933318b38bfdd4f..bc52bd91ab077819c3722e4e22524a662b67d568 100644 --- a/bhtree_mpi/src/datastructures/Node.hpp +++ b/bhtree_mpi/src/datastructures/Node.hpp @@ -9,15 +9,13 @@ #include namespace nbody { - using namespace std; - //class for storing node information class Node { friend class Tree; friend class BarnesHutTree; protected: Box bb; - vector bodies; + std::vector bodies; Node* prev; Node* next; Node* nextSibling; @@ -35,7 +33,7 @@ namespace nbody { virtual void extendBBtoCube(); virtual Box getBB(); virtual void setBB(Box bb); - virtual vector getBodies(); + virtual std::vector getBodies(); virtual void insertBefore(Node* node); virtual void insertAfter(Node* node); virtual void unlink(); @@ -45,8 +43,8 @@ namespace nbody { virtual void print(int parallelId); virtual bool sufficientForBody(Body body); virtual bool sufficientForBox(Box box); - virtual void setBodies(vector bodies); - virtual void extractLocalBodiesTo(vector& bodies); + virtual void setBodies(std::vector bodies); + virtual void extractLocalBodiesTo(std::vector& bodies); }; } diff --git a/bhtree_mpi/src/datastructures/Tree.cpp b/bhtree_mpi/src/datastructures/Tree.cpp index 66b8ab25a3f7b43772951820c5ab4accc2436dbb..d0d24ec2e6781f8391d3bc49ae51df6e9916610e 100644 --- a/bhtree_mpi/src/datastructures/Tree.cpp +++ b/bhtree_mpi/src/datastructures/Tree.cpp @@ -7,8 +7,6 @@ #include "Simulation.hpp" namespace nbody { - using namespace std; - Tree::Tree(int parallelId) { //insert dummy root node this->nodes = new Node(this); @@ -69,7 +67,7 @@ namespace nbody { accumulateForceOntoBody(body, n->representative); n = n->afterSubtree; } else if (n->leaf) { - for (vector::iterator it = n->bodies.begin(); it != n->bodies.end(); it++) { + for (std::vector::iterator it = n->bodies.begin(); it != n->bodies.end(); it++) { accumulateForceOntoBody(body, *it); } n = n->afterSubtree; @@ -83,7 +81,7 @@ namespace nbody { void Tree::computeForces() { 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++) { + for (std::vector::iterator it = n->bodies.begin(); it != n->bodies.end(); it++) { if (!it->refinement) { this->accumulateForceOnto(*it); } @@ -93,12 +91,12 @@ namespace nbody { } //get local bodies for rebuildiong tree after moving particles - vector Tree::extractLocalBodies() { - vector result; + std::vector Tree::extractLocalBodies() { + std::vector result; while (this->nodes->next != this->nodes) { if (this->nodes->next->leaf) { - for (vector::iterator it = this->nodes->next->bodies.begin(); it != this->nodes->next->bodies.end(); it++) { + for (std::vector::iterator it = this->nodes->next->bodies.begin(); it != this->nodes->next->bodies.end(); it++) { if (!it->refinement) { result.push_back(*it); } @@ -113,8 +111,8 @@ namespace nbody { } //get refinement particles required to compute forces within remote domains - vector Tree::copyRefinements(Box domain) { - vector result; + std::vector Tree::copyRefinements(Box domain) { + std::vector result; Node* current = this->nodes->next; if (!isValid(current->bb)) { @@ -155,7 +153,7 @@ namespace nbody { } //rebuild with predefined root node bounding box and bodies - void Tree::rebuild(Box domain, vector bodies) { + void Tree::rebuild(Box domain, std::vector bodies) { this->build(bodies, domain); } @@ -165,7 +163,7 @@ namespace nbody { 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++) { + for (std::vector::iterator it = n->bodies.begin(); it != n->bodies.end(); it++) { if (!it->refinement) { double pos[3] = {it->position[0], it->position[1], it->position[2]}; integrate(*it); @@ -184,7 +182,7 @@ namespace nbody { initBox(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++) { + for (std::vector::iterator it = n->bodies.begin(); it != n->bodies.end(); it++) { if (!it->refinement) { extend(result, *it); } @@ -198,7 +196,7 @@ namespace nbody { for (Node* n = this->nodes->next; n != this->nodes; n = n->next) { printBB(parallelId, n->bb); if (n->leaf) { - for (vector::iterator it = n->bodies.begin(); it != n->bodies.end(); it++) { + for (std::vector::iterator it = n->bodies.begin(); it != n->bodies.end(); it++) { if (!it->refinement) { printBody(this->parallelId, *it); } diff --git a/bhtree_mpi/src/datastructures/Tree.hpp b/bhtree_mpi/src/datastructures/Tree.hpp index 3a83cea30bb14a326827f911d90a20cc4ed5e008..53802babd7992792a5af0ff2c1fca3f2e0f38a3d 100644 --- a/bhtree_mpi/src/datastructures/Tree.hpp +++ b/bhtree_mpi/src/datastructures/Tree.hpp @@ -10,8 +10,6 @@ #include "Box.hpp" namespace nbody { - using namespace std; - class Node; class Simulation; @@ -30,17 +28,17 @@ namespace nbody { virtual ~Tree(); virtual void setSimulation(Simulation* simulation); virtual void clean(); - virtual void build(vector bodies) = 0; - virtual void build(vector bodies, Box domain) = 0; + virtual void build(std::vector bodies) = 0; + virtual void build(std::vector bodies, Box domain) = 0; virtual int numberOfChildren() = 0; virtual size_t numberOfNodes(); virtual bool isCorrect(); virtual void accumulateForceOnto(Body& body); virtual void computeForces(); - virtual vector extractLocalBodies(); - virtual vector copyRefinements(Box domain); + virtual std::vector extractLocalBodies(); + virtual std::vector copyRefinements(Box domain); virtual void rebuild(Box domain); - virtual void rebuild(Box domain, vector bodies); + virtual void rebuild(Box domain, std::vector bodies); virtual void rebuild(); virtual Box getRootBB(); virtual void print(int parallelId); diff --git a/bhtree_mpi/src/mpimain.cpp b/bhtree_mpi/src/mpimain.cpp index 484813a10827b9477c621f12fa8210051648274e..430a622a914905fc3e3533062df8cd8eacda5227 100644 --- a/bhtree_mpi/src/mpimain.cpp +++ b/bhtree_mpi/src/mpimain.cpp @@ -6,13 +6,12 @@ #include using namespace nbody; -using namespace std; int main(int argc, char* argv[]) { MPI_Init(&argc, &argv); if (argc < 2) { MPI_Finalize(); - cerr << "need input file parameter" << endl; + std::cerr << "need input file parameter" << std::endl; return -1; } MpiSimulation simulation; @@ -20,7 +19,7 @@ int main(int argc, char* argv[]) { MPI_Comm_rank(MPI_COMM_WORLD, &rank); //initialize and load particles - simulation.initialize(string(argv[1])); + simulation.initialize(std::string(argv[1])); //initial particle and domain distribution simulation.distributeBodies(); simulation.distributeDomains(); diff --git a/bhtree_mpi/src/simulation/MpiSimulation.cpp b/bhtree_mpi/src/simulation/MpiSimulation.cpp index c0b76db16000975885fce7ca6740ed5bcad0205a..6bdba65e695800f9a4dffb61672ac667dc446db9 100644 --- a/bhtree_mpi/src/simulation/MpiSimulation.cpp +++ b/bhtree_mpi/src/simulation/MpiSimulation.cpp @@ -11,8 +11,6 @@ #include "MpiSimulation.hpp" namespace nbody { - using namespace std; - MpiSimulation::MpiSimulation() { this->tree = nullptr; this->bodyType = MPI_DATATYPE_NULL; @@ -32,7 +30,7 @@ namespace nbody { } } - void MpiSimulation::initialize(string inputFile) { + void MpiSimulation::initialize(std::string inputFile) { //create MPI datatypes for bodies and domain boxes int bodyBlocklengths[6] = {1, 3, 3, 3, 1, 1}; MPI_Datatype bodyDatatypes[6] = {MPI_UNSIGNED_LONG, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_INT}; @@ -70,7 +68,7 @@ namespace nbody { //broadcast current state and terminate if input file cannot be read MPI_Bcast(&this->correctState, 1, MPI_INT, 0, MPI_COMM_WORLD); if (!this->correctState) { - cerr << "Error occurred: terminating ..." << endl; + std::cerr << "Error occurred: terminating ..." << std::endl; MPI_Type_free(&this->bodyType); MPI_Type_free(&this->boxType); MPI_Abort(MPI_COMM_WORLD, -1); @@ -98,7 +96,7 @@ namespace nbody { } //mpi send wrapper - void MpiSimulation::send(vector bodies, int target) { + void MpiSimulation::send(std::vector bodies, int target) { int bodySize = bodies.size(); SendStore* store = this->availableSendStore(bodySize); @@ -108,7 +106,7 @@ namespace nbody { } //mpi recv wrapper - int MpiSimulation::recv(vector& bodies, int source) { + int MpiSimulation::recv(std::vector& bodies, int source) { MPI_Status status; int count; @@ -125,7 +123,7 @@ namespace nbody { void MpiSimulation::distributeBodies() { //process 0 distributes bodies, others receive if (this->parallelRank == 0) { - vector nodes; + std::vector nodes; Box bb; initBox(bb); @@ -144,8 +142,8 @@ namespace nbody { mostBodiesIndex = i; } } - vector subdomains = splitLongestSide(nodes[mostBodiesIndex].getBB()); - vector buf = nodes[mostBodiesIndex].getBodies(); + std::vector subdomains = splitLongestSide(nodes[mostBodiesIndex].getBB()); + std::vector buf = nodes[mostBodiesIndex].getBodies(); Node n(nullptr); n.setBodies(extractBodies(subdomains[0], buf)); @@ -166,7 +164,7 @@ namespace nbody { } } - void MpiSimulation::distributeDomains(vector localBodies) { + void MpiSimulation::distributeDomains(std::vector localBodies) { Box localDomain; //determine local domain size @@ -196,7 +194,7 @@ namespace nbody { SendStore* MpiSimulation::availableSendStore(int numElems) { //determine if theere is a available store for non-blocking particle send //cleanup of unused send stores is also done - vector::iterator it = this->sendStores.begin(); + std::vector::iterator it = this->sendStores.begin(); while (it != this->sendStores.end()) { int completed; @@ -223,7 +221,7 @@ namespace nbody { //send out locally essential trees (local bodies needed by remote simulations, determined by remote domain size) for (int i = 0; i < this->parallelSize; i++) { if (i != this->parallelRank) { - vector refinements = this->tree->copyRefinements(this->domains[i]); + std::vector refinements = this->tree->copyRefinements(this->domains[i]); this->send(refinements, i); } @@ -231,7 +229,7 @@ namespace nbody { //receive bodies and integrate them into local tree for simulation for (int i = 0; i < this->parallelSize - 1; i++) { - vector refinements; + 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 @@ -239,14 +237,14 @@ namespace nbody { this->tree->mergeLET(refinements); } if (!this->tree->isCorrect()) { - cerr << "wrong tree" << endl; + std::cerr << "wrong tree" << std::endl; } } void MpiSimulation::buildTree() { this->tree->build(this->bodies, this->overallDomain); if (!this->tree->isCorrect()) { - cerr << "wrong tree" << endl; + std::cerr << "wrong tree" << std::endl; } } @@ -268,7 +266,7 @@ namespace nbody { //rebuild tree with new particle positions this->rebuildTree(); if (!this->tree->isCorrect()) { - cerr << "wrong tree" << endl; + std::cerr << "wrong tree" << std::endl; } } } diff --git a/bhtree_mpi/src/simulation/MpiSimulation.hpp b/bhtree_mpi/src/simulation/MpiSimulation.hpp index 89d637866ecc21d5adc0e2def288c44035b1414b..132de888db049786802b3883b894218efa2d692a 100644 --- a/bhtree_mpi/src/simulation/MpiSimulation.hpp +++ b/bhtree_mpi/src/simulation/MpiSimulation.hpp @@ -9,8 +9,6 @@ #include namespace nbody { - using namespace std; - typedef struct SendStoreStruct { Body* bodies; MPI_Request request; @@ -22,23 +20,23 @@ namespace nbody { protected: MPI_Datatype bodyType; MPI_Datatype boxType; - vector domains; + std::vector domains; Box overallDomain; - vector sendStores; + std::vector sendStores; virtual SendStore* availableSendStore(int numElems); - virtual void send(vector bodies, int target); - virtual int recv(vector& bodies, int source); + virtual void send(std::vector bodies, int target); + virtual int recv(std::vector& bodies, int source); public: MpiSimulation(); virtual ~MpiSimulation(); - virtual void initialize(string inputFile); + virtual void initialize(std::string inputFile); virtual void cleanup(); virtual int getNumberOfProcesses(); virtual int getProcessId(); virtual bool stateCorrect(); virtual void distributeBodies(); - virtual void distributeDomains(vector localBodies); + virtual void distributeDomains(std::vector localBodies); virtual void distributeDomains(Box localDomain); virtual void distributeDomains(); virtual void distributeLETs(); diff --git a/bhtree_mpi/src/simulation/Simulation.cpp b/bhtree_mpi/src/simulation/Simulation.cpp index d2cd42253e8e83c611e3ac4435792575b74a398e..9f031f6ca3698a103bd41d7c10ba003607c5d326 100644 --- a/bhtree_mpi/src/simulation/Simulation.cpp +++ b/bhtree_mpi/src/simulation/Simulation.cpp @@ -3,8 +3,6 @@ #include "Simulation.hpp" namespace nbody { - using namespace std; - Simulation::Simulation() { this->parallelRank = -1; this->parallelSize = -1; @@ -19,15 +17,15 @@ namespace nbody { this->bodies.clear(); } - void Simulation::addBodies(vector bodies) { + void Simulation::addBodies(std::vector bodies) { this->bodies.insert(this->bodies.end(), bodies.begin(), bodies.end()); } - vector Simulation::getBodies() { + std::vector Simulation::getBodies() { return this->bodies; } - bool Simulation::readInputData(string filename) { + bool Simulation::readInputData(std::string filename) { if (this->getProcessId() == 0) { this->bodies = dubinskiParse(filename); if (this->bodies.empty()) { diff --git a/bhtree_mpi/src/simulation/Simulation.hpp b/bhtree_mpi/src/simulation/Simulation.hpp index 86bcf3b690627229819c6ef57a0d57ec3ef39abc..5e2a998c3672b15328021db3e0421c303ca96f88 100644 --- a/bhtree_mpi/src/simulation/Simulation.hpp +++ b/bhtree_mpi/src/simulation/Simulation.hpp @@ -6,27 +6,25 @@ #include namespace nbody { - using namespace std; - //simulation superclass class Simulation { protected: int parallelSize; int parallelRank; int correctState; - vector bodies; + std::vector bodies; BarnesHutTree* tree; public: Simulation(); virtual ~Simulation(); - virtual void initialize(string inputFile) = 0; + virtual void initialize(std::string inputFile) = 0; virtual void cleanup() = 0; virtual void clearBodies(); - virtual void addBodies(vector bodies); - virtual vector getBodies(); + virtual void addBodies(std::vector bodies); + virtual std::vector getBodies(); virtual int getNumberOfProcesses() = 0; virtual int getProcessId() = 0; - virtual bool readInputData(string filename); + virtual bool readInputData(std::string filename); virtual Tree* getTree(); virtual void runStep() = 0; };