Commit 5380b9d8 authored by Thomas Steinreiter's avatar Thomas Steinreiter
Browse files

Merge branch 'master' into refactor_bhtree_mpi

parents 8cce5175 ee0fb174
......@@ -26,6 +26,7 @@ add_subdirectory(hermite4)
add_subdirectory(dynamic_sparse_data_exchange)
add_subdirectory(naive)
add_subdirectory(bhtree_mpi)
add_subdirectory(bhtree_pthread)
#
## BHTree requies gcc compiler, so we create it as a separate projectg
......
# ==================================================================================================
# This file is part of the CodeVault project. The project is licensed under Apache Version 2.0.
# CodeVault is part of the EU-project PRACE-4IP (WP7.3.C).
#
# Author(s):
# Paul Heinzlreiter <paul.heinzlreiter@risc-software.at>
#
# ==================================================================================================
cmake_minimum_required(VERSION 3.0)
project ("bhtree_pthread")
include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/common.cmake)
# ==================================================================================================
if ("${DWARF_PREFIX}" STREQUAL "")
set(DWARF_PREFIX 4_nbody)
endif()
set(NAME ${DWARF_PREFIX}_bhtree_pthread)
enable_language(CXX)
message("** Enabling '${NAME}'")
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
set(CXX11 ${COMPILER_SUPPORTS_CXX11})
set(CXX11_FLAGS -std=c++11)
set(CMAKE_CXX_FLAGS "-std=c++11")
set(GCC_DEBUG_COMPILE_FLAGS "-g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_DEBUG_COMPILE_FLAGS}")
find_package(Threads)
include_directories(src/datastructures src/simulation)
add_subdirectory(src/datastructures)
add_subdirectory(src/simulation)
add_executable(${NAME} src/pthreadmain.cpp)
target_link_libraries(${NAME} datastructures simulation ${CMAKE_THREAD_LIBS_INIT})
This diff is collapsed.
This diff is collapsed.
0.0078125 -0.561583 -0.0653953 -0.54142 -0.106656 -0.119243 0.286915
0.0078125 4.85715 -0.32989 -1.61621 0.388497 0.20792 0.120547
0.0078125 0.593217 0.235838 -0.0272317 0.0567244 -0.0189743 -0.391682
0.0078125 0.425112 -0.0570265 -0.102289 -0.76996 0.739456 -0.169181
0.0078125 -0.0244972 0.862396 -0.000555732 0.128044 0.160373 0.206437
0.0078125 -0.513309 -0.167869 1.09716 0.349379 0.347551 -0.0848735
0.0078125 -0.264388 -0.746426 -0.542277 0.639579 -0.373554 -0.226712
0.0078125 0.417573 0.310909 0.59141 -0.0583432 -0.00363399 -0.245571
0.0078125 0.154153 0.41177 -0.10071 -0.787805 0.105596 -0.438093
0.0078125 -4.6044 1.10861 0.33756 -0.139234 -0.143949 -0.154247
0.0078125 -0.706602 -0.0472532 0.748726 -0.0727336 0.334968 0.383024
0.0078125 -0.192172 -0.337933 0.213683 -0.901189 -0.475339 -0.539601
0.0078125 0.179866 -0.268977 -0.0605338 0.223589 -0.0170284 -0.186268
0.0078125 2.96078 -1.41116 -1.33619 0.0559445 0.257364 -0.209946
0.0078125 0.172295 0.207404 -0.133516 0.0956968 0.253246 -0.88766
0.0078125 -0.514109 0.144286 -0.0704705 0.208169 0.789467 0.788264
0.0078125 -0.177585 1.20233 -0.677041 0.312979 0.106783 -0.673485
0.0078125 0.448221 0.578203 0.141096 0.214575 -0.474873 -0.165383
0.0078125 -0.0329403 2.75999 -0.5621 0.146503 0.150967 0.0838864
0.0078125 0.0113743 0.139806 0.256194 -0.140107 -0.237034 0.896022
0.0078125 -0.143066 0.451225 0.347718 -0.0682482 0.395516 0.193018
0.0078125 -0.772185 0.292455 0.255409 -0.283089 -0.0587602 -0.013165
0.0078125 0.0261782 0.18092 -1.06157 0.00541864 -0.303779 0.542291
0.0078125 -0.357691 -0.326914 1.05071 -0.101559 -0.639916 0.464835
0.0078125 -0.941137 -0.113388 -0.0571181 0.391073 0.214316 0.0434986
0.0078125 -0.206825 -0.429225 0.329095 -0.636147 -0.506036 -0.00934656
0.0078125 -0.281783 0.357202 0.593003 0.110573 -0.205025 -0.213378
0.0078125 0.14681 -0.0808604 0.366173 0.227999 -0.00231039 -0.690504
0.0078125 -0.00283323 0.497696 -0.370414 0.309578 -0.454582 0.0793015
0.0078125 -0.364943 0.0668188 0.524401 -0.441061 -0.0287642 0.44691
0.0078125 -0.593893 -0.457863 0.250611 0.449883 0.156787 0.759861
0.0078125 0.721056 0.708421 -0.0803228 0.417303 0.261432 0.255582
0.0078125 2.79888 -3.81444 5.72763 -0.0788148 -0.11228 -0.0911524
0.0078125 -0.264817 0.580976 0.324753 0.204712 0.501081 0.60662
0.0078125 0.159077 -0.194931 3.03607 0.248306 0.127007 -0.335696
0.0078125 0.384243 -0.474148 0.117701 -0.591088 0.138479 0.175385
0.0078125 0.891879 -0.981796 0.68726 0.369926 0.0436471 0.356356
0.0078125 -0.23801 -0.340323 -0.42139 -0.683381 -0.537409 0.120988
0.0078125 -0.54539 0.331053 -0.338651 -0.358726 0.405047 -0.594486
0.0078125 0.329465 -0.0716469 0.148638 -0.904883 0.196906 -0.39708
0.0078125 -0.245302 0.0406106 -0.0246707 -0.948876 -0.0264139 -0.285205
0.0078125 -0.0547374 -0.214788 0.548032 0.373441 0.48664 -0.739805
0.0078125 -0.808209 -0.785836 -0.487431 -0.130457 -0.260229 0.137378
0.0078125 0.130226 0.251818 -0.27214 0.72646 0.0983734 -0.768273
0.0078125 0.816609 0.638435 -0.602271 0.201578 -0.0997548 0.0533556
0.0078125 0.0335484 0.160705 -0.604803 -0.458248 -0.328877 -0.231626
0.0078125 0.289742 0.0851022 0.296247 0.0590116 -0.146066 -0.260767
0.0078125 0.803008 0.235945 1.32902 -0.182219 -0.204981 0.274746
0.0078125 -0.11325 0.0231081 0.692128 0.422542 -0.281747 0.117922
0.0078125 0.839393 -0.790337 0.371333 0.0761422 -0.195154 -0.120698
0.0078125 -0.376874 0.196914 -0.427419 0.378496 -0.0721329 0.818237
0.0078125 -0.0851764 -0.633248 -0.728609 -0.0371911 0.124373 0.443528
0.0078125 1.26564 -0.693253 0.124148 -0.0656925 -0.31456 0.200808
0.0078125 0.540138 0.838819 0.594402 -0.0695378 0.267221 -0.0535934
0.0078125 0.718664 -0.866464 0.43578 0.0328011 0.624732 -0.622752
0.0078125 0.0709217 0.289103 -1.18601 -0.541128 -0.273111 0.259376
0.0078125 0.165375 0.253924 0.308721 -0.302709 0.206246 -0.421021
0.0078125 0.30295 0.45103 -1.18285 -0.675552 -0.309687 -0.195789
0.0078125 1.91037 1.48552 1.6489 -0.0572668 -0.167331 -0.0485191
0.0078125 -0.203928 2.21686 0.365465 0.370893 -0.154465 -0.229943
0.0078125 -0.141565 0.121267 -0.190342 -0.324136 1.06391 -0.252832
0.0078125 0.882969 0.318097 -1.22108 0.0106645 -0.0603032 0.28376
0.0078125 1.68156 -0.970704 0.955315 -0.112403 -0.0539148 0.155832
0.0078125 1.29341 -0.0844446 3.79333 0.151948 0.0359666 0.0193931
0.0078125 0.291916 -0.66188 -0.572157 0.484397 0.00628293 0.460706
0.0078125 -1.71339 0.0747937 -0.45653 0.0883908 0.167971 0.195311
0.0078125 -0.565081 0.567638 -0.0358912 0.800165 0.147079 0.0321938
0.0078125 -0.0303471 -0.111797 0.112722 0.424151 0.598671 0.590271
0.0078125 -0.0155903 0.643337 0.613217 -0.786376 -0.700514 -0.0612197
0.0078125 -0.588343 0.0779538 -0.0846362 0.374293 -0.114633 0.671602
0.0078125 0.355267 0.525516 0.161555 0.824373 0.192267 0.255344
0.0078125 -0.198203 -0.0887213 -0.0108636 -1.21444 -0.161621 0.269907
0.0078125 -0.740972 0.0310601 -0.0423134 0.387634 0.0924198 -0.251584
0.0078125 0.569375 -0.262927 0.311267 -0.144403 0.290308 0.570586
0.0078125 0.360238 0.275522 0.170519 0.617527 -0.611949 -0.69053
0.0078125 -0.0064339 0.0887533 -0.0978778 -0.0160654 0.323666 0.357143
0.0078125 -1.79199 0.537769 0.210823 -0.0734387 0.062987 0.294745
0.0078125 0.387556 0.057369 -0.242046 0.531833 -0.105745 0.0137902
0.0078125 -0.10987 0.0479845 -0.218173 -0.0169497 0.664175 -0.415118
0.0078125 -0.106214 -0.722274 -0.365652 0.0282852 -0.0869342 -0.167453
0.0078125 0.342844 -0.542864 0.726504 -0.102149 -0.623591 -0.130544
0.0078125 -0.725277 -0.447739 0.0147589 0.334304 -0.515125 -0.0301856
0.0078125 0.969074 0.310329 0.759039 -0.383845 -0.242729 0.294695
0.0078125 -0.232385 0.0059024 -0.2828 -0.386223 -0.814792 -0.160994
0.0078125 -0.0367583 -0.334258 0.496887 0.0163862 -0.119574 0.551395
0.0078125 1.80821 -2.26263 0.369196 0.378456 0.0762455 0.10637
0.0078125 0.22541 0.634131 0.4466 0.380069 0.33213 0.19809
0.0078125 0.0552975 0.094628 0.187535 0.368528 -0.245958 -0.299205
0.0078125 -0.179737 -0.28451 -0.195189 -0.0659155 0.575576 -0.02493
0.0078125 -0.441753 -0.187676 0.2657 -0.66282 -0.61283 0.237689
0.0078125 -1.0584 1.07063 0.0816655 0.162732 -0.0782579 -0.289376
0.0078125 0.230667 0.562123 0.422895 -0.415535 -0.272224 0.466389
0.0078125 -0.431271 0.941882 0.470262 -0.428963 0.124475 0.548398
0.0078125 -0.90623 0.0540758 0.705174 -0.65604 -0.471803 -0.0829079
0.0078125 0.283421 0.0618804 0.00101862 -0.37221 0.120181 -0.671326
0.0078125 -0.355921 -0.902373 -1.88237 0.151032 0.290279 0.0015099
0.0078125 -0.325479 0.195602 0.561911 0.640861 0.337243 -0.666231
0.0078125 -0.632459 -0.804121 0.891581 0.180773 -0.684755 0.280759
0.0078125 -0.223916 -0.204337 0.297543 -0.287444 0.570525 -0.375597
0.0078125 -0.584846 -0.911429 -1.65126 0.132051 -0.284014 0.30882
0.0078125 -0.842329 -1.01827 -2.70198 -0.15094 -0.000502812 0.0806111
0.0078125 -2.09965 0.802379 0.603029 0.111709 -0.804081 0.0606155
0.0078125 0.118922 -0.588657 0.0372491 -0.337486 -0.720821 0.0795549
0.0078125 0.191582 -0.275471 0.117875 0.234431 0.285525 0.584854
0.0078125 -0.0107175 0.324655 0.392256 -0.595578 0.0244533 -0.0750755
0.0078125 0.197357 -0.500572 0.189353 -0.708116 0.726939 0.181972
0.0078125 -0.213168 -0.232943 0.525649 0.613535 0.583002 -0.524635
0.0078125 0.016383 0.643089 0.118701 -0.0746607 0.74576 0.381188
0.0078125 -2.02546 2.33873 -6.56685 -0.201238 -0.063544 -0.210165
0.0078125 -1.37384 -0.345245 -0.448207 0.0937159 0.726463 0.34983
0.0078125 -0.53505 0.194187 0.138623 0.438337 0.321718 0.497497
0.0078125 0.393129 0.396318 0.202799 -0.232077 0.673534 0.199969
0.0078125 1.65585 1.51472 0.754924 0.12452 -0.0738437 -0.20314
0.0078125 0.050741 -0.176364 0.0845731 -0.0118441 -0.275304 0.517822
0.0078125 -0.69282 -0.315554 0.336758 -0.124871 -0.0726118 -0.48678
0.0078125 -4.49378 0.158931 -1.67364 0.0428135 -0.368193 -0.202662
0.0078125 0.151977 -0.12238 -0.232372 0.286413 0.547764 -0.624027
0.0078125 -0.151974 -0.456876 -1.01505 -0.0888675 -0.0692045 -0.0961761
0.0078125 0.0172932 0.450232 0.127097 0.213424 -0.394811 0.283268
0.0078125 -0.258719 -0.221393 -0.687557 -0.312324 -0.884635 -0.47024
0.0078125 0.336438 -0.0474728 -0.0363989 0.335346 -0.189319 -0.562923
0.0078125 -0.000520494 -0.0606313 0.0370563 0.710945 0.430098 0.427973
0.0078125 0.554218 -0.381913 -0.291806 -0.0101308 -0.750426 -0.212414
0.0078125 0.202166 0.0601055 0.246007 -0.0454595 0.846733 -0.225464
0.0078125 0.320666 0.208203 -0.248511 0.366862 -0.183597 0.203534
0.0078125 0.046223 -0.839237 0.541238 0.469524 -0.378442 -0.644366
0.0078125 -1.59413 -0.316486 -2.43866 0.00824341 -0.178253 -0.151392
0.0078125 3.07216 -2.60047 -3.83296 0.220359 0.130017 -0.173491
This diff is collapsed.
This diff is collapsed.
#include "BarnesHutTree.hpp"
#include "Node.hpp"
#include "Box.hpp"
#include <iostream>
#include <climits>
#include <cfloat>
namespace nbody {
using namespace std;
BarnesHutTree::BarnesHutTree(int parallelId) : Tree(parallelId) {
}
BarnesHutTree::~BarnesHutTree() {
}
//determine octree subboxes
vector<Box> BarnesHutTree::splitBB(Node* node) {
return octreeSplit(node->getBB());
}
int BarnesHutTree::numberOfChildren() {
return 8;
}
//update upper tree nodes according to moved particles
void BarnesHutTree::update() {
//iterate for updating representatives
Node* current = this->nodes->prev;
while (current != this->nodes) {
current->representative.id = ULONG_MAX;
current->representative.mass = 0.0;
current->representative.position[0] = 0.0;
current->representative.position[1] = 0.0;
current->representative.position[2] = 0.0;
if (current->leaf) {
for (unsigned int i = 0; i < current->bodies.size(); i++) {
current->representative.mass += current->bodies[i].mass;
for (int j = 0; j < 3; j++) {
current->representative.position[j] += current->bodies[i].position[j] * current->bodies[i].mass;
}
}
} else {
Node* child = current->next;
do {
current->representative.mass += child->representative.mass;
for (int j = 0; j < 3; j++) {
current->representative.position[j] += child->representative.position[j] * child->representative.mass;
}
child = child->nextSibling;
} while (child != nullptr);
}
for (int j = 0; j < 3; j++) {
if (current->representative.mass > FLT_EPSILON) {
current->representative.position[j] /= current->representative.mass;
} else {
current->representative.position[j] = 0.0;
}
}
current = current->prev;
}
}
//split tree node into sub-boxes during tree build
void BarnesHutTree::split(Node* current) {
vector<Box> subboxes = BarnesHutTree::splitBB(current);
current->leaf = false;
Node* after = current->next;
for (vector<Box>::iterator it = subboxes.begin(); it != subboxes.end(); it++) {
Node* child = new Node(current->tree);
child->parent = current;
child->bb = *it;
child->bodies = copyBodies(*it, current->bodies);
child->nextSibling = nullptr;
child->prevSibling = nullptr;
after->insertBefore(child);
if (it != subboxes.begin()) {
child->prev->nextSibling = child;
child->prevSibling = child->prev;
child->prev->afterSubtree = child;
}
}
after->prev->afterSubtree = current->afterSubtree;
current->bodies.clear();
}
//initialize tree for build process
void BarnesHutTree::init(vector<Body> bodies, Box domain) {
Node* current;
this->clean();
if (bodies.empty()) return;
//insert root node
this->nodes->insertAfter(new Node(this));
current = this->nodes->next;
//assign bodies to root node
current->bodies = bodies;
//setup proper bounding box
current->bb = domain;
current->extendBBforBodies();
current->extendBBtoCube();
current->afterSubtree = current->next;
}
//check if split is required and perform it
bool BarnesHutTree::splitNode(Node* current) {
bool result = current->isSplitable();
if (result) {
split(current);
}
return result;
}
//build tree with given domain
void BarnesHutTree::build(vector<Body> bodies, Box domain) {
this->init(bodies, domain);
//iterate over existing boxes and split if it contains too much bodies
BarnesHutTree::splitSubtree(this->nodes->next);
this->update();
}
//build tree
void BarnesHutTree::build(vector<Body> bodies) {
Box bb;
initBox(bb);
extendForBodies(bb, bodies);
this->build(bodies, bb);
}
//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<Body> bodies) {
//put all new bodies into fitting leaves, walk through tree and split
Node* current;
for (vector<Body>::iterator it = bodies.begin(); it != bodies.end(); it++) {
current = this->nodes->next;
while (!current->leaf) {
Node* child = current->next;
while (child != nullptr && !contained(child->getBB(), it->position)) {
child = child->nextSibling;
}
if (child != nullptr) {
current = child;
}
current = child;
}
current->bodies.push_back(*it);
current->bodies.back().refinement = true;
}
current = this->nodes->next;
while (current != this->nodes) {
this->splitNode(current);
current = current->next;
}
this->update();
}
//node splitting if required
void BarnesHutTree::splitSubtree(Node* root) {
bool toSplitLeft;
Node* current = root;
do {
toSplitLeft = false;
while (current != root->afterSubtree) {
if (current->isSplitable()) {
split(current);
toSplitLeft = true;
}
current = current->next;
}
} while (toSplitLeft);
}
//checking for tree validity
bool BarnesHutTree::isCorrect() {
for (Node* current = this->nodes->next; current != this->nodes; current = current->next) {
if (!current->isCorrect()) {
return false;
}
}
return true;
}
}
#ifndef BARNES_HUT_TREE_HPP
#define BARNES_HUT_TREE_HPP
#include "Tree.hpp"
#include "Box.hpp"
namespace nbody {
using namespace std;
class Node;
class BarnesHutTree : public Tree {
protected:
static vector<Box> splitBB(Node* node);
static bool splitNode(Node* current);
virtual void update();
virtual void init(vector<Body> bodies, Box domain);
static void split(Node* current);
public:
BarnesHutTree(int parallelId);
virtual ~BarnesHutTree();
virtual void build(vector<Body> bodies);
virtual void build(vector<Body> bodies, Box domain);
virtual void mergeLET(vector<Body> bodies);
virtual int numberOfChildren();
static void splitSubtree(Node* root);
virtual bool isCorrect();
};
}
#endif
#include <climits>
#include <cfloat>
#include <algorithm>
#include <iostream>
#include "BarnesHutTreeThreaded.hpp"
#include "Node.hpp"
#include "PthreadSimulation.hpp"
namespace nbody {
using namespace std;
BarnesHutTreeThreaded::BarnesHutTreeThreaded(int parallelId) : BarnesHutTree(parallelId) {
pthread_mutex_init(&this->nodesToProcess.mutex, nullptr);
}
BarnesHutTreeThreaded::~BarnesHutTreeThreaded() {
pthread_mutex_destroy(&this->nodesToProcess.mutex);
}
void BarnesHutTreeThreaded::addNodeToProcess(Node* node, NodesToProcess* store) {
pthread_mutex_lock(&store->mutex);
store->toProcess.push_back(node);
pthread_mutex_unlock(&store->mutex);
}
Node* BarnesHutTreeThreaded::getNodeToProcess(NodesToProcess* store) {
Node* result;
pthread_mutex_lock(&store->mutex);
if (store->toProcess.empty()) {
result = nullptr;
} else {
result = store->toProcess.back();
store->toProcess.pop_back();
vector<pthread_t>::iterator it = std::find(store->processing.begin(), store->processing.end(), pthread_self());
if (it == store->processing.end()) {
store->processing.push_back(pthread_self());
}
}
pthread_mutex_unlock(&store->mutex);
return result;
}
void BarnesHutTreeThreaded::checkNodeProcessingFinished(NodesToProcess* store) {
pthread_mutex_lock(&store->mutex);
if (store->toProcess.empty()) {
vector<pthread_t>::iterator it = std::find(store->processing.begin(), store->processing.end(), pthread_self());
if (it != store->processing.end()) {
store->processing.erase(it);
}
}
pthread_mutex_unlock(&store->mutex);
}
bool BarnesHutTreeThreaded::hasNodeProcessingFinished(NodesToProcess* store) {
bool finished;
pthread_mutex_lock(&store->mutex);
finished = store->processing.empty() && store->toProcess.empty();
pthread_mutex_unlock(&store->mutex);
return finished;
}
void BarnesHutTreeThreaded::updateNode(Node* current) {
current->representative.id = ULONG_MAX;
current->representative.mass = 0.0;
current->representative.position[0] = 0.0;
current->representative.position[1] = 0.0;
current->representative.position[2] = 0.0;
for (size_t i = 0; i < current->bodies.size(); i++) {
current->representative.mass += current->bodies[i].mass;
for (size_t j = 0; j < 3; j++) {
current->representative.position[j] += current->bodies[i].position[j] * current->bodies[i].mass;
}
}
for (size_t j = 0; j < 3; j++) {
if (current->representative.mass > FLT_EPSILON) {
current->representative.position[j] /= current->representative.mass;
} else {
current->representative.position[j] = 0.0;
}
}
}
void* BarnesHutTreeThreaded::build(void* data) {
NodesToProcess* toProcess = (NodesToProcess*) data;
while (!BarnesHutTreeThreaded::hasNodeProcessingFinished(toProcess)) {
Node* current = BarnesHutTreeThreaded::getNodeToProcess(toProcess);
if (current != nullptr) {
BarnesHutTreeThreaded::updateNode(current);
if (BarnesHutTree::splitNode(current)) {
Node* child = current->next;
while (child != nullptr) {
BarnesHutTreeThreaded::addNodeToProcess(child, toProcess);
child = child->nextSibling;
}
}
}
BarnesHutTreeThreaded::checkNodeProcessingFinished(toProcess);
}
pthread_exit(nullptr);
}
void* BarnesHutTreeThreaded::computeMove(void* data) {
NodesToProcess* toProcess = (NodesToProcess*) data;
vector<Body*> localBodies;
while (!BarnesHutTreeThreaded::hasNodeProcessingFinished(toProcess)) {
Node* current = BarnesHutTreeThreaded::getNodeToProcess(toProcess);
if (current != nullptr) {
for (vector<Body>::iterator it = current->bodies.begin(); it != current->bodies.end(); it++) {
if (!it->refinement) {
toProcess->tree->accumulateForceOnto(*it);
localBodies.push_back(&(*it));
}
}
}
BarnesHutTreeThreaded::checkNodeProcessingFinished(toProcess);
}
while (!localBodies.empty()) {
integrate(*(localBodies.back()));
localBodies.pop_back();
}
pthread_exit(nullptr);
}
void BarnesHutTreeThreaded::clearNodesToProcess() {
this->nodesToProcess.processing.clear();
this->nodesToProcess.toProcess.clear();
}
void BarnesHutTreeThreaded::build(vector<Body> bodies, Box domain) {
this->init(bodies, domain);
this->clearNodesToProcess();
this->nodesToProcess.toProcess.push_back(this->nodes->next);
for (int i = 0; i < this->simulation->getNumberOfProcesses(); i++) {
pthread_create((&((PthreadSimulation*) this->simulation)->threads[i]), nullptr, BarnesHutTreeThreaded::build, &this->nodesToProcess);
}
for (int i = 0; i < this->simulation->getNumberOfProcesses(); i++) {
void* retVal;
pthread_join(((PthreadSimulation*) this->simulation)->threads[i], &retVal);
}
if (this->isCorrect()) {
cout << "correct" << endl;
}
}
void BarnesHutTreeThreaded::computeMove() {
//accumulate forces for whole tree (local particles) and move particles
this->nodesToProcess.tree = this;
for (Node* n = this->nodes->next; n != this->nodes; n = n->next) {
if (n->leaf && !n->bodies.empty()) {
this->nodesToProcess.toProcess.push_back(n);
}
}
for (int i = 0; i < this->simulation->getNumberOfProcesses(); i++) {
pthread_create((&((PthreadSimulation*) this->simulation)->threads[i]), nullptr, BarnesHutTreeThreaded::computeMove, &this->nodesToProcess);
}
for (int i = 0; i < this->simulation->getNumberOfProcesses(); i++) {
void* retVal;
pthread_join(((PthreadSimulation*) this->simulation)->threads[i], &retVal);
}
}
}
#ifndef BARNES_HUT_TREE_THREADED_HPP
#define BARNES_HUT_TREE_THREADED_HPP
#include <vector>