diff --git a/source/adios2/core/Engine.inl b/source/adios2/core/Engine.inl index 1dde7f3c449f7dbb862113200883e84193ec4324..dccf770fd98215718fb83fdf6c0ba771827d1b8f 100644 --- a/source/adios2/core/Engine.inl +++ b/source/adios2/core/Engine.inl @@ -29,7 +29,7 @@ void Engine::Write(Variable<T> &variable, const T *values) { if (m_DebugMode) { - variable.CheckDims("in call to Write"); + variable.CheckDimsBeforeWrite("Write(" + variable.m_Name + ")"); } DoWrite(variable, values); diff --git a/source/adios2/core/VariableBase.cpp b/source/adios2/core/VariableBase.cpp index 713485cb904fe5920266488acc8e147123d4bdef..d98f572d15db6b399d008e6d5c4364cbbd29f91c 100644 --- a/source/adios2/core/VariableBase.cpp +++ b/source/adios2/core/VariableBase.cpp @@ -168,14 +168,6 @@ void VariableBase::InitShapeType() } m_ShapeID = ShapeID::JoinedArray; } - else if (std::count(m_Shape.begin(), m_Shape.end(), JoinedDim) > 1) - { - throw std::invalid_argument( - "ERROR: variable can't have more than one " - "JoinedDim in shape argument, in call to " - "DefineVariable " + - m_Name + "\n"); - } else if (m_Start.empty() && m_Count.empty()) { if (m_Shape.size() == 1 && m_Shape.front() == LocalValueDim) @@ -265,6 +257,12 @@ void VariableBase::InitShapeType() } /* Extra checks for invalid settings */ + if (m_DebugMode) + CheckDimsCommon("DefineVariable(" + m_Name + ")"); +} + +void VariableBase::CheckDimsCommon(const std::string hint) const +{ if (m_ShapeID != ShapeID::LocalValue) { if ((!m_Shape.empty() && @@ -276,14 +274,26 @@ void VariableBase::InitShapeType() { throw std::invalid_argument("ERROR: LocalValueDim is only " "allowed in a {LocalValueDim} " - "shape in call to " - "DefineVariable " + - m_Name + "\n"); + "shape in call to " + + hint + "\n"); } } + + if ((!m_Shape.empty() && + std::count(m_Shape.begin(), m_Shape.end(), JoinedDim) > 1) || + (!m_Start.empty() && + std::count(m_Start.begin(), m_Start.end(), JoinedDim) > 0) || + (!m_Count.empty() && + std::count(m_Count.begin(), m_Count.end(), JoinedDim) > 0)) + { + throw std::invalid_argument("ERROR: JoinedDim is only allowed once in " + "Shape and cannot appear in Start/Count in " + "call to " + + hint + "\n"); + } } -void VariableBase::CheckDims(const std::string hint) const +void VariableBase::CheckDimsBeforeWrite(const std::string hint) const { if (m_ShapeID == ShapeID::GlobalArray) { @@ -292,10 +302,12 @@ void VariableBase::CheckDims(const std::string hint) const throw std::invalid_argument( "ERROR: GlobalArray variable " + m_Name + " start and count dimensions must be defined by either " - "DefineVariable or a Selection " + + "DefineVariable or a Selection in call to " + hint + "\n"); } } + + CheckDimsCommon(hint); // TODO need to think more exceptions here } diff --git a/source/adios2/core/VariableBase.h b/source/adios2/core/VariableBase.h index 39c4367a00654c6cd9ceaecfb0388ffb2e49e4e2..61fc093dfd72f5860565edc4eb5da69d5ec72611 100644 --- a/source/adios2/core/VariableBase.h +++ b/source/adios2/core/VariableBase.h @@ -137,9 +137,14 @@ public: /** Registered transforms */ std::vector<TransformInfo> m_TransformsInfo; + /** Self-check dims according to type, called right after DefineVariable and + * SetSelection. + * @param hint extra debugging info for the exception */ + void CheckDimsCommon(const std::string hint) const; + /** Self-check dims according to type, called from Engine before Write * @param hint extra debugging info for the exception */ - void CheckDims(const std::string hint) const; + void CheckDimsBeforeWrite(const std::string hint) const; private: const bool m_DebugMode = false;