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
26
27namespace shamrock::solvergraph {
28
31 std::shared_ptr<shamrock::patch::PatchDataLayerLayout> ghost_layer_layout;
32
33 public:
35
40
41 inline void set_edges(
42 std::shared_ptr<shamrock::solvergraph::ScalarsEdge<u64>> object_counts,
43 std::shared_ptr<shamrock::solvergraph::PatchDataLayerDDShared> ghost_layer) {
44 __internal_set_ro_edges({object_counts});
45 __internal_set_rw_edges({ghost_layer});
46 }
47
48 inline Edges get_edges() {
49 return Edges{
50 get_ro_edge<shamrock::solvergraph::ScalarsEdge<u64>>(0),
51 get_rw_edge<shamrock::solvergraph::PatchDataLayerDDShared>(0),
52 };
53 }
54
56 auto edges = get_edges();
57 auto &ghost_layer = edges.ghost_layer;
58
59 std::vector<u64_3> debug_infos;
60 ghost_layer.patchdatas.for_each(
61 [&](u64 sender, u64 receiver, shamrock::patch::PatchDataLayer &pdat) {
62 debug_infos.push_back(u64_3{sender, receiver, pdat.get_obj_cnt()});
63 });
64 std::vector<u64_3> collected;
65 shamalgs::collective::vector_allgatherv(debug_infos, collected, MPI_COMM_WORLD);
66
67 std::vector<u64_3> object_counts;
68 edges.object_counts.values.for_each([&](u64 id, u64 count) {
69 object_counts.push_back(u64_3{id, count, shamcomm::world_rank()});
70 });
71 std::vector<u64_3> collected_object_counts;
72 shamalgs::collective::vector_allgatherv(
73 object_counts, collected_object_counts, MPI_COMM_WORLD);
74
75 auto compute_threshold = [&]() -> std::tuple<u64, u64, u64> {
76 std::vector<u64> values;
77 values.reserve(collected.size());
78
79 for (const u64_3 &info : collected) {
80 values.push_back(info.z());
81 }
82
83 std::sort(values.begin(), values.end());
84
85 auto percentile = [&](double p) -> u64 {
86 size_t idx = static_cast<size_t>(p * (values.size() - 1));
87 return values[idx];
88 };
89
90 u64 p50 = percentile(0.50);
91 u64 p80 = percentile(0.80);
92 u64 p95 = percentile(0.95);
93
94 return {p50, p80, p95};
95 };
96
97 auto [p50, p80, p95] = compute_threshold();
98
99 if (shamcomm::world_rank() == 0) {
100
101 std::string log
102 = " --- ExchangeGhostLayerDebugDotGraph debug infos (comm sizes) --- \n";
103
104 logger::raw_ln("p50: ", p50, "p80: ", p80, "p95: ", p95);
105
106 log += R"graph(
107 graph [
108 overlap=false,
109 nodesep=3,
110 ranksep=5
111 ];
112 )graph";
113
114 u32 current_subgraph = 0;
115 log += shambase::format("subgraph cluster_{0} {{\n", current_subgraph);
116
117 for (u64_3 &info : collected_object_counts) {
118 if (info.z() != current_subgraph) {
119 log += "}\n";
120 current_subgraph = info.z();
121 log += shambase::format("subgraph cluster_{0} {{\n", current_subgraph);
122 }
123 log += shambase::format(
124 "p_{0} [label=\"Patch {0} N={1}\"];\n", info.x(), info.y());
125 }
126 log += "}\n";
127
128 log += "\n";
129 for (u64_3 &info : collected) {
130
131 const char *edge_color = "green";
132 if (info.z() >= p95) {
133 edge_color = "red";
134 } else if (info.z() >= p80) {
135 edge_color = "darkgoldenrod";
136 } else if (info.z() >= p50) {
137 edge_color = "blue";
138 }
139
140 log += shambase::format(
141 "p_{0} -> p_{1} [xlabel={2}, color={3}, fontcolor={3}];\n",
142 info.x(),
143 info.y(),
144 info.z(),
145 edge_color);
146 }
147 log += " --- ExchangeGhostLayerDebugDotGraph debug infos (comm sizes) --- \n";
148 logger::raw_ln(log);
149 }
150 }
151
152 inline virtual std::string _impl_get_label() const {
153 return "ExchangeGhostLayerDebugDotGraph";
154 };
155
156 inline virtual std::string _impl_get_tex() const { return ""; };
157 };
158} // namespace shamrock::solvergraph
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.
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:30
void __internal_set_rw_edges(std::vector< std::shared_ptr< IEdge > > new_rw_edges)
Set the read write edges.
Definition INode.hpp:181
void __internal_set_ro_edges(std::vector< std::shared_ptr< IEdge > > new_ro_edges)
Set the read only edges.
Definition INode.hpp:171
Shared distributed data layer for patch data management.
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:40