Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
CLBVHDualTreeTraversal.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
15
22
23namespace shamtree {
24
26 namespace impl {
27
29 struct Reference {
30 static constexpr std::string_view variant_type_name = "reference";
31 };
32
35 static constexpr std::string_view variant_type_name = "parallel_select";
36 };
37
40 static constexpr std::string_view variant_type_name = "scan_multipass";
41 };
42
45 [](const sham::DeviceScheduler_ptr &, auto &self) {
46 self.set(ScanMultipass{});
47 }};
48
51 return dtt_impl.get_default_config_list();
52 }
53
56 return dtt_impl.get_current_config();
57 }
58
61
63 void set_impl_clbvh_dual_tree_traversal(const std::string &impl) {
64 shamlog_info_ln("tree", "setting dtt implementation to impl :", impl);
65 dtt_impl.set(impl);
66 }
67
69 void autoselect_impl_clbvh_dual_tree_traversal(const sham::DeviceScheduler_ptr &dev_sched) {
70 dtt_impl.autoselect(dev_sched);
71 shamlog_info_ln(
72 "tree",
73 "defaulting dtt implementation to impl :",
75 }
76
77 } // namespace impl
78
79 template<class Tmorton, class Tvec, u32 dim>
81 sham::DeviceScheduler_ptr dev_sched,
83 shambase::VecComponent<Tvec> theta_crit,
84 bool ordered_result,
85 bool allow_leaf_lowering) {
86
87 if (bvh.is_empty()) {
89 "BVH is empty, cannot perform DTT");
90 }
91
95
96 if (!impl::dtt_impl.is_set()) {
98 }
99
100 bool ord = ordered_result;
101 bool llow = allow_leaf_lowering;
102
103 return std::visit(
105 [&](impl::Reference) {
106 return ImplRef::dtt(dev_sched, bvh, theta_crit, ord, llow);
107 },
109 return ImplPar::dtt(dev_sched, bvh, theta_crit, ord, llow);
110 },
112 return ImplSca::dtt(dev_sched, bvh, theta_crit, ord, llow);
113 },
114 },
115 impl::dtt_impl.get());
116 }
117
118 template DTTResult clbvh_dual_tree_traversal<u64, f64_3, 3>(
119 sham::DeviceScheduler_ptr dev_sched,
120 const CompressedLeafBVH<u64, f64_3, 3> &bvh,
121 shambase::VecComponent<f64_3> theta_crit,
122 bool ordered_result,
123 bool allow_leaf_lowering);
124
125 template DTTResult clbvh_dual_tree_traversal<u32, f64_3, 3>(
126 sham::DeviceScheduler_ptr dev_sched,
127 const CompressedLeafBVH<u32, f64_3, 3> &bvh,
128 shambase::VecComponent<f64_3> theta_crit,
129 bool ordered_result,
130 bool allow_leaf_lowering);
131
132} // namespace shamtree
DTTResult clbvh_dual_tree_traversal(sham::DeviceScheduler_ptr dev_sched, const CompressedLeafBVH< Tmorton, Tvec, dim > &bvh, shambase::VecComponent< Tvec > theta_crit, bool ordered_result=false, bool allow_leaf_lowering=false)
Perform dual tree traversal on a compressed leaf bounding volume hierarchy.
Generic std::variant-based implementation selector.
Drop-in replacement for the hand-rolled "global variable + enum + name mapping.
A Compressed Leaf Bounding Volume Hierarchy (CLBVH) for neighborhood queries.
bool is_empty() const
is the BVH empty ?
This header file contains utility functions related to exception handling in the code.
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
namespace to control implementation behavior
bool is_impl_set_clbvh_dual_tree_traversal()
Check if an implementation has been selected for dual tree traversal.
shamalgs::ImplVariantGlobal< Reference, ParallelSelect, ScanMultipass > dtt_impl
Currently selected dual tree traversal implementation.
void autoselect_impl_clbvh_dual_tree_traversal(const sham::DeviceScheduler_ptr &dev_sched)
Select the default implementation for dual tree traversal.
void set_impl_clbvh_dual_tree_traversal(const std::string &impl)
Set the implementation for dual tree traversal, from a config json string.
std::vector< std::string > get_default_impl_list_clbvh_dual_tree_traversal()
Get list of available dual tree traversal implementations, as config json strings.
std::string get_current_impl_clbvh_dual_tree_traversal_impl()
Get the current implementation for dual tree traversal, as a config json string.
Build an overload set out of several callables, for use with std::visit.
Result structure for dual tree traversal operations.
Parallel-select implementation of the dual tree traversal.
Naive reference CPU implementation of the dual tree traversal.
Scan-multipass implementation of the dual tree traversal.