70 if (!pdat.is_empty()) {
72 PatchDataField<T> &pos_field = pdat.get_field<T>(ipos);
74 if (pos_field.get_nvar() != 1) {
75 shambase::throw_unimplemented();
80 sptree.compute_patch_owner(
81 shamsys::instance::get_compute_scheduler_ptr(),
83 pos_field.get_obj_cnt()));
85 bool err_id_in_newid =
false;
87 sycl::host_accessor nid{newid_buf_map.
get(
id), sycl::read_only};
88 for (
u32 i = 0; i < pdat.get_obj_cnt(); i++) {
90 err_id_in_newid = err_id_in_newid || (err);
94 if (err_id_in_newid) {
96 "a new id could not be computed");
101 return newid_buf_map;
122 using namespace shamrock::patch;
124 std::unordered_map<u64, u64> histogram_extract;
126 sched.patch_data.for_each_patchdata(
128 histogram_extract[current_pid] = 0;
129 if (!pdat.is_empty()) {
131 sycl::host_accessor nid{new_pid.get(current_pid), sycl::read_only};
135 const u32 cnt = pdat.get_obj_cnt();
137 for (
u32 i = cnt - 1; i < cnt; i--) {
138 u64 new_pid = nid[i];
139 if (current_pid != new_pid) {
141 if (!part_exchange.
has_key(current_pid, new_pid)) {
150 if (_old_id == current_pid && _new_id == new_pid) {
152 histogram_extract[current_pid]++;
158 std::vector<u32> keep_ids;
159 std::unordered_map<u64, std::vector<u32>> extract_indexes;
161 const u32 cnt = pdat.get_obj_cnt();
162 for (
u32 i = 0; i < cnt; i++) {
163 u64 new_pid = nid[i];
164 if (current_pid != new_pid) {
165 extract_indexes[new_pid].push_back(i);
166 histogram_extract[current_pid]++;
168 keep_ids.push_back(i);
172 for (
auto &[new_id, vec] : extract_indexes) {
174 u64 new_pid = new_id;
175 std::vector<u32> &idx_extract = vec;
177 if (!part_exchange.
has_key(current_pid, new_pid)) {
186 if (_old_id == current_pid && _new_id == new_pid) {
187 pdat.append_subset_to(idx_extract, pdat_int);
193 pdat.keep_ids(keep_idx, keep_ids.size());
198 for (
auto &[k, v] : histogram_extract) {
199 shamlog_debug_ln(
"ReattributeDataUtility",
"patch", k,
"extract=", v);
202 return part_exchange;
221 using namespace shamrock::patch;
223 u32 ipos = sched.pdl_old().get_field_idx<T>(position_field);
230 shamlog_debug_ln(
"ReattributeDataUtility", sender, receiver, pdat.get_obj_cnt());
237 shamalgs::collective::serialize_sparse_comm<PatchDataLayer>(
238 shamsys::instance::get_compute_scheduler_ptr(),
239 std::move(part_exchange),
242 return sched.get_patch_rank_owner(
id);
246 ser.allocate(pdat.serialize_buf_byte_size());
247 pdat.serialize_buf(ser);
248 return ser.finalize();
253 shamsys::instance::get_compute_scheduler_ptr(),
255 return PatchDataLayer::deserialize_buf(ser, sched.get_layout_ptr_old());
260 shamlog_debug_ln(
"Part Exchanges", format(
"send = {} recv = {}", sender, receiver));
261 sched.patch_data.get_pdat(receiver).insert_elements(pdat);
Header file describing a Node Instance.
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
A buffer allocated in USM (Unified Shared Memory)
Container for objects shared between two distributed data elements.
bool has_key(u64 left_id, u64 right_id) const
Check if a patch pair exists in the container.
void for_each(std::function< void(u64, u64, T &)> &&f)
Apply a function to all stored objects.
iterator add_obj(u64 left_id, u64 right_id, T &&obj)
Add an object associated with a patch pair.
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.
T & get(u64 id)
Returns a reference to an object in the collection.
Utility class used to move the objects between patches.
ReattributeDataUtility(PatchScheduler &sched)
Constructor.
shambase::DistributedDataShared< shamrock::patch::PatchDataLayer > extract_elements(shambase::DistributedData< sycl::buffer< u64 > > new_pid)
Extracts elements that do not belong to a patch from the patch data based on the new patch IDs.
shambase::DistributedData< sycl::buffer< u64 > > compute_new_pid(SerialPatchTree< T > &sptree, u32 ipos)
Computes the new patch owner IDs for the objects in the patches based on their position in space.
void reatribute_patch_objects(SerialPatchTree< T > &sptree, std::string position_field)
Reattribute objects based on a given position field.
PatchDataLayer container class, the layout is described in patchdata_layout.
void extract_element(u32 pidx, PatchDataLayer &out_pdat)
extract particle at index pidx and insert it in the provided vectors
sycl::buffer< T > vec_to_buf(const std::vector< T > &buf)
Convert a std::vector to a sycl::buffer
namespace for basic c++ utilities
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
namespace for the main framework
constexpr u64 u64_max
u64 max value
main include file for memory algorithms