diff --git a/classddc_1_1PdiEvent.html b/classddc_1_1PdiEvent.html index ee1d30b8a..7b76e68a7 100644 --- a/classddc_1_1PdiEvent.html +++ b/classddc_1_1PdiEvent.html @@ -176,7 +176,7 @@

Detailed Description

-

Definition at line 29 of file pdi.hpp.

+

Definition at line 30 of file pdi.hpp.

Constructor & Destructor Documentation

◆ PdiEvent() [1/3]

@@ -202,7 +202,7 @@

-

Definition at line 39 of file pdi.hpp.

+

Definition at line 63 of file pdi.hpp.

@@ -281,7 +281,7 @@

-

Definition at line 45 of file pdi.hpp.

+

Definition at line 69 of file pdi.hpp.

@@ -375,7 +375,7 @@

API with access argument

-

Definition at line 64 of file pdi.hpp.

+

Definition at line 88 of file pdi.hpp.

@@ -415,7 +415,7 @@

-

Definition at line 91 of file pdi.hpp.

+

Definition at line 110 of file pdi.hpp.

@@ -455,7 +455,7 @@

-

Definition at line 109 of file pdi.hpp.

+

Definition at line 126 of file pdi.hpp.

@@ -498,7 +498,7 @@

Chunk (const)& or ChunkSpan&& or ChunkSpan (const)&)

-

Definition at line 120 of file pdi.hpp.

+

Definition at line 137 of file pdi.hpp.

@@ -540,7 +540,7 @@

Definition at line 129 of file pdi.hpp.

+

Definition at line 146 of file pdi.hpp.

@@ -582,7 +582,7 @@

Definition at line 136 of file pdi.hpp.

+

Definition at line 153 of file pdi.hpp.

diff --git a/namespaceddc.html b/namespaceddc.html index 2a3f19293..ed9e18d83 100644 --- a/namespaceddc.html +++ b/namespaceddc.html @@ -5662,7 +5662,7 @@

-

Definition at line 145 of file pdi.hpp.

+

Definition at line 162 of file pdi.hpp.

@@ -5694,7 +5694,7 @@

-

Definition at line 151 of file pdi.hpp.

+

Definition at line 168 of file pdi.hpp.

