diff --git a/include/openPMD/LoadStoreChunk.hpp b/include/openPMD/LoadStoreChunk.hpp index dbc4a08f0c..882b127d05 100644 --- a/include/openPMD/LoadStoreChunk.hpp +++ b/include/openPMD/LoadStoreChunk.hpp @@ -41,15 +41,15 @@ namespace internal } // namespace internal template -class ConfigureStoreChunk : protected internal::ConfigureStoreChunkData +class ConfigureLoadStore : protected internal::ConfigureStoreChunkData { friend class RecordComponent; template - friend class ConfigureStoreChunk; + friend class ConfigureLoadStore; protected: - ConfigureStoreChunk(RecordComponent &rc); - ConfigureStoreChunk(ConfigureStoreChunkData &&); + ConfigureLoadStore(RecordComponent &rc); + ConfigureLoadStore(ConfigureStoreChunkData &&); auto dim() const -> uint8_t; auto getOffset() const -> Offset; @@ -59,7 +59,7 @@ class ConfigureStoreChunk : protected internal::ConfigureStoreChunkData public: using return_type = std::conditional_t< std::is_void_v, - /*then*/ ConfigureStoreChunk, + /*then*/ ConfigureLoadStore, /*else*/ ChildClass>; template using normalize_dataset_type = std::remove_cv_t>; @@ -93,24 +93,24 @@ class ConfigureStoreChunk : protected internal::ConfigureStoreChunkData typename T_ContiguousContainer::value_type> const>>>; template - auto enqueue() -> DynamicMemoryView; + [[nodiscard]] auto enqueueStore() -> DynamicMemoryView; // definition for this one is in RecordComponent.tpp since it needs the // definition of class RecordComponent. template - auto enqueue(F &&createBuffer) -> DynamicMemoryView; + [[nodiscard]] auto enqueueStore(F &&createBuffer) -> DynamicMemoryView; }; template class ConfigureStoreChunkFromBuffer - : public ConfigureStoreChunk> + : public ConfigureLoadStore> { public: using parent_t = - ConfigureStoreChunk>; + ConfigureLoadStore>; private: template - friend class ConfigureStoreChunk; + friend class ConfigureLoadStore; Ptr_Type m_buffer; std::optional m_mem_select; @@ -126,80 +126,8 @@ class ConfigureStoreChunkFromBuffer auto as_parent() & -> parent_t &; auto as_parent() const & -> parent_t const &; - auto enqueue() -> void; + auto enqueueStore() -> void; }; - -template -template -auto ConfigureStoreChunk::fromSharedPtr(std::shared_ptr data) - -> ConfigureStoreChunkFromBuffer< - std::shared_ptr const>> -{ - if (!data) - { - throw std::runtime_error( - "Unallocated pointer passed during chunk store."); - } - return ConfigureStoreChunkFromBuffer< - std::shared_ptr const>>( - std::static_pointer_cast const>( - std::move(data)), - {std::move(*this)}); -} -template -template -auto ConfigureStoreChunk::fromUniquePtr(UniquePtrWithLambda data) - -> ConfigureStoreChunkFromBuffer< - UniquePtrWithLambda>> -{ - if (!data) - { - throw std::runtime_error( - "Unallocated pointer passed during chunk store."); - } - return ConfigureStoreChunkFromBuffer< - UniquePtrWithLambda>>( - std::move(data).template static_cast_>(), - {std::move(*this)}); -} -template -template -auto ConfigureStoreChunk::fromRawPtr(T *data) - -> ConfigureStoreChunkFromBuffer< - std::shared_ptr const>> -{ - if (!data) - { - throw std::runtime_error( - "Unallocated pointer passed during chunk store."); - } - return ConfigureStoreChunkFromBuffer< - std::shared_ptr const>>( - auxiliary::shareRaw(data), {std::move(*this)}); -} - -template -template -auto ConfigureStoreChunk::fromUniquePtr( - std::unique_ptr data) - -> ConfigureStoreChunkFromBuffer< - UniquePtrWithLambda>> -{ - return fromUniquePtr(UniquePtrWithLambda(std::move(data))); -} -template -template -auto ConfigureStoreChunk::fromContiguousContainer( - T_ContiguousContainer &data) -> - typename std::enable_if_t< - auxiliary::IsContiguousContainer_v, - ConfigureStoreChunkFromBuffer const>>> -{ - if (!m_extent.has_value() && dim() == 1) - { - m_extent = Extent{data.size()}; - } - return fromRawPtr(data.data()); -} } // namespace openPMD + +#include "openPMD/LoadStoreChunk.tpp" diff --git a/include/openPMD/LoadStoreChunk.tpp b/include/openPMD/LoadStoreChunk.tpp new file mode 100644 index 0000000000..215df35302 --- /dev/null +++ b/include/openPMD/LoadStoreChunk.tpp @@ -0,0 +1,80 @@ +#pragma once + +#include "openPMD/LoadStoreChunk.hpp" + +namespace openPMD +{ + +template +template +auto ConfigureLoadStore::fromSharedPtr(std::shared_ptr data) + -> ConfigureStoreChunkFromBuffer< + std::shared_ptr const>> +{ + if (!data) + { + throw std::runtime_error( + "Unallocated pointer passed during chunk store."); + } + return ConfigureStoreChunkFromBuffer< + std::shared_ptr const>>( + std::static_pointer_cast const>( + std::move(data)), + {std::move(*this)}); +} +template +template +auto ConfigureLoadStore::fromUniquePtr(UniquePtrWithLambda data) + -> ConfigureStoreChunkFromBuffer< + UniquePtrWithLambda>> +{ + if (!data) + { + throw std::runtime_error( + "Unallocated pointer passed during chunk store."); + } + return ConfigureStoreChunkFromBuffer< + UniquePtrWithLambda>>( + std::move(data).template static_cast_>(), + {std::move(*this)}); +} +template +template +auto ConfigureLoadStore::fromRawPtr(T *data) + -> ConfigureStoreChunkFromBuffer< + std::shared_ptr const>> +{ + if (!data) + { + throw std::runtime_error( + "Unallocated pointer passed during chunk store."); + } + return ConfigureStoreChunkFromBuffer< + std::shared_ptr const>>( + auxiliary::shareRaw(data), {std::move(*this)}); +} + +template +template +auto ConfigureLoadStore::fromUniquePtr(std::unique_ptr data) + -> ConfigureStoreChunkFromBuffer< + UniquePtrWithLambda>> +{ + return fromUniquePtr(UniquePtrWithLambda(std::move(data))); +} +template +template +auto ConfigureLoadStore::fromContiguousContainer( + T_ContiguousContainer &data) -> + typename std::enable_if_t< + auxiliary::IsContiguousContainer_v, + ConfigureStoreChunkFromBuffer const>>> +{ + if (!m_extent.has_value() && dim() == 1) + { + m_extent = Extent{data.size()}; + } + return fromRawPtr(data.data()); +} +} // namespace openPMD diff --git a/include/openPMD/RecordComponent.hpp b/include/openPMD/RecordComponent.hpp index 74fb6fc72c..d7aeab3ec3 100644 --- a/include/openPMD/RecordComponent.hpp +++ b/include/openPMD/RecordComponent.hpp @@ -134,7 +134,7 @@ class RecordComponent : public BaseRecordComponent friend class internal::RecordComponentData; friend class MeshRecordComponent; template - friend class ConfigureStoreChunk; + friend class ConfigureLoadStore; template friend class ConfigureStoreChunkFromBuffer; @@ -288,7 +288,7 @@ class RecordComponent : public BaseRecordComponent template void loadChunkRaw(T *data, Offset offset, Extent extent); - ConfigureStoreChunk prepareStoreChunk(); + ConfigureLoadStore prepareStoreChunk(); /** Store a chunk of data from a chunk of memory. * diff --git a/include/openPMD/RecordComponent.tpp b/include/openPMD/RecordComponent.tpp index 147d4d439d..743d1276f6 100644 --- a/include/openPMD/RecordComponent.tpp +++ b/include/openPMD/RecordComponent.tpp @@ -192,7 +192,7 @@ RecordComponent::storeChunk(std::shared_ptr data, Offset o, Extent e) .offset(std::move(o)) .extent(std::move(e)) .fromSharedPtr(std::move(data)) - .enqueue(); + .enqueueStore(); } template @@ -203,7 +203,7 @@ RecordComponent::storeChunk(UniquePtrWithLambda data, Offset o, Extent e) .offset(std::move(o)) .extent(std::move(e)) .fromUniquePtr(std::move(data)) - .enqueue(); + .enqueueStore(); } template @@ -214,7 +214,7 @@ RecordComponent::storeChunk(std::unique_ptr data, Offset o, Extent e) .offset(std::move(o)) .extent(std::move(e)) .fromUniquePtr(std::move(data)) - .enqueue(); + .enqueueStore(); } template @@ -224,7 +224,7 @@ void RecordComponent::storeChunkRaw(T *ptr, Offset offset, Extent extent) .offset(std::move(offset)) .extent(std::move(extent)) .fromRawPtr(ptr) - .enqueue(); + .enqueueStore(); } template @@ -244,7 +244,7 @@ RecordComponent::storeChunk(T_ContiguousContainer &data, Offset o, Extent e) storeChunkConfig.extent(std::move(e)); } - std::move(storeChunkConfig).fromContiguousContainer(data).enqueue(); + std::move(storeChunkConfig).fromContiguousContainer(data).enqueueStore(); } template @@ -254,7 +254,7 @@ RecordComponent::storeChunk(Offset o, Extent e, F &&createBuffer) return prepareStoreChunk() .offset(std::move(o)) .extent(std::move(e)) - .enqueue(std::forward(createBuffer)); + .enqueueStore(std::forward(createBuffer)); } template @@ -264,7 +264,7 @@ RecordComponent::storeChunk(Offset offset, Extent extent) return prepareStoreChunk() .offset(std::move(offset)) .extent(std::move(extent)) - .enqueue(); + .enqueueStore(); } template @@ -367,7 +367,7 @@ void RecordComponent::verifyChunk(Offset const &o, Extent const &e) const // definitions for LoadStoreChunk.hpp template template -auto ConfigureStoreChunk::enqueue(F &&createBuffer) +auto ConfigureLoadStore::enqueueStore(F &&createBuffer) -> DynamicMemoryView { return m_rc.storeChunkSpanCreateBuffer_impl( diff --git a/src/LoadStoreChunk.cpp b/src/LoadStoreChunk.cpp index 89712b728e..8b27ae7e41 100644 --- a/src/LoadStoreChunk.cpp +++ b/src/LoadStoreChunk.cpp @@ -44,24 +44,24 @@ namespace } // namespace template -ConfigureStoreChunk::ConfigureStoreChunk(RecordComponent &rc) +ConfigureLoadStore::ConfigureLoadStore(RecordComponent &rc) : ConfigureStoreChunkData(rc) {} template -ConfigureStoreChunk::ConfigureStoreChunk( +ConfigureLoadStore::ConfigureLoadStore( internal::ConfigureStoreChunkData &&data) : ConfigureStoreChunkData(std::move(data)) {} template -auto ConfigureStoreChunk::dim() const -> uint8_t +auto ConfigureLoadStore::dim() const -> uint8_t { return m_rc.getDimensionality(); } template -auto ConfigureStoreChunk::getOffset() const -> Offset +auto ConfigureLoadStore::getOffset() const -> Offset { if (m_offset.has_value()) { @@ -81,7 +81,7 @@ auto ConfigureStoreChunk::getOffset() const -> Offset } template -auto ConfigureStoreChunk::getExtent() const -> Extent +auto ConfigureLoadStore::getExtent() const -> Extent { if (m_extent.has_value()) { @@ -94,21 +94,21 @@ auto ConfigureStoreChunk::getExtent() const -> Extent } template -auto ConfigureStoreChunk::storeChunkConfig() const +auto ConfigureLoadStore::storeChunkConfig() const -> internal::StoreChunkConfig { return internal::StoreChunkConfig{getOffset(), getExtent()}; } template -auto ConfigureStoreChunk::extent(Extent extent) -> return_type & +auto ConfigureLoadStore::extent(Extent extent) -> return_type & { m_extent = std::move(extent); return *static_cast(this); } template -auto ConfigureStoreChunk::offset(Offset offset) -> return_type & +auto ConfigureLoadStore::offset(Offset offset) -> return_type & { m_offset = std::move(offset); return *static_cast(this); @@ -116,7 +116,7 @@ auto ConfigureStoreChunk::offset(Offset offset) -> return_type & template template -auto ConfigureStoreChunk::enqueue() -> DynamicMemoryView +auto ConfigureLoadStore::enqueueStore() -> DynamicMemoryView { return m_rc.storeChunkSpan_impl(storeChunkConfig()); } @@ -161,7 +161,7 @@ auto ConfigureStoreChunkFromBuffer::memorySelection( } template -auto ConfigureStoreChunkFromBuffer::enqueue() -> void +auto ConfigureStoreChunkFromBuffer::enqueueStore() -> void { this->m_rc.storeChunk_impl( asWriteBuffer(std::move(m_buffer)), @@ -170,12 +170,12 @@ auto ConfigureStoreChunkFromBuffer::enqueue() -> void } #define INSTANTIATE_METHOD_TEMPLATES(base_class, dtype) \ - template auto base_class::enqueue() -> DynamicMemoryView; + template auto base_class::enqueueStore() -> DynamicMemoryView; #define INSTANTIATE_METHOD_TEMPLATES_FOR_BASE(dtype) \ - INSTANTIATE_METHOD_TEMPLATES(ConfigureStoreChunk, dtype) + INSTANTIATE_METHOD_TEMPLATES(ConfigureLoadStore, dtype) -template class ConfigureStoreChunk; +template class ConfigureLoadStore; OPENPMD_FOREACH_DATASET_DATATYPE(INSTANTIATE_METHOD_TEMPLATES_FOR_BASE) #undef INSTANTIATE_METHOD_TEMPLATES_FOR_BASE @@ -183,17 +183,17 @@ OPENPMD_FOREACH_DATASET_DATATYPE(INSTANTIATE_METHOD_TEMPLATES_FOR_BASE) #define INSTANTIATE_STORE_CHUNK_FROM_BUFFER(dtype) \ template class ConfigureStoreChunkFromBuffer< \ std::shared_ptr>; \ - template class ConfigureStoreChunk< \ + template class ConfigureLoadStore< \ ConfigureStoreChunkFromBuffer>>; \ INSTANTIATE_METHOD_TEMPLATES( \ - ConfigureStoreChunk< \ + ConfigureLoadStore< \ ConfigureStoreChunkFromBuffer>>, \ dtype) \ template class ConfigureStoreChunkFromBuffer>; \ - template class ConfigureStoreChunk< \ + template class ConfigureLoadStore< \ ConfigureStoreChunkFromBuffer>>; \ INSTANTIATE_METHOD_TEMPLATES( \ - ConfigureStoreChunk< \ + ConfigureLoadStore< \ ConfigureStoreChunkFromBuffer>>, \ dtype) diff --git a/src/RecordComponent.cpp b/src/RecordComponent.cpp index 0d8e21c906..4041df127e 100644 --- a/src/RecordComponent.cpp +++ b/src/RecordComponent.cpp @@ -66,9 +66,9 @@ RecordComponent::RecordComponent() : BaseRecordComponent(NoInit()) setData(std::make_shared()); } -ConfigureStoreChunk RecordComponent::prepareStoreChunk() +ConfigureLoadStore RecordComponent::prepareStoreChunk() { - return ConfigureStoreChunk{*this}; + return ConfigureLoadStore{*this}; } namespace diff --git a/test/ParallelIOTest.cpp b/test/ParallelIOTest.cpp index 668fa2a749..b530ccc04e 100644 --- a/test/ParallelIOTest.cpp +++ b/test/ParallelIOTest.cpp @@ -440,13 +440,13 @@ void available_chunks_test(std::string const &file_ending) .fromContiguousContainer(ydata_firstandlastrow) .offset({0, 3ul * mpi_rank}) .extent({1, 3}) - .enqueue(); + .enqueueStore(); E_y.prepareStoreChunk() .offset({1, 3ul * mpi_rank}) .extent({3, 3}) .fromContiguousContainer(ydata) .memorySelection({{1, 1}, {5, 5}}) - .enqueue(); + .enqueueStore(); // if condition checks if this PR is available in ADIOS2: // https://github.com/ornladios/ADIOS2/pull/4169 if constexpr (CanTheMemorySelectionBeReset) @@ -455,7 +455,7 @@ void available_chunks_test(std::string const &file_ending) .fromContiguousContainer(ydata_firstandlastrow) .offset({4, 3ul * mpi_rank}) .extent({1, 3}) - .enqueue(); + .enqueueStore(); } it0.close(); }