Skip to content

Commit

Permalink
Add variant-based loadChunk
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed May 24, 2024
1 parent fea6696 commit 067ed06
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
4 changes: 4 additions & 0 deletions include/openPMD/LoadStoreChunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ class ConfigureLoadStore : protected internal::ConfigureLoadStoreData

template <typename T>
[[nodiscard]] auto enqueueLoad() -> std::shared_ptr<T>;

using shared_ptr_dataset_types = auxiliary::detail::
map_variant<auxiliary::detail::as_shared_pointer, dataset_types>::type;
[[nodiscard]] auto enqueueLoadVariant() -> shared_ptr_dataset_types;
};

template <typename Ptr_Type, typename ChildClass = void>
Expand Down
23 changes: 23 additions & 0 deletions src/LoadStoreChunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,29 @@ auto ConfigureLoadStore<ChildClass>::enqueueLoad() -> std::shared_ptr<T>
return m_rc.loadChunkAllocate_impl<T>(storeChunkConfig());
}

namespace
{
template <typename ConfigureLoadStore_t>
struct VisitorEnqueueLoadVariant
{
template <typename T>
static auto call(RecordComponent const &, ConfigureLoadStore_t &cfg) ->
typename ConfigureLoadStore_t::shared_ptr_dataset_types
{
return cfg.template enqueueLoad<T>();
}
};
} // namespace

template <typename ChildClass>
auto ConfigureLoadStore<ChildClass>::enqueueLoadVariant()
-> shared_ptr_dataset_types
{
return m_rc
.visit<VisitorEnqueueLoadVariant<ConfigureLoadStore<ChildClass>>>(
*this);
}

template <typename Ptr_Type, typename ChildClass>
ConfigureStoreChunkFromBuffer<Ptr_Type, ChildClass>::
ConfigureStoreChunkFromBuffer(Ptr_Type buffer, parent_t &&parent)
Expand Down
16 changes: 10 additions & 6 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1659,13 +1659,17 @@ inline void write_test(const std::string &backend)
auto opaqueTypeDataset = rc.visit<ReadFromAnyType>();

auto variantTypeDataset = rc.loadChunkVariant();
auto variantTypeDataset2 = rc.prepareLoadStore().enqueueLoadVariant();
rc.seriesFlush();
std::visit(
[](auto &&shared_ptr) {
std::cout << "First value in loaded chunk: '" << shared_ptr.get()[0]
<< '\'' << std::endl;
},
variantTypeDataset);
for (auto ptr : {&variantTypeDataset, &variantTypeDataset2})
{
std::visit(
[](auto &&shared_ptr) {
std::cout << "First value in loaded chunk: '"
<< shared_ptr.get()[0] << '\'' << std::endl;
},
*ptr);
}
}

TEST_CASE("write_test", "[serial]")
Expand Down

0 comments on commit 067ed06

Please sign in to comment.