Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
BuildGhostInterfaceIdTable.cpp
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
16
18#include "shambase/string.hpp"
19#include "shamcomm/logs.hpp"
23#include <unordered_set>
24#include <map>
25#include <string>
26#include <vector>
27
28template<class Tvec>
31
32 using namespace shamrock::patch;
33
34 auto edges = get_edges();
35
36 // inputs
37 auto &positions = edges.positions;
38 auto &interface_infos = edges.interface_infos.values;
39
40 // positions only holds non-empty patches, an interface whose sender is absent from it has no
41 // particles to send and is therefore dropped (as an empty interface would be). Since the filter
42 // only holds **local** non-empty patches, an interface whose sender is not a local patch would
43 // also be silently dropped here rather than raising an error.
44 std::vector<u64> ids_vec = positions.get_refs().get_ids();
45 std::unordered_set<u64> non_empty_senders(ids_vec.begin(), ids_vec.end());
46
48
49 std::map<u64, f64> send_count_stats;
50
51 interface_infos.for_each([&](u64 sender, u64 receiver, const InterfaceBuildInfos &build) {
52 if (non_empty_senders.find(sender) == non_empty_senders.end()) {
53 return;
54 }
55
56 PatchDataField<Tvec> &xyz = positions.get_field(sender);
57
58 sham::DeviceBuffer<u32> idxs_res = xyz.get_ids_where(
59 [](auto access, u32 id, Tvec vmin, Tvec vmax) {
60 return Patch::is_in_patch_converted(access[id], vmin, vmax);
61 },
62 build.cut_volume.lower,
63 build.cut_volume.upper);
64
65 u32 pcnt = idxs_res.get_size();
66
67 // prevent sending empty patches
68 if (pcnt == 0) {
69 return;
70 }
71
72 f64 ratio = f64(pcnt) / f64(xyz.get_obj_cnt());
73
74 shamlog_debug_ln(
75 "InterfaceGen",
76 "gen interface :",
77 sender,
78 "->",
79 receiver,
80 "volume ratio:",
81 build.volume_ratio,
82 "part_ratio:",
83 ratio);
84
85 res.add_obj(sender, receiver, InterfaceIdTable{build, std::move(idxs_res), ratio});
86
87 send_count_stats[sender] += ratio;
88 });
89
90 bool has_warn = false;
91
92 std::string warn_log = "";
93
94 for (auto &[k, v] : send_count_stats) {
95 if (v > 0.2) {
96 warn_log += sham::format("\n patch {} high interf/patch volume: {}", k, v);
97 has_warn = true;
98 }
99 }
100
101 if (has_warn && shamcomm::world_rank() == 0) {
102 warn_log = "\n This can lead to high mpi "
103 "overhead, try to increase the patch split crit"
104 + warn_log;
105 }
106
107 if (has_warn) {
108 logger::warn_ln("InterfaceGen", "High interface/patch volume ratio." + warn_log);
109 }
110
111 edges.interface_id_table.values = std::move(res);
112}
113
114template<class Tvec>
118
Solvergraph node selecting the ids of the particles sent through each ghost interface.
Header file for the patch struct and related function.
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory).
size_t get_size() const
Gets the number of elements in the buffer.
Container for objects shared between two distributed data elements.
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.
virtual std::string _impl_get_tex() const
get the tex of the node
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:41
void warn_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:132
This file contains the definition for the stacktrace related functionality.
#define __shamrock_stack_entry()
Macro to create a stack entry.
static bool is_in_patch_converted(sycl::vec< T, 3 > val, sycl::vec< T, 3 > min_val, sycl::vec< T, 3 > max_val)
check if particle is in the asked range, given the output of @convert_coord
Definition Patch.hpp:210
Functions related to the MPI communicator.