diff --git a/pdi_8hpp_source.html b/pdi_8hpp_source.html index b5ab3f4ef..f6ef6d03c 100644 --- a/pdi_8hpp_source.html +++ b/pdi_8hpp_source.html @@ -133,172 +133,189 @@
4
5#pragma once
6
-
7#include <memory_resource>
-
8#include <string>
-
9#include <type_traits>
-
10#include <utility>
-
11#include <vector>
-
12
-
13#include <pdi.h>
-
14
-
15#include "ddc/chunk_traits.hpp"
-
16#include "ddc/discrete_vector.hpp"
-
17
-
18namespace ddc {
-
19
-
20template <class T>
-
21static constexpr PDI_inout_t default_access_v
-
22 = (std::is_lvalue_reference_v<T> && !std::is_const_v<std::remove_reference_t<T>>)
-
23 ? PDI_INOUT
-
24 : PDI_OUT;
-
25
-
26template <class T>
-
27static constexpr PDI_inout_t chunk_default_access_v = is_writable_chunk_v<T> ? PDI_INOUT : PDI_OUT;
-
28
-
29class PdiEvent
-
30{
-
31 std::string m_event_name;
-
32
-
33 std::vector<std::string> m_names;
-
34
-
35 /// a memory buffer where temporary variables are stored until the class is destroyed
-
36 std::pmr::monotonic_buffer_resource m_metadata;
+
7#include <any>
+
8#include <list>
+
9#include <string>
+
10#include <type_traits>
+
11#include <utility>
+
12#include <vector>
+
13
+
14#include <pdi.h>
+
15
+
16#include "ddc/chunk_traits.hpp"
+
17#include "ddc/discrete_vector.hpp"
+
18
+
19namespace ddc {
+
20
+
21template <class T>
+
22static constexpr PDI_inout_t default_access_v
+
23 = (std::is_lvalue_reference_v<T> && !std::is_const_v<std::remove_reference_t<T>>)
+
24 ? PDI_INOUT
+
25 : PDI_OUT;
+
26
+
27template <class T>
+
28static constexpr PDI_inout_t chunk_default_access_v = is_writable_chunk_v<T> ? PDI_INOUT : PDI_OUT;
+
29
+
30class PdiEvent
+
31{
+
32 std::string m_event_name;
+
33
+
34 std::vector<std::string> m_names;
+
35
+
36 std::list<std::any> m_metadata;
37
-
38public:
-
39 explicit PdiEvent(std::string const& event_name) : m_event_name(event_name) {}
-
40
-
41 PdiEvent(PdiEvent const& rhs) = delete;
+
38 char const* store_name(std::string&& name)
+
39 {
+
40 return m_names.emplace_back(std::move(name)).c_str();
+
41 }
42
-
43 PdiEvent(PdiEvent&& rhs) noexcept = delete;
-
44
-
45 ~PdiEvent() noexcept
-
46 {
-
47 PDI_event(m_event_name.c_str());
-
48 for (std::string const& one_name : m_names) {
-
49 PDI_reclaim(one_name.c_str());
-
50 }
-
51 }
-
52
-
53 PdiEvent& operator=(PdiEvent const& rhs) = delete;
+
43 char const* store_name(std::string const& name)
+
44 {
+
45 return m_names.emplace_back(name).c_str();
+
46 }
+
47
+
48 template <class T>
+
49 T* store_scalar(T t)
+
50 {
+
51 std::any& ref = m_metadata.emplace_back(std::in_place_type<T>, std::move(t));
+
52 return std::any_cast<T>(&ref);
+
53 }
54
-
55 PdiEvent& operator=(PdiEvent&& rhs) noexcept = delete;
-
56
-
57 /// @{
-
58 /// API with access argument
-
59
-
60 template <
-
61 PDI_inout_t access,
-
62 class BorrowedChunk,
-
63 std::enable_if_t<is_borrowed_chunk_v<BorrowedChunk>, int> = 0>
-
64 PdiEvent& with(std::string const& name, BorrowedChunk&& data)
-
65 {
-
66 static_assert(
-
67 !(access & PDI_IN) || (chunk_default_access_v<BorrowedChunk> & PDI_IN),
-
68 "Invalid access for constant data");
-
69 auto extents = detail::array(data.domain().extents());
-
70 std::size_t& rank = *std::pmr::polymorphic_allocator<std::size_t>(&m_metadata).allocate(1);
-
71 rank = extents.size();
-
72 PDI_share((name + "_rank").c_str(), &rank, PDI_OUT);
-
73 m_names.push_back(name + "_rank");
-
74 PDI_share(
-
75 (name + "_extents").c_str(),
-
76 std::pmr::vector<std::size_t>(extents.begin(), extents.end(), &m_metadata).data(),
-
77 PDI_OUT);
-
78 m_names.push_back(name + "_extents");
-
79 PDI_share(
-
80 name.c_str(),
-
81 const_cast<chunk_value_t<BorrowedChunk>*>(data.data_handle()),
-
82 access);
-
83 m_names.push_back(name);
-
84 return *this;
-
85 }
-
86
-
87 template <
-
88 PDI_inout_t access,
-
89 class Arithmetic,
-
90 std::enable_if_t<std::is_arithmetic_v<std::remove_reference_t<Arithmetic>>, int> = 0>
-
91 PdiEvent& with(std::string const& name, Arithmetic&& data)
-
92 {
-
93 static_assert(
-
94 !(access & PDI_IN) || (default_access_v<Arithmetic> & PDI_IN),
-
95 "Invalid access for constant data");
-
96 using value_type = std::remove_cv_t<std::remove_reference_t<Arithmetic>>;
-
97 value_type* data_ptr = const_cast<value_type*>(&data);
-
98 // for read-only data, we share a copy instead of the data itself in case we received a ref on a temporary,
-
99 if constexpr (!(access & PDI_IN)) {
-
100 data_ptr = std::pmr::polymorphic_allocator<value_type>(&m_metadata).allocate(1);
-
101 *data_ptr = data;
-
102 }
-
103 PDI_share(name.c_str(), data_ptr, access);
-
104 m_names.push_back(name);
-
105 return *this;
-
106 }
-
107
-
108 template <PDI_inout_t access, class T>
-
109 PdiEvent& and_with(std::string const& name, T&& t)
-
110 {
-
111 return with<access>(name, std::forward<T>(t));
-
112 }
-
113
-
114 /// @}
-
115 /// API with access deduction
-
116 /// @{
-
117
-
118 /// Borrowed chunk overload (Chunk (const)& or ChunkSpan&& or ChunkSpan (const)&)
-
119 template <class BorrowedChunk, std::enable_if_t<is_borrowed_chunk_v<BorrowedChunk>, int> = 0>
-
120 PdiEvent& with(std::string const& name, BorrowedChunk&& data)
-
121 {
-
122 return with<chunk_default_access_v<BorrowedChunk>>(name, std::forward<BorrowedChunk>(data));
+
55 template <class T>
+
56 T* store_array(std::vector<T> v)
+
57 {
+
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();
+
60 }
+
61
+
62public:
+
63 explicit PdiEvent(std::string const& event_name) : m_event_name(event_name) {}
+
64
+
65 PdiEvent(PdiEvent const& rhs) = delete;
+
66
+
67 PdiEvent(PdiEvent&& rhs) noexcept = delete;
+
68
+
69 ~PdiEvent() noexcept
+
70 {
+
71 PDI_event(m_event_name.c_str());
+
72 for (std::string const& one_name : m_names) {
+
73 PDI_reclaim(one_name.c_str());
+
74 }
+
75 }
+
76
+
77 PdiEvent& operator=(PdiEvent const& rhs) = delete;
+
78
+
79 PdiEvent& operator=(PdiEvent&& rhs) noexcept = delete;
+
80
+
81 /// @{
+
82 /// API with access argument
+
83
+
84 template <
+
85 PDI_inout_t access,
+
86 class BorrowedChunk,
+
87 std::enable_if_t<is_borrowed_chunk_v<BorrowedChunk>, int> = 0>
+
88 PdiEvent& with(std::string const& name, BorrowedChunk&& data)
+
89 {
+
90 static_assert(
+
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);
+
95 PDI_share(
+
96 store_name(name + "_extents"),
+
97 store_array(std::vector<std::size_t>(extents.begin(), extents.end())),
+
98 PDI_OUT);
+
99 PDI_share(
+
100 store_name(name),
+
101 const_cast<chunk_value_t<BorrowedChunk>*>(data.data_handle()),
+
102 access);
+
103 return *this;
+
104 }
+
105
+
106 template <
+
107 PDI_inout_t access,
+
108 class Arithmetic,
+
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)
+
111 {
+
112 static_assert(
+
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);
+
117 // for read-only data, we share a copy instead of the data itself in case we received a ref on a temporary,
+
118 if constexpr (!(access & PDI_IN)) {
+
119 data_ptr = store_scalar(data);
+
120 }
+
121 PDI_share(store_name(name), data_ptr, access);
+
122 return *this;
123 }
124
-
125 /// Arithmetic overload
-
126 template <
-
127 class Arithmetic,
-
128 std::enable_if_t<std::is_arithmetic_v<std::remove_reference_t<Arithmetic>>, int> = 0>
-
129 PdiEvent& with(std::string const& name, Arithmetic&& data)
-
130 {
-
131 return with<default_access_v<Arithmetic>>(name, std::forward<Arithmetic>(data));
-
132 }
-
133
-
134 /// With synonym
-
135 template <class T>
-
136 PdiEvent& and_with(std::string const& name, T&& t)
-
137 {
-
138 return with(name, std::forward<T>(t));
-
139 }
-
140
-
141 /// @}
-
142};
-
143
-
144template <PDI_inout_t access, class DataType>
-
145void expose_to_pdi(std::string const& name, DataType&& data)
-
146{
-
147 PdiEvent(name).with<access>(name, std::forward<DataType>(data));
-
148}
-
149
-
150template <class DataType>
-
151void expose_to_pdi(std::string const& name, DataType&& data)
-
152{
-
153 PdiEvent(name).with(name, std::forward<DataType>(data));
-
154}
-
155
-
156} // namespace ddc
- +
125 template <PDI_inout_t access, class T>
+
126 PdiEvent& and_with(std::string const& name, T&& t)
+
127 {
+
128 return with<access>(name, std::forward<T>(t));
+
129 }
+
130
+
131 /// @}
+
132 /// API with access deduction
+
133 /// @{
+
134
+
135 /// Borrowed chunk overload (Chunk (const)& or ChunkSpan&& or ChunkSpan (const)&)
+
136 template <class BorrowedChunk, std::enable_if_t<is_borrowed_chunk_v<BorrowedChunk>, int> = 0>
+
137 PdiEvent& with(std::string const& name, BorrowedChunk&& data)
+
138 {
+
139 return with<chunk_default_access_v<BorrowedChunk>>(name, std::forward<BorrowedChunk>(data));
+
140 }
+
141
+
142 /// Arithmetic overload
+
143 template <
+
144 class Arithmetic,
+
145 std::enable_if_t<std::is_arithmetic_v<std::remove_reference_t<Arithmetic>>, int> = 0>
+
146 PdiEvent& with(std::string const& name, Arithmetic&& data)
+
147 {
+
148 return with<default_access_v<Arithmetic>>(name, std::forward<Arithmetic>(data));
+
149 }
+
150
+
151 /// With synonym
+
152 template <class T>
+
153 PdiEvent& and_with(std::string const& name, T&& t)
+
154 {
+
155 return with(name, std::forward<T>(t));
+
156 }
+
157
+
158 /// @}
+
159};
+
160
+
161template <PDI_inout_t access, class DataType>
+
162void expose_to_pdi(std::string const& name, DataType&& data)
+
163{
+
164 PdiEvent(name).with<access>(name, std::forward<DataType>(data));
+
165}
+
166
+
167template <class DataType>
+
168void expose_to_pdi(std::string const& name, DataType&& data)
+
169{
+
170 PdiEvent(name).with(name, std::forward<DataType>(data));
+
171}
+
172
+
173} // namespace ddc
+
PdiEvent(PdiEvent const &rhs)=delete
-
PdiEvent & and_with(std::string const &name, T &&t)
With synonym.
Definition pdi.hpp:136
-
PdiEvent & and_with(std::string const &name, T &&t)
Definition pdi.hpp:109
+
PdiEvent & and_with(std::string const &name, T &&t)
With synonym.
Definition pdi.hpp:153
+
PdiEvent & and_with(std::string const &name, T &&t)
Definition pdi.hpp:126
PdiEvent & operator=(PdiEvent &&rhs) noexcept=delete
-
~PdiEvent() noexcept
Definition pdi.hpp:45
+
~PdiEvent() noexcept
Definition pdi.hpp:69
PdiEvent & operator=(PdiEvent const &rhs)=delete
-
PdiEvent(std::string const &event_name)
Definition pdi.hpp:39
-
PdiEvent & with(std::string const &name, Arithmetic &&data)
Arithmetic overload.
Definition pdi.hpp:129
-
PdiEvent & with(std::string const &name, BorrowedChunk &&data)
API with access deduction.
Definition pdi.hpp:120
-
PdiEvent & with(std::string const &name, Arithmetic &&data)
Definition pdi.hpp:91
-
PdiEvent & with(std::string const &name, BorrowedChunk &&data)
Definition pdi.hpp:64
+
PdiEvent(std::string const &event_name)
Definition pdi.hpp:63
+
PdiEvent & with(std::string const &name, Arithmetic &&data)
Arithmetic overload.
Definition pdi.hpp:146
+
PdiEvent & with(std::string const &name, BorrowedChunk &&data)
API with access deduction.
Definition pdi.hpp:137
+
PdiEvent & with(std::string const &name, Arithmetic &&data)
Definition pdi.hpp:110
+
PdiEvent & with(std::string const &name, BorrowedChunk &&data)
Definition pdi.hpp:88
PdiEvent(PdiEvent &&rhs) noexcept=delete
The top-level namespace of DDC.
-
void expose_to_pdi(std::string const &name, DataType &&data)
Definition pdi.hpp:145
-
void expose_to_pdi(std::string const &name, DataType &&data)
Definition pdi.hpp:151
+
void expose_to_pdi(std::string const &name, DataType &&data)
Definition pdi.hpp:162
+
void expose_to_pdi(std::string const &name, DataType &&data)
Definition pdi.hpp:168