Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
MpiDataTypeHandler.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
19#include <functional>
20#include <string>
21
22namespace shamsys::mpidtypehandler {
23
24 using fct_sig = std::function<void()>;
25
26 inline std::vector<fct_sig> static_init_shamrock_mpidtype{};
27 inline std::vector<fct_sig> static_free_shamrock_mpidtype{};
28
29 inline std::vector<std::string> static_init_shamrock_mpidtype_names{};
30 inline std::vector<std::string> static_free_shamrock_mpidtype_names{};
31
32 inline void init_mpidtype() {
33 for (u32 i = 0; i < static_init_shamrock_mpidtype.size(); i++) {
34 auto fct = static_init_shamrock_mpidtype[i];
35 auto name = static_init_shamrock_mpidtype_names[i];
36 shamlog_debug_mpi_ln("MpiDTypehandler", "initialising type :", name);
37 fct();
38 }
39 }
40
41 inline void free_mpidtype() {
42 for (u32 i = 0; i < static_free_shamrock_mpidtype.size(); i++) {
43 auto fct = static_free_shamrock_mpidtype[i];
44 auto name = static_free_shamrock_mpidtype_names[i];
45 shamlog_debug_mpi_ln("MpiDTypehandler", "freeing type :", name);
46 fct();
47 }
48 }
49
50 struct MPIDTypeinit {
51 inline explicit MPIDTypeinit(fct_sig t, std::string name) {
52 static_init_shamrock_mpidtype.push_back(std::move(t));
53 static_init_shamrock_mpidtype_names.push_back(name);
54 }
55 };
56
57 struct MPIDTypefree {
58 inline explicit MPIDTypefree(fct_sig t, std::string name) {
59 static_free_shamrock_mpidtype.push_back(std::move(t));
60 static_free_shamrock_mpidtype_names.push_back(name);
61 }
62 };
63
64} // namespace shamsys::mpidtypehandler
65
70#define Register_MPIDtypeInit(placeholdername, name) \
71 void mpiinit_##placeholdername(); \
72 void (*mpiinit_ptr_##placeholdername)() = mpiinit_##placeholdername; \
73 shamsys::mpidtypehandler::MPIDTypeinit mpiinit_class_obj_##placeholdername( \
74 mpiinit_ptr_##placeholdername, name); \
75 void mpiinit_##placeholdername()
76
81#define Register_MPIDtypeFree(placeholdername, name) \
82 void mpifree_##placeholdername(); \
83 void (*mpifree_ptr_##placeholdername)() = mpifree_##placeholdername; \
84 shamsys::mpidtypehandler::MPIDTypefree mpifree_class_obj_##placeholdername( \
85 mpifree_ptr_##placeholdername, name); \
86 void mpifree_##placeholdername()
std::uint32_t u32
32 bit unsigned integer
std::function< void(py::module &)> fct_sig
alias to pybind11 namespace