From 12eab13975e971524d295d2ca6ab24000fb647cc Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Sun, 17 Apr 2022 21:26:04 -0400 Subject: [PATCH 1/4] moved Span class into separated files --- source/adios2/CMakeLists.txt | 1 + source/adios2/core/Variable.cpp | 4 --- source/adios2/core/Variable.h | 33 +---------------- source/adios2/core/Variable.tcc | 64 --------------------------------- 4 files changed, 2 insertions(+), 100 deletions(-) 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/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 From b0ffc917a0809226abb5607c19aa619a37835699 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Sun, 17 Apr 2022 21:26:50 -0400 Subject: [PATCH 2/4] added Span class files --- source/adios2/core/Span.cpp | 27 +++++++++++ source/adios2/core/Span.h | 67 +++++++++++++++++++++++++++ source/adios2/core/Span.tcc | 90 +++++++++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+) create mode 100644 source/adios2/core/Span.cpp create mode 100644 source/adios2/core/Span.h create mode 100644 source/adios2/core/Span.tcc diff --git a/source/adios2/core/Span.cpp b/source/adios2/core/Span.cpp new file mode 100644 index 0000000000..5b70684054 --- /dev/null +++ b/source/adios2/core/Span.cpp @@ -0,0 +1,27 @@ +/* + * 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" + +#include "adios2/common/ADIOSMacros.h" +#include "adios2/core/Engine.h" +#include "adios2/helper/adiosFunctions.h" //helper::GetDataType + +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..dd0f0d99f3 --- /dev/null +++ b/source/adios2/core/Span.h @@ -0,0 +1,67 @@ +/* + * 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_ + +/// \cond EXCLUDE_FROM_DOXYGEN +#include +#include //std::ostream in MonitorGroups +#include +#include +#include +/// \endcond + +#include "adios2/common/ADIOSTypes.h" +#include "adios2/core/VariableBase.h" +#include "adios2/helper/adiosMath.h" +#include "adios2/helper/adiosType.h" + +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; +}; + +} // 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..e9d36a3226 --- /dev/null +++ b/source/adios2/core/Span.tcc @@ -0,0 +1,90 @@ +/* + * 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" +#include "adios2/helper/adiosFunctions.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 +const T &Span::At(const size_t position) const +{ + 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) + + " , 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 + +#endif /* ADIOS2_CORE_SPAN_TCC_ */ From 73be4d71da4448b68b68d340f07057533bcb355c Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Mon, 18 Apr 2022 00:37:31 -0400 Subject: [PATCH 3/4] removed unnecessary header files --- source/adios2/core/Span.cpp | 4 ---- source/adios2/core/Span.h | 11 ----------- source/adios2/core/Span.tcc | 1 - 3 files changed, 16 deletions(-) diff --git a/source/adios2/core/Span.cpp b/source/adios2/core/Span.cpp index 5b70684054..6fc7019835 100644 --- a/source/adios2/core/Span.cpp +++ b/source/adios2/core/Span.cpp @@ -10,10 +10,6 @@ #include "Span.tcc" -#include "adios2/common/ADIOSMacros.h" -#include "adios2/core/Engine.h" -#include "adios2/helper/adiosFunctions.h" //helper::GetDataType - namespace adios2 { namespace core diff --git a/source/adios2/core/Span.h b/source/adios2/core/Span.h index dd0f0d99f3..7e680f5d30 100644 --- a/source/adios2/core/Span.h +++ b/source/adios2/core/Span.h @@ -11,18 +11,7 @@ #ifndef ADIOS2_CORE_SPAN_H_ #define ADIOS2_CORE_SPAN_H_ -/// \cond EXCLUDE_FROM_DOXYGEN -#include -#include //std::ostream in MonitorGroups -#include -#include -#include -/// \endcond - -#include "adios2/common/ADIOSTypes.h" #include "adios2/core/VariableBase.h" -#include "adios2/helper/adiosMath.h" -#include "adios2/helper/adiosType.h" namespace adios2 { diff --git a/source/adios2/core/Span.tcc b/source/adios2/core/Span.tcc index e9d36a3226..53b61ae659 100644 --- a/source/adios2/core/Span.tcc +++ b/source/adios2/core/Span.tcc @@ -14,7 +14,6 @@ #include "Span.h" #include "adios2/core/Engine.h" -#include "adios2/helper/adiosFunctions.h" namespace adios2 { From 43d83044ea1d5c7ac74be336912dc9453700773c Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Mon, 18 Apr 2022 04:33:37 -0400 Subject: [PATCH 4/4] removed unused members in Span --- source/adios2/core/Span.h | 5 +---- source/adios2/core/Span.tcc | 25 +------------------------ 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/source/adios2/core/Span.h b/source/adios2/core/Span.h index 7e680f5d30..d2e97e343f 100644 --- a/source/adios2/core/Span.h +++ b/source/adios2/core/Span.h @@ -22,7 +22,6 @@ template class Span { public: - std::pair m_MinMaxDataPositions; std::pair m_MinMaxMetadataPositions; // internal position variables from which the engine @@ -40,10 +39,8 @@ class Span 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; @@ -53,4 +50,4 @@ class Span } // end namespace core } // end namespace adios2 -#endif /* ADIOS2_CORE_SPAN_H_ */ +#endif // ADIOS2_CORE_SPAN_H_ diff --git a/source/adios2/core/Span.tcc b/source/adios2/core/Span.tcc index 53b61ae659..ab7435cdd3 100644 --- a/source/adios2/core/Span.tcc +++ b/source/adios2/core/Span.tcc @@ -52,21 +52,6 @@ T &Span::At(const size_t position) return (*this)[position]; } -template -const T &Span::At(const size_t position) const -{ - 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) + - " , in call to const T& Span::At"); - } - - return (*this)[position]; -} - template T &Span::operator[](const size_t position) { @@ -75,15 +60,7 @@ T &Span::operator[](const size_t position) 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 -#endif /* ADIOS2_CORE_SPAN_TCC_ */ +#endif // ADIOS2_CORE_SPAN_TCC_