30#include <nlohmann/json.hpp>
31#include <unordered_set>
53 u64 split_load_value = 0_u64;
54 u64 merge_load_value = 0_u64;
65 {
"split_load_value", p.split_load_value},
66 {
"merge_load_value", p.merge_load_value},
77 j.at(
"split_load_value").get_to<
u64>(p.split_load_value);
78 j.at(
"merge_load_value").get_to<
u64>(p.merge_load_value);
96 std::shared_ptr<shamrock::patch::PatchDataLayerLayout> pdl_ptr;
113 inline std::shared_ptr<shamrock::patch::PatchDataLayerLayout> get_layout_ptr_old()
const {
125 void init_mpi_required_types();
127 void free_mpi_required_types();
130 const std::shared_ptr<shamrock::patch::PatchDataLayerLayout> &pdl_ptr,
136 std::string dump_status();
141 p.load_value = load_function(p);
146 template<
class vectype>
147 std::tuple<vectype, vectype> get_box_tranform();
149 template<
class vectype>
150 std::tuple<vectype, vectype> get_box_volume();
152 bool should_resize_box(
bool node_in);
161 template<
class vectype>
164 if (!pdl_old().check_main_field_type<vectype>()) {
165 std::invalid_argument(
166 std::string(
"the main field is not of the correct type to call this function\n")
167 +
"fct called : " + __PRETTY_FUNCTION__
168 +
"current patch data layout : " + pdl_old().get_description_str());
173 shamlog_debug_ln(
"PatchScheduler",
"box resized to :", bmin, bmax);
185 void make_patch_base_grid(std::array<u32, dim> patch_count);
193 template<
class vectype>
201 void check_patchdata_locality_correctness();
204 void dump_local_patches(std::string filename);
206 std::vector<std::unique_ptr<shamrock::patch::PatchDataLayer>> gather_data(
u32 rank);
231 void sync_build_LB(
bool global_patch_sync,
bool balance_load);
235 return get_sim_box().template get_patch_transform<vec>();
257 template<
class Function>
265 fct(patch_id, cur_p, pdat);
270 template<
class Function>
271 inline void for_each_patch(Function &&fct) {
279 fct(patch_id, cur_p);
284 inline void for_each_global_patch(
287 if (!p.is_err_mode()) {
293 inline void for_each_local_patch(
296 if (!p.is_err_mode()) {
302 inline void for_each_local_patchdata(
306 if (!p.is_err_mode()) {
312 inline void for_each_local_patch_nonempty(
318 if ((!cur_p.
is_err_mode()) && (!pdat.is_empty())) {
324 inline u32 get_patch_rank_owner(
u64 patch_id) {
330 inline void for_each_patchdata_nonempty(
336 if ((!cur_p.
is_err_mode()) && (!pdat.is_empty())) {
347 using namespace shamrock::patch;
349 ret.
add_obj(id_patch, fct(cur_p, pdat));
358 using namespace shamrock::patch;
362 return shamalgs::collective::fetch_all_simple<T, Patch>(
371 using namespace shamrock::patch;
373 return shamalgs::collective::fetch_all_storeload<T, Patch>(
384 using namespace shamrock::patch;
386 ret.
add_obj(id_patch, fct(cur_p, pdat));
389 return distrib_data_local_to_all_simple(ret);
397 using namespace shamrock::patch;
399 ret.
add_obj(id_patch, fct(cur_p, pdat));
402 return distrib_data_local_to_all_load_store(ret);
417 inline u64 get_rank_count() {
419 using namespace shamrock::patch;
422 num_obj += pdat.get_obj_cnt();
428 inline u64 get_total_obj_count() {
430 u64 part_cnt = get_rank_count();
431 return shamalgs::collective::allreduce_sum(part_cnt);
435 inline std::unique_ptr<sycl::buffer<T>> rankgather_field(
u32 field_idx) {
437 std::unique_ptr<sycl::buffer<T>> ret;
439 auto fd = pdl_old().
get_field<T>(field_idx);
442 u64 num_obj = get_rank_count();
445 ret = std::make_unique<sycl::buffer<T>>(num_obj * nvar);
447 using namespace shamrock::patch;
454 if (pdat.get_obj_cnt() > 0) {
455 write_with_offset_into(
456 shamsys::instance::get_compute_scheduler().get_queue(),
458 pdat.get_field<T>(field_idx).get_buf(),
460 pdat.get_obj_cnt() * nvar);
462 ptr += pdat.get_obj_cnt() * nvar;
492 template<
class Function,
class Pfield>
493 inline void compute_patch_field(Pfield &field, MPI_Datatype &dtype, Function &&lambda) {
501 field.local_nodes_value[idx] = lambda(
502 shamsys::instance::get_compute_queue(),
508 field.build_global(dtype);
511 inline auto get_node_set_edge_patchdata_layer_refs() {
515 using namespace shamrock::patch;
521 return std::make_shared<decltype(node_set_edge)>(std::move(node_set_edge));
534 nlohmann::json serialize_patch_metadata();
537 void split_patches(std::unordered_set<u64> split_rq);
538 void merge_patches(std::unordered_set<u64> merge_rq);
540 void set_patch_pack_values(std::unordered_set<u64> merge_rq);
function to run load balancing with the hilbert curve
Node that applies a custom function to modify connected edges.
Defines the PatchDataLayerRefs class for managing distributed references to patch data layers.
void to_json(nlohmann::json &j, const PatchSchedulerConfig &p)
Converts a PatchSchedulerConfig object to a JSON object.
void from_json(const nlohmann::json &j, PatchSchedulerConfig &p)
Deserializes a PatchSchedulerConfig object from a JSON object.
Header file for the patch struct and related function.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
void set_coord_domain_bound(std::tuple< vectype, vectype > box)
modify the bounding box of the patch domain
void for_each_patch_data(Function &&fct)
for each macro for patchadata example usage
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)
PatchTree patch_tree
handle the tree structure of the patches
void scheduler_step(bool do_split_merge, bool do_load_balancing)
scheduler step
void set_coord_domain_bound(vectype bmin, vectype bmax)
modify the bounding box of the patch domain
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())
std::vector< u64 > add_root_patches(std::vector< shamrock::patch::PatchCoord< 3 > > coords)
add a root patch to the scheduler
u64 crit_patch_merge
merging limit (if load value < crit_patch_merge => patch merge)
void allpush_data(shamrock::patch::PatchDataLayer &pdat)
push data in the scheduler The content of pdat as to be the same for each node
void add_root_patch()
add patch to the scheduler
Handle the patch list of the mpi scheduler.
std::vector< shamrock::patch::Patch > local
contain the list of patch owned by the current node
bool is_load_values_up_to_date
Are patch load values up to date.
std::unordered_map< u64, u64 > id_patch_to_local_idx
id_patch_to_local_idx[patch_id] = index in local patch list
std::vector< shamrock::patch::Patch > global
contain the list of all patches in the simulation
std::unordered_map< u64, u64 > id_patch_to_global_idx
id_patch_to_global_idx[patch_id] = index in global patch list
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.
FieldDescriptor< T > get_field(const std::string &field_name)
Get the field description id if matching name & type.
PatchDataLayer container class, the layout is described in patchdata_layout.
Store the information related to the size of the simulation box to convert patch integer coordinates ...
void set_bounding_box(shammath::CoordRange< T > new_box)
Override the stored bounding box by the one given in new_box.
static constexpr u64 max_box_sz
maximal value along an axis for the patch coordinate
Patch Tree : Tree structure organisation for an abstract list of patches Nb : this tree is compatible...
Class to handle PatchData owned by the node.
shamrock::patch::SimulationBoxInfo sim_box
simulation box geometry info
shambase::DistributedData< PatchData > owned_data
map container for patchdata owned by the current node (layout : id_patch,data)
A node that applies a custom function to modify connected edges.
virtual void free_alloc() override
Free allocated memory.
memory manipulation algorithms
namespace for basic c++ utilities
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...
header for PatchData related function and declaration
Class to handle the patch list of the mpi scheduler.
This file contains the definition for the stacktrace related functionality.
Patch object that contain generic patch information.
bool is_err_mode() const
check if a patch is in error mode
u32 node_owner_id
node rank owner of this patch
u64 id_patch
unique key that identify the patch
header file to manage sycl