Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
CellIterator.hpp
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
10#pragma once
11
20#include "shambackends/math.hpp"
21#include "shamcomm/logs.hpp"
22#include <utility>
23
24namespace shamtree {
25
29 const u32 *endrange;
31
33 inline bool is_id_leaf(u32 id) const { return id >= offset_leaf; }
34
45 template<class Functor_iter>
46 inline void for_each_in_cell(const u32 &cell_id, Functor_iter &&func_it) const {
47
48 bool is_leaf = is_id_leaf(cell_id);
49
50 // internal cell id or leaf id (hence the sub internal_cell_count if leaf)
51 u32 cbeg = (is_leaf) ? cell_id - offset_leaf : cell_id;
52
53 // other end of the cell range (either ourself if leaf, or the endrange if internal)
54 // this exclude the upper bound as the +1 must be made after the reordering
55 u32 cend = ((is_leaf) ? cbeg : endrange[cbeg]);
56
57 // tree cell index range
58 uint c1 = sham::min(cbeg, cend);
59 uint c2 = sham::max(cbeg, cend);
60
61 u32 _startrange = reduc_index_map[c1];
62 u32 _endrange = reduc_index_map[c2 + 1]; // <--- this +1
63
64 for (unsigned int id_s = _startrange; id_s < _endrange; id_s++) {
65
66 // recover old index before morton sort
67 uint id_b = sort_index_map[id_s];
68
69 // iteration function
70 func_it(id_b);
71 }
72 }
73 };
74
120
123 std::vector<u32> sort_index_map;
124 std::vector<u32> reduc_index_map;
125 std::vector<u32> endrange;
127
129
131 inline acc get_read_access() const {
132 return acc{sort_index_map.data(), reduc_index_map.data(), endrange.data(), offset_leaf};
133 }
134 };
135
136} // namespace shamtree
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory)
void complete_event_state(sycl::event e) const
Complete the event state of the buffer.
const T * get_read_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{}) const
Get a read-only pointer to the buffer's data.
Class to manage a list of SYCL events.
Definition EventList.hpp:31
void for_each_in_cell(const u32 &cell_id, Functor_iter &&func_it) const
Iterate over all particles in a given cell.
const u32 * reduc_index_map
Pointer to the reduction index map.
u32 offset_leaf
number of internal cells & offset to retrieve the first leaf
const u32 * endrange
Id of the other end of the index range corresponding to the cell.
const u32 * sort_index_map
Pointer to the sort index map.
bool is_id_leaf(u32 id) const
is the given id a leaf (Note that if there is no internal cell every node is a leaf)
host version of the cell iterator
u32 offset_leaf
number of internal cells & offset to retrieve the first leaf
std::vector< u32 > endrange
End range.
acc get_read_access() const
get read only accessor
std::vector< u32 > reduc_index_map
Reduction index map.
std::vector< u32 > sort_index_map
Sort index map.
Iterator over cells of a BinaryTree.
const sham::DeviceBuffer< u32 > & buf_sort_index_map
Sort index map buffer.
u32 offset_leaf
number of internal cells & offset to retrieve the first leaf
const sham::DeviceBuffer< u32 > & buf_endrange
End range buffer.
acc get_read_access(sham::EventList &deps) const
Get a read-only access to the buffers.
const sham::DeviceBuffer< u32 > & buf_reduc_index_map
Reduction index map buffer.
void complete_event_state(sycl::event e) const
Completes the event state for the associated buffers.