Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ExchangeGhostLayerDebugDotGraph.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
21
26
27#define NODE_EDGES(X_RO, X_RW) \
28 /* ------------------- inputs ------------------- */ \
29 X_RO(shamrock::solvergraph::ScalarsEdge<u64>, object_counts) \
30 \
31 /* ------------------- outputs ------------------- */ \
32 X_RW(shamrock::solvergraph::PatchDataLayerDDShared, ghost_layer)
33
34namespace shamrock::solvergraph {
35
36 class ExchangeGhostLayerDebugDotGraph : public shamrock::solvergraph::INode {
38 std::shared_ptr<shamrock::patch::PatchDataLayerLayout> ghost_layer_layout;
39
40 public:
41 ExchangeGhostLayerDebugDotGraph() {}
42
43 EXPAND_NODE_EDGES(NODE_EDGES)
44
46 auto edges = get_edges();
47 auto &ghost_layer = edges.ghost_layer;
48
49 std::vector<u64_3> debug_infos;
50 ghost_layer.patchdatas.for_each(
51 [&](u64 sender, u64 receiver, shamrock::patch::PatchDataLayer &pdat) {
52 debug_infos.push_back(u64_3{sender, receiver, pdat.get_obj_cnt()});
53 });
54 std::vector<u64_3> collected;
55 shamalgs::collective::vector_allgatherv(debug_infos, collected, MPI_COMM_WORLD);
56
57 std::vector<u64_3> object_counts;
58 edges.object_counts.values.for_each([&](u64 id, u64 count) {
59 object_counts.push_back(u64_3{id, count, shamcomm::world_rank()});
60 });
61 std::vector<u64_3> collected_object_counts;
63 object_counts, collected_object_counts, MPI_COMM_WORLD);
64
65 auto compute_threshold = [&]() -> std::tuple<u64, u64, u64> {
66 std::vector<u64> values;
67 values.reserve(collected.size());
68
69 for (const u64_3 &info : collected) {
70 values.push_back(info.z());
71 }
72
73 std::sort(values.begin(), values.end());
74
75 auto percentile = [&](double p) -> u64 {
76 size_t idx = static_cast<size_t>(p * (values.size() - 1));
77 return values[idx];
78 };
79
80 u64 p50 = percentile(0.50);
81 u64 p80 = percentile(0.80);
82 u64 p95 = percentile(0.95);
83
84 return {p50, p80, p95};
85 };
86
87 auto [p50, p80, p95] = compute_threshold();
88
89 if (shamcomm::world_rank() == 0) {
90
91 std::string log
92 = " --- ExchangeGhostLayerDebugDotGraph debug infos (comm sizes) --- \n";
93
94 logger::raw_ln("p50: ", p50, "p80: ", p80, "p95: ", p95);
95
96 log += R"graph(
97 graph [
98 overlap=false,
99 nodesep=3,
100 ranksep=5
101 ];
102 )graph";
103
104 u32 current_subgraph = 0;
105 log += sham::format("subgraph cluster_{0} {{\n", current_subgraph);
106
107 for (u64_3 &info : collected_object_counts) {
108 if (info.z() != current_subgraph) {
109 log += "}\n";
110 current_subgraph = info.z();
111 log += sham::format("subgraph cluster_{0} {{\n", current_subgraph);
112 }
113 log += sham::format("p_{0} [label=\"Patch {0} N={1}\"];\n", info.x(), info.y());
114 }
115 log += "}\n";
116
117 log += "\n";
118 for (u64_3 &info : collected) {
119
120 const char *edge_color = "green";
121 if (info.z() >= p95) {
122 edge_color = "red";
123 } else if (info.z() >= p80) {
124 edge_color = "darkgoldenrod";
125 } else if (info.z() >= p50) {
126 edge_color = "blue";
127 }
128
129 log += sham::format(
130 "p_{0} -> p_{1} [xlabel={2}, color={3}, fontcolor={3}];\n",
131 info.x(),
132 info.y(),
133 info.z(),
134 edge_color);
136 log += " --- ExchangeGhostLayerDebugDotGraph debug infos (comm sizes) --- \n";
137 logger::raw_ln(log);
138 }
140
141 inline virtual std::string _impl_get_label() const {
142 return "ExchangeGhostLayerDebugDotGraph";
143 };
144
145 inline virtual std::string _impl_get_tex() const { return ""; };
146 };
147} // namespace shamrock::solvergraph
148
149#undef NODE_EDGES
Shared distributed data layer for patch data management in solver graphs.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
PatchDataLayer container class, the layout is described in patchdata_layout.
u32 get_obj_cnt() const
get the number of objects (particles) stored in this layer
virtual std::string _impl_get_tex() const
get the tex of the node
virtual std::string _impl_get_label() const
get the label of the node
Inode is node between data edges, takes multiple inputs, multiple outputs.
Definition INode.hpp:31
std::vector< int > vector_allgatherv(const std::vector< T > &send_vec, const MPI_Datatype &send_type, std::vector< T > &recv_vec, const MPI_Datatype &recv_type, const MPI_Comm comm)
allgatherv on vector with size query (size querying variant of vector_allgatherv_ks) //TODO add fault...
Definition exchanges.hpp:98
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:41
void raw_ln(Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:89