Skip to content

Commit bd7b378

Browse files
committed
Don't use std::packaged_task
Intel compilers having trouble
1 parent 1fe4534 commit bd7b378

File tree

4 files changed

+50
-54
lines changed

4 files changed

+50
-54
lines changed

include/openPMD/LoadStoreChunk.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ namespace core
143143

144144
template <typename T>
145145
[[nodiscard]] auto
146-
enqueueLoad() -> auxiliary::DeferredFuture<std::shared_ptr<T>>;
146+
enqueueLoad() -> auxiliary::DeferredComputation<std::shared_ptr<T>>;
147147

148148
template <typename T>
149149
[[nodiscard]] auto load(EnqueuePolicy) -> std::shared_ptr<T>;
150150

151151
[[nodiscard]] auto
152-
enqueueLoadVariant() -> auxiliary::DeferredFuture<
152+
enqueueLoadVariant() -> auxiliary::DeferredComputation<
153153
auxiliary::detail::shared_ptr_dataset_types>;
154154

155155
[[nodiscard]] auto loadVariant(EnqueuePolicy)
@@ -167,7 +167,7 @@ namespace core
167167

168168
auto storeChunkConfig() -> internal::LoadStoreConfigWithBuffer;
169169

170-
auto enqueueStore() -> auxiliary::DeferredFuture<void>;
170+
auto enqueueStore() -> auxiliary::DeferredComputation<void>;
171171

172172
auto store(EnqueuePolicy) -> void;
173173

include/openPMD/auxiliary/Future.hpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,22 @@
22

33
#include "openPMD/auxiliary/TypeTraits.hpp"
44

5-
#include <future>
5+
#include <functional>
66

77
namespace openPMD::auxiliary
88
{
99
template <typename T>
10-
class DeferredFuture
10+
class DeferredComputation
1111
{
12-
using task_type = std::packaged_task<T()>;
13-
using future_type = std::future<T>;
14-
future_type m_future;
12+
using task_type = std::function<T()>;
1513
task_type m_task;
14+
bool m_valid = false;
1615

1716
public:
18-
DeferredFuture(task_type);
17+
DeferredComputation(task_type);
1918

2019
auto get() -> T;
2120

2221
[[nodiscard]] auto valid() const noexcept -> bool;
23-
24-
auto wait() -> void;
2522
};
2623
} // namespace openPMD::auxiliary

src/LoadStoreChunk.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,14 @@ namespace core
114114

115115
template <typename T>
116116
auto ConfigureLoadStore::enqueueLoad()
117-
-> auxiliary::DeferredFuture<std::shared_ptr<T>>
117+
-> auxiliary::DeferredComputation<std::shared_ptr<T>>
118118
{
119119
auto res = m_rc.loadChunkAllocate_impl<T>(storeChunkConfig());
120-
return auxiliary::DeferredFuture<std::shared_ptr<T>>(
121-
std::packaged_task<std::shared_ptr<T>()>(
122-
[res_lambda = std::move(res), rc = m_rc]() mutable {
123-
rc.seriesFlush();
124-
return res_lambda;
125-
}));
120+
return auxiliary::DeferredComputation<std::shared_ptr<T>>(
121+
[res_lambda = std::move(res), rc = m_rc]() mutable {
122+
rc.seriesFlush();
123+
return res_lambda;
124+
});
126125
}
127126

128127
template <typename T>
@@ -144,24 +143,25 @@ namespace core
144143
{
145144
template <typename T>
146145
static auto call(RecordComponent &rc, internal::LoadStoreConfig cfg)
147-
-> auxiliary::DeferredFuture<
146+
-> auxiliary::DeferredComputation<
148147
auxiliary::detail::shared_ptr_dataset_types>
149148
{
150149
auto res = rc.loadChunkAllocate_impl<T>(std::move(cfg));
151-
return auxiliary::DeferredFuture<
150+
return auxiliary::DeferredComputation<
152151
auxiliary::detail::shared_ptr_dataset_types>(
153-
std::packaged_task<
154-
auxiliary::detail::shared_ptr_dataset_types()>(
155-
[res_lambda = std::move(res), rc_lambda = rc]() mutable
156-
-> auxiliary::detail::shared_ptr_dataset_types {
157-
rc_lambda.seriesFlush();
158-
return res_lambda;
159-
}));
152+
153+
[res_lambda = std::move(res), rc_lambda = rc]() mutable
154+
-> auxiliary::detail::shared_ptr_dataset_types {
155+
std::cout << "Flushing Series from Future" << std::endl;
156+
rc_lambda.seriesFlush();
157+
std::cout << "Flushed Series from Future" << std::endl;
158+
return res_lambda;
159+
});
160160
}
161161
};
162162

