Skip to content

Commit

Permalink
Clean all tree nodes in first iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalobg committed Jun 23, 2024
1 parent 2e7dbc4 commit 505dcbc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/barnes_hut.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
using clock_timer = std::chrono::steady_clock;

template<typename T, typename Index_t>
void barnes_hut_step(System<T>& system, Arguments arguments, AtomicQuadTree<T, Index_t> tree) {
void barnes_hut_step(System<T>& system, Arguments arguments, AtomicQuadTree<T, Index_t> tree, bool first) {
auto start_timer = clock_timer::now();

clear_tree(system, tree);
clear_tree(system, tree, first? tree.capacity : tree.bump_allocator->load(memory_order_relaxed));
compute_bounded_atomic_quad_tree(system, tree);
build_atomic_tree(system, tree);
auto built_tree_timer = clock_timer::now();
Expand Down Expand Up @@ -57,8 +57,8 @@ void run_barnes_hut(System<T>& system, Arguments arguments) {
std::cout << "Tree init complete\n";
}
for (size_t step = 0; step < arguments.steps; step++) {
barnes_hut_step<T, Index_t>(system, arguments, tree);
saver.save_points(system);
barnes_hut_step<T, Index_t>(system, arguments, tree, step == 0);
saver.save_points(system);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/kernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ auto compute_bounded_atomic_quad_tree(System<T>& system, AtomicQuadTree<T, Index
}

template<typename T, typename Index_t>
auto clear_tree(System<T>& system, AtomicQuadTree<T, Index_t> tree) {
auto clear_tree(System<T>& system, AtomicQuadTree<T, Index_t> tree, Index_t last_node) {
// clear the tree, ready for next iteration
auto r = system.body_indices();
std::for_each_n(
std::execution::par_unseq,
r.begin(), tree.bump_allocator->load(memory_order_acquire),
r.begin(), last_node,
[tree] (auto tree_index) mutable { tree.clear(tree_index); });
}

Expand Down

0 comments on commit 505dcbc

Please sign in to comment.