Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ExchangeGhostField.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
24
25template<class T>
27 auto edges = get_edges();
28
29 // outputs
30 auto &ghost_layer = edges.ghost_layer;
31 const shamrock::solvergraph::RankGetter &rank_owner = edges.rank_owner;
32
34
35 shamalgs::collective::serialize_sparse_comm<PatchDataField<T>>(
36 shamsys::instance::get_compute_scheduler_ptr(),
37 std::move(ghost_layer.patchdata_fields),
38 recv_dat,
39 [&](u64 id) {
40 return rank_owner.get_rank_owner(id);
41 },
42 [](PatchDataField<T> &pdat) {
43 shamalgs::SerializeHelper ser(shamsys::instance::get_compute_scheduler_ptr());
44 ser.allocate(pdat.serialize_full_byte_size());
45 pdat.serialize_full(ser);
46 return ser.finalize();
47 },
48 [&](sham::DeviceBuffer<u8> &&buf) {
49 // exchange the buffer held by the distrib data and give it to the serializer
51 shamsys::instance::get_compute_scheduler_ptr(),
52 std::forward<sham::DeviceBuffer<u8>>(buf));
54 },
55 cache);
56
57 ghost_layer.patchdata_fields = std::move(recv_dat);
58}
59
60template<class T>
62 auto rank_owner = get_ro_edge_base(0).get_tex_symbol();
63 auto ghost_layer = get_rw_edge_base(0).get_tex_symbol();
64
65 std::string tex = R"tex(
66 Exchange ghost field data between distributed processes
67
68 \begin{align}
69 {ghost_layer}_{i \rightarrow \underline{j}} = \text{Sparse comm}({ghost_layer}_{\underline{i} \rightarrow j}) \\
70 \text{where } {rank_owner}_{\underline{j}} = \text{MPI world rank} \\
71 \text{and } {rank_owner}_{\underline{i}} = \text{MPI world rank} \\
72 \text{and } i \in [0, N_{\rm patch}] \\
73 \text{and } j \in [0, N_{\rm patch}] \\
74 \end{align},
75 underlined indices denotes one that currently owned by the local process.
76 )tex";
77
78 shambase::replace_all(tex, "{rank_owner}", rank_owner);
79 shambase::replace_all(tex, "{ghost_layer}", ghost_layer);
80
81 return tex;
82}
83
85// Explicitly instantiate all classes in XMAC_LIST_ENABLED_FIELD
88#ifndef DOXYGEN
89 #define X(a) template class shamrock::solvergraph::ExchangeGhostField<a>;
90XMAC_LIST_ENABLED_FIELD
91 #undef X
92#endif
93
Solver graph node for exchanging ghost field data between distributed processes.
std::uint64_t u64
64 bit unsigned integer
static PatchDataField deserialize_full(shamalgs::SerializeHelper &serializer)
deserialize a field inverse of serialize_full
A buffer allocated in USM (Unified Shared Memory)
Container for objects shared between two distributed data elements.
virtual std::string _impl_get_tex() const
Returns the TeX representation for this node.
void _impl_evaluate_internal()
Performs the ghost field data exchange computation.
void replace_all(std::string &inout, std::string_view what, std::string_view with)
replace all occurence of a search string with another
Definition string.hpp:183