Skip to content
Snippets Groups Projects
Commit 9273bae1 authored by Thomas Steinreiter's avatar Thomas Steinreiter
Browse files

* use range for

  * do squared comparison instead of sqrt
  * remove unused Node::parent
  * forwarding reference optimization for MPI send
parent 8f7b6919
Branches
No related merge requests found
......@@ -128,18 +128,18 @@ namespace nbody {
//put all new bodies into fitting leaves, walk through tree and split
Node* current;
for (auto it = std::begin(bodies); it != std::end(bodies); it++) {
for (auto& b : bodies) {
current = nodes->next;
while (!current->leaf) {
Node* child = current->next;
while (child != nullptr && !child->getBB().contained(it->position)) {
while (child != nullptr && !child->getBB().contained(b.position)) {
child = child->nextSibling;
}
//TODO(pheinzlr): check for child == nullptr?
current = child;
}
current->bodies.push_back(*it);
current->bodies.push_back(b);
current->bodies.back().refinement = true;
}
current = nodes->next;
......
......@@ -157,7 +157,7 @@ namespace nbody {
for (std::size_t i = 0; i < 3; i++) {
distance += (representative.position[i] - body.position[i]) * (representative.position[i] - body.position[i]);
}
return sqrt(distance) > getL(); // TODO(steinret): do squared comparison
return distance > std::pow(getL(), 2.0);
}
//check if node is sufficient for force evaluation for all bodies in box
......
......@@ -20,7 +20,6 @@ namespace nbody {
Node* next{ this };
Node* nextSibling{ nullptr };
Node* prevSibling{ nullptr };
Node* parent{ nullptr };
Node* afterSubtree{ nullptr };
bool leaf{ true };
Tree* tree{ nullptr };
......
......@@ -84,13 +84,13 @@ namespace nbody {
}
//mpi send wrapper
void MpiSimulation::send(const std::vector<Body>& bodies, int target) {
void MpiSimulation::send(std::vector<Body>&& bodies, int target) {
const auto bodySize = bodies.size();
//do unblocking send
auto store = std::make_unique<SendStore>(bodies); //TODO(steinret): ask ponweist if this could be done w/o unique_ptr
auto store = std::make_unique<SendStore>(std::move(bodies)); //TODO(steinret): ask ponweist if this could be done w/o unique_ptr
MPI_Isend(store->bodies.data(), bodySize, 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);
sendStores.push_back(std::move(store));
}
......@@ -189,9 +189,9 @@ namespace nbody {
//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<std::size_t>(parallelSize); i++) {
if (i != static_cast<std::size_t>(parallelRank)) {
std::vector<Body> refinements = tree->copyRefinements(domains[i]);
auto refinements = tree->copyRefinements(domains[i]);
send(refinements, i);
send(std::move(refinements), i);
}
}
......
......@@ -13,7 +13,7 @@ namespace nbody {
struct SendStore {
std::vector<Body> bodies;
MPI_Request request{ MPI_REQUEST_NULL };
SendStore(const std::vector<Body>& b):bodies(b) {};
SendStore(std::vector<Body>&& b):bodies(std::move(b)) {};
};
//MPI simulation
......@@ -26,7 +26,7 @@ namespace nbody {
std::vector<std::unique_ptr<SendStore>> sendStores;
void flushSendStore();
virtual void send(const std::vector<Body>& bodies, int target);
virtual void send(std::vector<Body>&& bodies, int target);
virtual int recv(std::vector<Body>& bodies, int source);
public:
MpiSimulation(const std::string& inputFile);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment