diff --git a/bhtree_mpi/src/datastructures/BarnesHutTree.cpp b/bhtree_mpi/src/datastructures/BarnesHutTree.cpp index 61e6ecca277e297bcad99c0bfabcc57fe796630e..fadf55de25cc4efc49d0394cb5c02b978245ae5e 100644 --- a/bhtree_mpi/src/datastructures/BarnesHutTree.cpp +++ b/bhtree_mpi/src/datastructures/BarnesHutTree.cpp @@ -66,7 +66,7 @@ namespace nbody { current->leaf = false; Node* after = current->next; - for (std::vector::iterator it = subboxes.begin(); it != subboxes.end(); it++) { + for (auto it = std::begin(subboxes); it != std::end(subboxes); it++) { Node* child = new Node(current->tree); child->parent = current; @@ -75,7 +75,7 @@ namespace nbody { child->nextSibling = nullptr; child->prevSibling = nullptr; after->insertBefore(child); - if (it != subboxes.begin()) { + if (it != std::begin(subboxes)) { child->prev->nextSibling = child; child->prevSibling = child->prev; child->prev->afterSubtree = child; @@ -136,7 +136,7 @@ namespace nbody { //put all new bodies into fitting leaves, walk through tree and split Node* current; - for (std::vector::iterator it = bodies.begin(); it != bodies.end(); it++) { + for (auto it = std::begin(bodies); it != std::end(bodies); it++) { current = this->nodes->next; while (!current->leaf) { Node* child = current->next; diff --git a/bhtree_mpi/src/datastructures/Body.cpp b/bhtree_mpi/src/datastructures/Body.cpp index 6c41672d9b2e33a8bfb6e41550929e1b02d184a0..aedde8a5cd19c5c19da0d1260537a45a27c5a5e4 100644 --- a/bhtree_mpi/src/datastructures/Body.cpp +++ b/bhtree_mpi/src/datastructures/Body.cpp @@ -13,7 +13,7 @@ namespace nbody { void resetAcceleration(Body& body) { - std::fill(body.acceleration.begin(), body.acceleration.end(), 0.0); + std::fill(std::begin(body.acceleration), std::end(body.acceleration), 0.0); } //helper method for intergration @@ -75,9 +75,9 @@ namespace nbody { } bool validBody(Body body) { - 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 (!std::all_of(std::begin(body.position), std::end(body.position), validDouble)) return false; + if (!std::all_of(std::begin(body.velocity), std::end(body.velocity), validDouble)) return false; + if (!std::all_of(std::begin(body.acceleration), std::end(body.acceleration), validDouble)) return false; if (!validDouble(body.mass)) return false; return body.mass >= 0.0; } @@ -124,12 +124,12 @@ namespace nbody { void printBodies(int parallelId, std::vector bodies) { - for (std::vector::iterator it = bodies.begin(); it != bodies.end(); it++) { - printBody(parallelId, *it); + for (auto& body : bodies) { + printBody(parallelId, body); } } bool valid(std::vector bodies) { - return all_of(bodies.begin(), bodies.end(), validBody); + return std::all_of(std::begin(bodies), std::end(bodies), validBody); } } diff --git a/bhtree_mpi/src/datastructures/Box.cpp b/bhtree_mpi/src/datastructures/Box.cpp index f05eb507f237421ddc5a3765b6b891a6e9c9584a..9a210a4a6da87cb16d2d47aaec7f72c6ba6cca9f 100644 --- a/bhtree_mpi/src/datastructures/Box.cpp +++ b/bhtree_mpi/src/datastructures/Box.cpp @@ -6,8 +6,8 @@ namespace nbody { void initBox(Box& box) { - std::fill(box.min.begin(), box.min.end(), FLT_MAX); - std::fill(box.max.begin(), box.max.end(), FLT_MIN); + std::fill(std::begin(box.min), std::end(box.min), FLT_MAX); //TODO(steinret) numeric limits + std::fill(std::begin(box.max), std::end(box.max), FLT_MIN); } //extend box to form cube @@ -36,10 +36,10 @@ namespace nbody { //extend for bodies void extendForBodies(Box& box, std::vector bodies) { - for (std::vector::iterator it = bodies.begin(); it != bodies.end(); it++) { + for (const auto& body : bodies) { for (int i = 0; i < 3; i++) { - box.min[i] = std::min(it->position[i], box.min[i]); - box.max[i] = std::max(it->position[i], box.max[i]); + box.min[i] = std::min(body.position[i], box.min[i]); + box.max[i] = std::max(body.position[i], box.max[i]); } } } @@ -47,9 +47,9 @@ namespace nbody { //extract bodies within box std::vector extractBodies(Box box, std::vector& bodies) { std::vector result; - std::vector::iterator it = bodies.begin(); + auto it = std::begin(bodies); - while (it != bodies.end()) { + while (it != std::end(bodies)) { 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]) { @@ -63,14 +63,14 @@ namespace nbody { } //copy bodies within box - std::vector copyBodies(Box box, std::vector bodies) { + std::vector copyBodies(Box box, std::vector bodies) { //TODO(steinret) std::copy_if ?? std::vector result; - 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]) { - result.push_back(*it); + for (auto& body : bodies) { + if (body.position[0] >= box.min[0] && body.position[0] <= box.max[0] && + body.position[1] >= box.min[1] && body.position[1] <= box.max[1] && + body.position[2] >= box.min[2] && body.position[2] <= box.max[2]) { + result.push_back(body); } } return result; diff --git a/bhtree_mpi/src/datastructures/Node.cpp b/bhtree_mpi/src/datastructures/Node.cpp index 10253e3c58e1a00746e8df60156b19d68a1669fa..f46e24e2036578da3c548aa53bf5f33e5fd37c7e 100644 --- a/bhtree_mpi/src/datastructures/Node.cpp +++ b/bhtree_mpi/src/datastructures/Node.cpp @@ -88,8 +88,8 @@ namespace nbody { return false; } } - for (std::vector::iterator it = this->bodies.begin(); it != this->bodies.end(); it++) { - if (!isContained(*it, this->bb)) { + for (auto& body : bodies) { //TODO(steinret) std::all_of ?? + if (!isContained(body, this->bb)) { std::cerr << "bb out of bounds\n"; return false; } @@ -136,10 +136,10 @@ namespace nbody { double mass = 0.0; if (this->leaf) { - for (std::vector::iterator it = this->bodies.begin(); it != this->bodies.end(); it++) { - mass += it->mass; + for (auto& body : bodies) { + mass += body.mass; for (int i = 0; i < 3; i++) { - position[i] += it->position[i] * it->mass; + position[i] += body.position[i] * body.mass; } } } else { @@ -160,9 +160,9 @@ namespace nbody { void Node::print(int parallelId) { printBB(parallelId, this->bb); - for (std::vector::iterator it = this->bodies.begin(); it != this->bodies.end(); it++) { + for (auto& body : bodies) { std::cout << " "; - printBody(parallelId, *it); + printBody(parallelId, body); } } @@ -186,11 +186,11 @@ namespace nbody { } //get local bodies - void Node::extractLocalBodiesTo(std::vector& bodies) { + void Node::extractLocalBodiesTo(std::vector& bodies) { //TODO(steinret): std::copy_if std::vector result; - std::vector::iterator it = this->bodies.begin(); + auto it= std::begin(bodies); - while (it != this->bodies.end()) { + while (it != std::end(bodies)) { if (!it->refinement) { bodies.push_back(*it); } diff --git a/bhtree_mpi/src/datastructures/Tree.cpp b/bhtree_mpi/src/datastructures/Tree.cpp index d0d24ec2e6781f8391d3bc49ae51df6e9916610e..2e1d5c1d5bbd5fa26675dca3f99f86fd99b781ac 100644 --- a/bhtree_mpi/src/datastructures/Tree.cpp +++ b/bhtree_mpi/src/datastructures/Tree.cpp @@ -67,8 +67,8 @@ namespace nbody { accumulateForceOntoBody(body, n->representative); n = n->afterSubtree; } else if (n->leaf) { - for (std::vector::iterator it = n->bodies.begin(); it != n->bodies.end(); it++) { - accumulateForceOntoBody(body, *it); + for (auto b : n->bodies) { + accumulateForceOntoBody(body, b); } n = n->afterSubtree; } else { @@ -81,9 +81,9 @@ namespace nbody { void Tree::computeForces() { for (Node* n = this->nodes->next; n != this->nodes; n = n->next) { if (n->leaf) { - for (std::vector::iterator it = n->bodies.begin(); it != n->bodies.end(); it++) { - if (!it->refinement) { - this->accumulateForceOnto(*it); + for (auto b : n->bodies) { + if (!b.refinement) { + this->accumulateForceOnto(b); } } } @@ -96,9 +96,9 @@ namespace nbody { while (this->nodes->next != this->nodes) { if (this->nodes->next->leaf) { - for (std::vector::iterator it = this->nodes->next->bodies.begin(); it != this->nodes->next->bodies.end(); it++) { - if (!it->refinement) { - result.push_back(*it); + for (auto& b : nodes->next->bodies) { //TODO(steinret) copy_if + if (!b.refinement) { + result.push_back(b); } } } @@ -129,7 +129,7 @@ namespace nbody { current = current->afterSubtree; } else if (current->leaf) { - result.insert(result.end(), current->bodies.begin(), current->bodies.end()); + result.insert(std::end(result), std::begin(current->bodies), std::end(current->bodies)); current = current->next; } else { current = current->next; @@ -163,11 +163,11 @@ namespace nbody { for (Node* n = this->nodes->next; n != this->nodes; n = n->next) { if (n->leaf) { - 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); - extend(bb, *it); + for (auto& b : n->bodies) { + if (!b.refinement) { + double pos[3] = {b.position[0], b.position[1], b.position[2]}; + integrate(b); + extend(bb, b); } } } @@ -182,9 +182,9 @@ namespace nbody { initBox(result); for (Node* n = this->nodes->next; n != this->nodes; n = n->next) { if (n->leaf) { - for (std::vector::iterator it = n->bodies.begin(); it != n->bodies.end(); it++) { - if (!it->refinement) { - extend(result, *it); + for (auto& b : n->bodies) { + if (!b.refinement) { + extend(result, b); } } } @@ -196,9 +196,9 @@ namespace nbody { for (Node* n = this->nodes->next; n != this->nodes; n = n->next) { printBB(parallelId, n->bb); if (n->leaf) { - for (std::vector::iterator it = n->bodies.begin(); it != n->bodies.end(); it++) { - if (!it->refinement) { - printBody(this->parallelId, *it); + for (auto& b : n->bodies) { + if (!b.refinement) { + printBody(this->parallelId, b); } } } diff --git a/bhtree_mpi/src/simulation/MpiSimulation.cpp b/bhtree_mpi/src/simulation/MpiSimulation.cpp index ee236a2ab31ffe7d122e1e292821b59e145c687d..2a630052f61b0d6d5afd9e295adea019ce37de09 100644 --- a/bhtree_mpi/src/simulation/MpiSimulation.cpp +++ b/bhtree_mpi/src/simulation/MpiSimulation.cpp @@ -148,12 +148,12 @@ namespace nbody { n.setBodies(extractBodies(subdomains[0], buf)); n.setBB(subdomains[0]); - nodes.insert(nodes.begin() + mostBodiesIndex, n); + nodes.insert(std::begin(nodes) + mostBodiesIndex, n); n = Node(nullptr); n.setBodies(extractBodies(subdomains[1], buf)); n.setBB(subdomains[1]); - nodes.insert(nodes.begin() + mostBodiesIndex, n); - nodes.erase(nodes.begin() + mostBodiesIndex + 2); + nodes.insert(std::begin(nodes) + mostBodiesIndex, n); + nodes.erase(std::begin(nodes) + mostBodiesIndex + 2); } this->bodies = nodes[0].getBodies(); for (unsigned int i = 1; i < nodes.size(); i++) { @@ -194,9 +194,9 @@ 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 - std::vector::iterator it = this->sendStores.begin(); + auto it = std::begin(sendStores); - while (it != this->sendStores.end()) { + while (it != std::end(sendStores)) { int completed; MPI_Test(&it->request, &completed, MPI_STATUS_IGNORE); diff --git a/bhtree_mpi/src/simulation/Simulation.cpp b/bhtree_mpi/src/simulation/Simulation.cpp index 9f031f6ca3698a103bd41d7c10ba003607c5d326..b155c8769f07512115bbc4b536fb6880946e27a0 100644 --- a/bhtree_mpi/src/simulation/Simulation.cpp +++ b/bhtree_mpi/src/simulation/Simulation.cpp @@ -18,7 +18,7 @@ namespace nbody { } void Simulation::addBodies(std::vector bodies) { - this->bodies.insert(this->bodies.end(), bodies.begin(), bodies.end()); + this->bodies.insert(std::end(this->bodies), std::begin(bodies), std::end(bodies)); } std::vector Simulation::getBodies() {