163163
auto ConfigureLoadStore::enqueueLoadVariant()
164-
-> auxiliary::DeferredFuture<
164+
-> auxiliary::DeferredComputation<
165165
auxiliary::detail::shared_ptr_dataset_types>
166166
{
167167
return m_rc.visit<VisitorEnqueueLoadVariant>(this->storeChunkConfig());
@@ -208,14 +208,14 @@ namespace core
208208

209209
template <typename Ptr_Type>
210210
auto ConfigureStoreChunkFromBuffer<Ptr_Type>::enqueueStore()
211-
-> auxiliary::DeferredFuture<void>
211+
-> auxiliary::DeferredComputation<void>
212212
{
213213
this->m_rc.storeChunk_impl(
214214
asWriteBuffer(std::move(m_buffer)),
215215
determineDatatype<auxiliary::IsPointer_t<Ptr_Type>>(),
216216
storeChunkConfig());
217-
return auxiliary::DeferredFuture<void>(std::packaged_task<void()>(
218-
[rc_lambda = m_rc]() mutable -> void { rc_lambda.seriesFlush(); }));
217+
return auxiliary::DeferredComputation<void>(
218+
[rc_lambda = m_rc]() mutable -> void { rc_lambda.seriesFlush(); });
219219
}
220220

221221
template <typename Ptr_Type>
@@ -305,7 +305,7 @@ template class compose::ConfigureLoadStore<ConfigureLoadStore>;
305305
-> DynamicMemoryView<dtype>; \
306306
template auto core::ConfigureLoadStore::enqueueLoad() \
307307
/* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
308-
-> auxiliary::DeferredFuture<std::shared_ptr<dtype>>; \
308+
-> auxiliary::DeferredComputation<std::shared_ptr<dtype>>; \
309309
template auto core::ConfigureLoadStore::load(EnqueuePolicy) \
310310
->std::shared_ptr<dtype>;
311311
// clang-format on

src/auxiliary/Future.cpp

+21-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "openPMD/auxiliary/Future.hpp"
22
#include "openPMD/LoadStoreChunk.hpp"
33

4+
#include <iostream>
45
#include <memory>
6+
#include <stdexcept>
57

68
// comment
79

@@ -11,41 +13,38 @@ namespace openPMD::auxiliary
1113
{
1214

1315
template <typename T>
14-
DeferredFuture<T>::DeferredFuture(task_type task)
15-
: m_future(task.get_future()), m_task(std::move(task))
16+
DeferredComputation<T>::DeferredComputation(task_type task)
17+
: m_task([wrapped_task = std::move(task), this]() {
18+
if (!this->m_valid)
19+
{
20+
throw std::runtime_error(
21+
"[DeferredComputation] No valid state. Probably already "
22+
"computed.");
23+
}
24+
this->m_valid = false;
25+
return std::move(wrapped_task)();
26+
})
27+
, m_valid(true)
1628
{}
1729

1830
template <typename T>
19-
auto DeferredFuture<T>::get() -> T
31+
auto DeferredComputation<T>::get() -> T
2032
{
21-
if (m_future.valid())
22-
{
23-
m_task();
24-
} // else get() was already called, propagate the std::future behavior
25-
return m_future.get();
33+
return m_task();
2634
}
2735

2836
template <typename T>
29-
auto DeferredFuture<T>::valid() const noexcept -> bool
37+
auto DeferredComputation<T>::valid() const noexcept -> bool
3038
{
31-
return m_future.valid();
39+
return m_valid;
3240
}
3341

34-
template <typename T>
35-
auto DeferredFuture<T>::wait() -> void
36-
{
37-
if (!m_task.valid())
38-
{
39-
m_task();
40-
}
41-
}
42-
43-
template class DeferredFuture<void>;
44-
template class DeferredFuture<auxiliary::detail::shared_ptr_dataset_types>;
42+
template class DeferredComputation<void>;
43+
template class DeferredComputation<auxiliary::detail::shared_ptr_dataset_types>;
4544
// clang-format off
4645
#define INSTANTIATE_FUTURE(dtype) \
4746
/* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
48-
template class DeferredFuture<std::shared_ptr<dtype>>;
47+
template class DeferredComputation<std::shared_ptr<dtype>>;
4948
OPENPMD_FOREACH_DATASET_DATATYPE(INSTANTIATE_FUTURE)
5049
#undef INSTANTIATE_FUTURE
5150
// clang-format on

0 commit comments

Comments
 (0)