Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
GeneratorFromOtherContext.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
22#include "shammath/AABB.hpp"
26
28
29 template<class Tvec>
31 using Tscal = shambase::VecComponent<Tvec>;
34 using LatticeIter = typename shammath::LatticeCubic<Tvec>::IteratorDiscontinuous;
35
36 ShamrockCtx &context;
38
39 public:
40 GeneratorFromOtherContext(ShamrockCtx &context, ShamrockCtx &context_other)
41 : context(context) {
42
43 context_other.sched->for_each_patchdata_nonempty(
45 data_other.add_obj(patch.id_patch, pdat.duplicate());
46 });
47 }
48
49 bool is_done() {
50 bool ret = true;
51 data_other.for_each([&](u64 id_patch, shamrock::patch::PatchDataLayer &pdat) {
52 if (pdat.get_obj_cnt() > 0) {
53 ret = false;
54 }
55 });
56 return ret;
57 }
58
60 StackEntry stack_loc{};
61
62 using namespace shamrock::patch;
63 PatchScheduler &sched = shambase::get_check_ref(context.sched);
64 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
65
66 // Make a patchdata to receive the data from the other context
67 PatchDataLayer tmp(sched.get_layout_ptr_old());
68
69 data_other.for_each([&](u64 id_patch, shamrock::patch::PatchDataLayer &pdat) {
70 if (pdat.get_obj_cnt() > 0 && tmp.get_obj_cnt() < nmax) {
71
72 u32 remain_to_gen = nmax - tmp.get_obj_cnt();
73 remain_to_gen = std::min(remain_to_gen, pdat.get_obj_cnt());
74
75 if (remain_to_gen == 0) {
76 return;
77 }
78
79 sham::DeviceBuffer<u32> indices(remain_to_gen, dev_sched);
80
81 indices.fill_lambda([&](u32 i) {
82 return i;
83 });
84
85 pdat.extract_elements(indices, tmp);
86 }
87 });
88
89 return tmp;
90 }
91
92 std::string get_name() { return "GeneratorFromOtherContext"; }
93 ISPHSetupNode_Dot get_dot_subgraph() { return ISPHSetupNode_Dot{get_name(), 0, {}}; }
94 };
95
96} // namespace shammodels::sph::modules
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
The MPI scheduler.
A buffer allocated in USM (Unified Shared Memory)
Represents a collection of objects distributed across patches identified by a u64 id.
iterator add_obj(u64 id, T &&obj)
Adds a new object to the collection.
void for_each(std::function< void(u64, T &)> &&f)
Applies a function to each object in the collection.
Iterator utility to generate the lattice.
utility for generating Cubic crystal lattices
bool is_done()
This function return true if the setup is done.
ISPHSetupNode_Dot get_dot_subgraph()
Get a dot subgraph describing the node and its childrens (recursively)
shamrock::patch::PatchDataLayer next_n(u32 nmax)
This function generate patchdata with at most nmax per MPI ranks This function is always assumed as c...
This class is an interface that all SPH setup nodes must implement. It describe an operation associat...
PatchDataLayer container class, the layout is described in patchdata_layout.
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...
Definition memory.hpp:110
namespace for the sph model modules
This file contains the definition for the stacktrace related functionality.
This struct is used to generate a dot graph of the setup tree.
Patch object that contain generic patch information.
Definition Patch.hpp:33
u64 id_patch
unique key that identify the patch
Definition Patch.hpp:86