16#include "ddc/chunk_traits.hpp"
17#include "ddc/discrete_vector.hpp"
22static constexpr PDI_inout_t default_access_v
23 = (std::is_lvalue_reference_v<T> && !std::is_const_v<std::remove_reference_t<T>>)
28static constexpr PDI_inout_t chunk_default_access_v = is_writable_chunk_v<T> ? PDI_INOUT : PDI_OUT;
32 std::string m_event_name;
34 std::vector<std::string> m_names;
36 std::list<std::any> m_metadata;
38 char const* store_name(std::string&& name)
40 return m_names.emplace_back(std::move(name)).c_str();
43 char const* store_name(std::string
const& name)
45 return m_names.emplace_back(name).c_str();
51 std::any& ref = m_metadata.emplace_back(std::in_place_type<T>, std::move(t));
52 return std::any_cast<T>(&ref);
56 T* store_array(std::vector<T> v)
58 std::any& ref = m_metadata.emplace_back(std::in_place_type<std::vector<T>>, std::move(v));
59 return std::any_cast<std::vector<T>>(&ref)->data();
63 explicit PdiEvent(std::string
const& event_name) : m_event_name(event_name) {}
71 PDI_event(m_event_name.c_str());
72 for (std::string
const& one_name : m_names) {
73 PDI_reclaim(one_name.c_str());
87 std::enable_if_t<is_borrowed_chunk_v<BorrowedChunk>,
int> = 0>
88 PdiEvent&
with(std::string
const& name, BorrowedChunk&& data)
91 !(access & PDI_IN) || (chunk_default_access_v<BorrowedChunk> & PDI_IN),
92 "Invalid access for constant data");
93 std::array
const extents = detail::array(data.domain().extents());
94 PDI_share(store_name(name +
"_rank"), store_scalar(extents.size()), PDI_OUT);
96 store_name(name +
"_extents"),
97 store_array(std::vector<std::size_t>(extents.begin(), extents.end())),
101 const_cast<chunk_value_t<BorrowedChunk>*>(data.data_handle()),
109 std::enable_if_t<std::is_arithmetic_v<std::remove_reference_t<Arithmetic>>,
int> = 0>
110 PdiEvent&
with(std::string
const& name, Arithmetic&& data)
113 !(access & PDI_IN) || (default_access_v<Arithmetic> & PDI_IN),
114 "Invalid access for constant data");
115 using value_type = std::remove_cv_t<std::remove_reference_t<Arithmetic>>;
116 value_type* data_ptr =
const_cast<value_type*>(&data);
118 if constexpr (!(access & PDI_IN)) {
119 data_ptr = store_scalar(data);
121 PDI_share(store_name(name), data_ptr, access);
125#if defined(DDC_BUILD_DEPRECATED_CODE)
138 template <
class BorrowedChunk, std::enable_if_t<is_borrowed_chunk_v<BorrowedChunk>,
int> = 0>
139 PdiEvent&
with(std::string
const& name, BorrowedChunk&& data)
141 return with<chunk_default_access_v<BorrowedChunk>>(name, std::forward<BorrowedChunk>(data));
147 std::enable_if_t<std::is_arithmetic_v<std::remove_reference_t<Arithmetic>>,
int> = 0>
148 PdiEvent&
with(std::string
const& name, Arithmetic&& data)
150 return with<default_access_v<Arithmetic>>(name, std::forward<Arithmetic>(data));
153#if defined(DDC_BUILD_DEPRECATED_CODE)
165template <PDI_inout_t access,
class DataType>
168 PdiEvent(name
).with<access>(name, std::forward<DataType>(data));
171template <
class DataType>
174 PdiEvent(name
).with(name, std::forward<DataType>(data));
PdiEvent(PdiEvent const &rhs)=delete
PdiEvent & operator=(PdiEvent &&rhs) noexcept=delete
PdiEvent & operator=(PdiEvent const &rhs)=delete
PdiEvent(std::string const &event_name)
PdiEvent & with(std::string const &name, Arithmetic &&data)
Arithmetic overload.
PdiEvent & with(std::string const &name, BorrowedChunk &&data)
API with access deduction.
PdiEvent & with(std::string const &name, Arithmetic &&data)
PdiEvent & with(std::string const &name, BorrowedChunk &&data)
PdiEvent(PdiEvent &&rhs) noexcept=delete
The top-level namespace of DDC.
void expose_to_pdi(std::string const &name, DataType &&data)
void expose_to_pdi(std::string const &name, DataType &&data)