39template<
class Tvec,
template<
class>
class SPHKernel>
42 if (solver.solver_config.scheduler_conf.split_load_value == 0) {
44 "Scheduler load value should be greater than 0");
47 solver.init_required_fields();
49 solver.solver_config.scheduler_conf.split_load_value,
50 solver.solver_config.scheduler_conf.merge_load_value);
52 using namespace shamrock::patch;
58 shamlog_debug_ln(
"Sys",
"build local scheduler tables");
64 solver.init_ghost_layout();
66 solver.init_solver_graph();
69template<
class Tvec,
template<
class>
class SPHKernel>
72 return shamalgs::collective::allreduce_sum(sched.get_rank_count());
75template<
class Tvec,
template<
class>
class SPHKernel>
77 return totmass / get_total_part_count();
80template<
class Tvec,
template<
class>
class SPHKernel>
82 Tscal dr, std::pair<Tvec, Tvec> box) -> std::pair<Tvec, Tvec> {
84 auto [a, b] = generic::setup::generators::get_ideal_fcc_box<Tscal>(
85 dr, std::make_tuple(box.first, box.second));
89template<
class Tvec,
template<
class>
class SPHKernel>
91 Tscal dr, std::pair<Tvec, Tvec> box) -> std::pair<Tvec, Tvec> {
93 auto [a, b] = generic::setup::generators::get_ideal_fcc_box<Tscal>(
94 dr, std::make_tuple(box.first, box.second));
98template<
class Tvec,
template<
class>
class SPHKernel>
100 Tscal dr, std::pair<Tvec, Tvec> _box) {
105 using namespace shamrock::patch;
109 std::string log =
"";
111 auto make_sliced = [&]() {
112 std::vector<Tvec> vec_lst;
113 generic::setup::generators::add_particles_fcc(
115 std::make_tuple(box.lower, box.upper),
117 return box.contain_pos(r);
119 [&](Tvec r, Tscal h) {
120 vec_lst.push_back(r);
123 std::vector<std::vector<Tvec>> sliced_buf;
127 std::vector<Tvec> cur_buf;
128 for (
u32 i = 0; i < vec_lst.size(); i++) {
129 cur_buf.push_back(vec_lst[i]);
131 if (cur_buf.size() > sz_buf) {
132 sliced_buf.push_back(std::exchange(cur_buf, std::vector<Tvec>{}));
136 if (cur_buf.size() > 0) {
137 sliced_buf.push_back(std::exchange(cur_buf, std::vector<Tvec>{}));
143 std::vector<std::vector<Tvec>> sliced_buf = make_sliced();
145 for (std::vector<Tvec> to_ins : sliced_buf) {
149 = sched.get_sim_box().
template get_patch_transform<Tvec>();
153 std::vector<Tvec> vec_acc;
154 for (Tvec r : to_ins) {
155 if (patch_coord.contain_pos(r)) {
156 vec_acc.push_back(r);
160 if (vec_acc.size() == 0) {
164 log += shambase::format(
165 "\n rank = {} patch id={}, add N={} particles, coords = {} {}",
173 tmp.resize(vec_acc.size());
177 u32 len = vec_acc.size();
179 sched.pdl_old().template get_field_idx<Tvec>(
"xyz"));
180 sycl::buffer<Tvec> buf(vec_acc.data(), len);
181 f.override(buf, len);
186 sched.pdl_old().template get_field_idx<Tscal>(
"hpart"));
187 using Kernel = SPHKernel<Tscal>;
188 f.override(Kernel::hfactd * dr);
191 pdat.insert_elements(tmp);
194 sched.check_patchdata_locality_correctness();
200 sched.update_local_load_value([&](
Patch p) {
204 shamlog_debug_ln(
"setup", log);
207template<
class Tvec,
template<
class>
class SPHKernel>
209 Tscal dr, std::pair<Tvec, Tvec> _box) {
214 using namespace shamrock::patch;
218 std::string log =
"";
220 auto make_sliced = [&]() {
221 std::vector<Tvec> vec_lst;
222 generic::setup::generators::add_particles_fcc(
224 std::make_tuple(box.lower, box.upper),
226 return box.contain_pos(r);
228 [&](Tvec r, Tscal h) {
229 vec_lst.push_back(r);
232 std::vector<std::vector<Tvec>> sliced_buf;
236 std::vector<Tvec> cur_buf;
237 for (
u32 i = 0; i < vec_lst.size(); i++) {
238 cur_buf.push_back(vec_lst[i]);
240 if (cur_buf.size() > sz_buf) {
241 sliced_buf.push_back(std::exchange(cur_buf, std::vector<Tvec>{}));
245 if (cur_buf.size() > 0) {
246 sliced_buf.push_back(std::exchange(cur_buf, std::vector<Tvec>{}));
252 std::vector<std::vector<Tvec>> sliced_buf = make_sliced();
254 for (std::vector<Tvec> to_ins : sliced_buf) {
258 = sched.get_sim_box().
template get_patch_transform<Tvec>();
262 std::vector<Tvec> vec_acc;
263 for (Tvec r : to_ins) {
264 if (patch_coord.contain_pos(r)) {
265 vec_acc.push_back(r);
269 if (vec_acc.size() == 0) {
273 log += shambase::format(
274 "\n rank = {} patch id={}, add N={} particles, coords = {} {}",
282 tmp.resize(vec_acc.size());
286 u32 len = vec_acc.size();
288 sched.pdl_old().template get_field_idx<Tvec>(
"xyz"));
289 sycl::buffer<Tvec> buf(vec_acc.data(), len);
290 f.override(buf, len);
295 sched.pdl_old().template get_field_idx<Tscal>(
"hpart"));
296 using Kernel = SPHKernel<Tscal>;
297 f.override(Kernel::hfactd * dr);
300 pdat.insert_elements(tmp);
303 sched.check_patchdata_locality_correctness();
309 sched.update_local_load_value([&](
Patch p) {
313 shamlog_debug_ln(
"setup", log);
Header file describing a Node Instance.
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
SchedulerPatchData patch_data
handle the data of the patches of the scheduler
u64 crit_patch_split
splitting limit (if load value > crit_patch_split => patch split)
void scheduler_step(bool do_split_merge, bool do_load_balancing)
scheduler step
SchedulerPatchList patch_list
handle the list of the patches of the scheduler
std::unordered_set< u64 > owned_patch_id
(owned_patch_id = patch_list.build_local())
void add_root_patch()
add patch to the scheduler
std::unordered_set< u64 > build_local()
select owned patches owned by the node to rebuild local
void build_local_idx_map()
recompute id_patch_to_local_idx
void init()
Initialise the model and all the related data structures (patch scheduler in particular)
PatchDataLayer container class, the layout is described in patchdata_layout.
shambase::DistributedData< PatchData > owned_data
map container for patchdata owned by the current node (layout : id_patch,data)
This header file contains utility functions related to exception handling in the code.
GSPH Model class - high-level interface for GSPH simulations.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
This file contains the definition for the stacktrace related functionality.
Patch object that contain generic patch information.