diff --git a/source/adios2/CMakeLists.txt b/source/adios2/CMakeLists.txt index b9c7b7a4ab..3bf8fe2e4d 100644 --- a/source/adios2/CMakeLists.txt +++ b/source/adios2/CMakeLists.txt @@ -15,6 +15,7 @@ add_library(adios2_core core/Stream.cpp core/Stream.tcc core/Variable.cpp core/Variable.tcc core/VariableBase.cpp + core/Span.cpp core/Span.tcc core/Group.cpp core/Group.tcc #operator diff --git a/source/adios2/core/Span.cpp b/source/adios2/core/Span.cpp new file mode 100644 index 0000000000..6fc7019835 --- /dev/null +++ b/source/adios2/core/Span.cpp @@ -0,0 +1,23 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Span.cpp + * + * Created on: Apr 17, 2022 + * Author: Jason Wang jason.ruonan.wang@gmail.com + */ + +#include "Span.tcc" + +namespace adios2 +{ +namespace core +{ + +#define declare_template_instantiation(T) template class Span; +ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation) +#undef declare_type + +} // end namespace core +} // end namespace adios2 diff --git a/source/adios2/core/Span.h b/source/adios2/core/Span.h new file mode 100644 index 0000000000..d2e97e343f --- /dev/null +++ b/source/adios2/core/Span.h @@ -0,0 +1,53 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Span.h + * + * Created on: Apr 17, 2022 + * Author: Jason Wang jason.ruonan.wang@gmail.com + */ + +#ifndef ADIOS2_CORE_SPAN_H_ +#define ADIOS2_CORE_SPAN_H_ + +#include "adios2/core/VariableBase.h" + +namespace adios2 +{ +namespace core +{ + +template +class Span +{ +public: + std::pair m_MinMaxMetadataPositions; + + // internal position variables from which the engine + // can return a valid pointer any time + // BP5 needs two levels of reference, BP3/4 uses only one + size_t m_PayloadPosition = 0; + int m_BufferIdx = -1; + + T m_Value = T{}; + + Span(Engine &engine, const size_t size); + ~Span() = default; + + size_t Size() const noexcept; + T *Data() const noexcept; + + T &At(const size_t position); + + T &operator[](const size_t position); + +private: + Engine &m_Engine; + size_t m_Size = 0; +}; + +} // end namespace core +} // end namespace adios2 + +#endif // ADIOS2_CORE_SPAN_H_ diff --git a/source/adios2/core/Span.tcc b/source/adios2/core/Span.tcc new file mode 100644 index 0000000000..ab7435cdd3 --- /dev/null +++ b/source/adios2/core/Span.tcc @@ -0,0 +1,66 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * Span.tcc + * + * Created on: Apr 17, 2022 + * Author: Jason Wang jason.ruonan.wang@gmail.com + */ + +#ifndef ADIOS2_CORE_SPAN_TCC_ +#define ADIOS2_CORE_SPAN_TCC_ + +#include "Span.h" + +#include "adios2/core/Engine.h" + +namespace adios2 +{ +namespace core +{ + +template +Span::Span(Engine &engine, const size_t size) +: m_Engine(engine), m_Size(size) +{ +} + +template +size_t Span::Size() const noexcept +{ + return m_Size; +} + +template +T *Span::Data() const noexcept +{ + return m_Engine.BufferData(m_BufferIdx, m_PayloadPosition); +} + +template +T &Span::At(const size_t position) +{ + if (position > m_Size) + { + helper::Throw( + "Core", "Span", "At", + "position " + std::to_string(position) + + " is out of bounds for span of size " + std::to_string(m_Size)); + } + + return (*this)[position]; +} + +template +T &Span::operator[](const size_t position) +{ + T &data = *m_Engine.BufferData(m_BufferIdx, + m_PayloadPosition + position * sizeof(T)); + return data; +} + +} // end namespace core +} // end namespace adios2 + +#endif // ADIOS2_CORE_SPAN_TCC_ diff --git a/source/adios2/core/Variable.cpp b/source/adios2/core/Variable.cpp index 187311e342..5c26fe56db 100644 --- a/source/adios2/core/Variable.cpp +++ b/source/adios2/core/Variable.cpp @@ -112,9 +112,5 @@ namespace core ADIOS2_FOREACH_STDTYPE_1ARG(declare_type) #undef declare_type -#define declare_template_instantiation(T) template class Span; -ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation) -#undef declare_type - } // end namespace core } // end namespace adios2 diff --git a/source/adios2/core/Variable.h b/source/adios2/core/Variable.h index 4b62a912ce..1f4ea40fbf 100644 --- a/source/adios2/core/Variable.h +++ b/source/adios2/core/Variable.h @@ -19,6 +19,7 @@ #include /// \endcond +#include "Span.h" #include "adios2/common/ADIOSTypes.h" #include "adios2/core/VariableBase.h" #include "adios2/helper/adiosMath.h" @@ -29,38 +30,6 @@ namespace adios2 namespace core { -template -class Span -{ -public: - std::pair m_MinMaxDataPositions; - std::pair m_MinMaxMetadataPositions; - - // internal position variables from which the engine - // can return a valid pointer any time - // BP5 needs two levels of reference, BP3/4 uses only one - size_t m_PayloadPosition = 0; - int m_BufferIdx = -1; - - T m_Value = T{}; - - Span(Engine &engine, const size_t size); - ~Span() = default; - - size_t Size() const noexcept; - T *Data() const noexcept; - - T &At(const size_t position); - const T &At(const size_t position) const; - - T &operator[](const size_t position); - const T &operator[](const size_t position) const; - -private: - Engine &m_Engine; - size_t m_Size = 0; -}; - /** * @param Base (parent) class for template derived (child) class Variable. */ diff --git a/source/adios2/core/Variable.tcc b/source/adios2/core/Variable.tcc index 9beb0b05d6..4f93c933a0 100644 --- a/source/adios2/core/Variable.tcc +++ b/source/adios2/core/Variable.tcc @@ -257,70 +257,6 @@ void Variable::CheckRandomAccess(const size_t step, } } -// Span functions -template -Span::Span(Engine &engine, const size_t size) -: m_Engine(engine), m_Size(size) -{ -} - -template -size_t Span::Size() const noexcept -{ - return m_Size; -} - -template -T *Span::Data() const noexcept -{ - return m_Engine.BufferData(m_BufferIdx, m_PayloadPosition); -} - -template -T &Span::At(const size_t position) -{ - if (position > m_Size) - { - helper::Throw( - "Core", "Variable", "At", - "position " + std::to_string(position) + - " is out of bounds for span of size " + std::to_string(m_Size)); - } - - return (*this)[position]; -} - -template -const T &Span::At(const size_t position) const -{ - if (position > m_Size) - { - helper::Throw( - "Core", "Variable", "At", - "position " + std::to_string(position) + - " is out of bounds for span of size " + std::to_string(m_Size) + - " , in call to const T& Span::At"); - } - - return (*this)[position]; -} - -template -T &Span::operator[](const size_t position) -{ - T &data = *m_Engine.BufferData(m_BufferIdx, - m_PayloadPosition + position * sizeof(T)); - return data; -} - -template -const T &Span::operator[](const size_t position) const -{ - const T &data = *m_Engine.BufferData( - m_BufferIdx, m_PayloadPosition + position * sizeof(T)); - return data; -} - } // end namespace core } // end namespace adios2