Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sels #1171

Merged
merged 4 commits into from
Feb 13, 2019
Merged

Sels #1171

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bindings/CXX11/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ target_sources(adios2 PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/cxx11/IO.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cxx11/IO.tcc
${CMAKE_CURRENT_SOURCE_DIR}/cxx11/Operator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cxx11/Types.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cxx11/Types.tcc
${CMAKE_CURRENT_SOURCE_DIR}/cxx11/Variable.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cxx11/fstream/ADIOS2fstream.cpp
)
Expand Down Expand Up @@ -38,5 +40,6 @@ install(
cxx11/Attribute.h
cxx11/Engine.h
cxx11/Operator.h
cxx11/Types.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cxx11
)
42 changes: 24 additions & 18 deletions bindings/CXX11/cxx11/Engine.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ void Engine::Put(Variable<T> variable, const T *data, const Mode launch)
{
using IOType = typename TypeInfo<T>::IOType;
adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Put");
adios2::helper::CheckForNullptr(
variable.m_Variable, "for variable in call to Engine::Put");
adios2::helper::CheckForNullptr(variable.m_Variable,
"for variable in call to Engine::Put");
m_Engine->Put(*variable.m_Variable, reinterpret_cast<const IOType *>(data),
launch);
}
Expand All @@ -80,8 +80,8 @@ void Engine::Put(Variable<T> variable, const T &datum, const Mode /*launch*/)
{
using IOType = typename TypeInfo<T>::IOType;
adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Put");
adios2::helper::CheckForNullptr(
variable.m_Variable, "for variable in call to Engine::Put");
adios2::helper::CheckForNullptr(variable.m_Variable,
"for variable in call to Engine::Put");
m_Engine->Put(*variable.m_Variable,
reinterpret_cast<const IOType &>(datum));
}
Expand All @@ -100,8 +100,8 @@ void Engine::Get(Variable<T> variable, T *data, const Mode launch)
{
using IOType = typename TypeInfo<T>::IOType;
adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get");
adios2::helper::CheckForNullptr(
variable.m_Variable, "for variable in call to Engine::Get");
adios2::helper::CheckForNullptr(variable.m_Variable,
"for variable in call to Engine::Get");
m_Engine->Get(*variable.m_Variable, reinterpret_cast<IOType *>(data),
launch);
}
Expand All @@ -119,8 +119,8 @@ void Engine::Get(Variable<T> variable, T &datum, const Mode /*launch*/)
{
using IOType = typename TypeInfo<T>::IOType;
adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get");
adios2::helper::CheckForNullptr(
variable.m_Variable, "for variable in call to Engine::Get");
adios2::helper::CheckForNullptr(variable.m_Variable,
"for variable in call to Engine::Get");
m_Engine->Get(*variable.m_Variable, reinterpret_cast<IOType &>(datum));
}

Expand All @@ -139,8 +139,8 @@ void Engine::Get(Variable<T> variable, std::vector<T> &dataV, const Mode launch)
using IOType = typename TypeInfo<T>::IOType;
adios2::helper::CheckForNullptr(
m_Engine, "in call to Engine::Get with std::vector argument");
adios2::helper::CheckForNullptr(
variable.m_Variable, "for variable in call to Engine::Get");
adios2::helper::CheckForNullptr(variable.m_Variable,
"for variable in call to Engine::Get");
m_Engine->Get(*variable.m_Variable,
reinterpret_cast<std::vector<IOType> &>(dataV), launch);
}
Expand All @@ -152,25 +152,30 @@ void Engine::Get(const std::string &variableName, std::vector<T> &dataV,
using IOType = typename TypeInfo<T>::IOType;
adios2::helper::CheckForNullptr(
m_Engine, "in call to Engine::Get with std::vector argument");
m_Engine->Get(variableName, reinterpret_cast<std::vector<IOType> &>(dataV), launch);
m_Engine->Get(variableName, reinterpret_cast<std::vector<IOType> &>(dataV),
launch);
}

template <class T>
void Engine::Get(Variable<T> variable, typename Variable<T>::Info& info, const Mode launch)
void Engine::Get(Variable<T> variable, typename Variable<T>::Info &info,
const Mode launch)
{
using IOType = typename TypeInfo<T>::IOType;
adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get");
adios2::helper::CheckForNullptr(
variable.m_Variable, "for variable in call to Engine::Get");
info.m_Info = m_Engine->Get(*variable.m_Variable, launch);
adios2::helper::CheckForNullptr(variable.m_Variable,
"for variable in call to Engine::Get");
info.m_Info = reinterpret_cast<typename Variable<T>::Info::CoreInfo *>(
m_Engine->Get(*variable.m_Variable, launch));
}

template <class T>
void Engine::Get(const std::string &variableName, typename Variable<T>::Info& info, const Mode launch)
void Engine::Get(const std::string &variableName,
typename Variable<T>::Info &info, const Mode launch)
{
using IOType = typename TypeInfo<T>::IOType;
adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get");
info.m_Info = m_Engine->Get<IOType>(variableName, launch);
info.m_Info = reinterpret_cast<typename Variable<T>::Info::CoreInfo *>(
m_Engine->Get<IOType>(variableName, launch));
}

template <class T>
Expand Down Expand Up @@ -205,7 +210,8 @@ Engine::AllStepsBlocksInfo(const Variable<T> variable) const

// Design Node: All Info structs are copied. This prevents Engine::Get() from
// connecting the Core Info struct to Binding Info struct when this method is
// called. Instead of returning a vector, BlocksInfo could populate a vector member
// called. Instead of returning a vector, BlocksInfo could populate a vector
// member
// of the Variable, and those could contain pointers to the Core Info structs,
// enabling users of the Inline engine to do Info.Data()
template <class T>
Expand Down
22 changes: 22 additions & 0 deletions bindings/CXX11/cxx11/Types.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* Types.cpp : implementation of Types.h
*
* Created on: Feb 12, 2019
* Author: William F Godoy godoywf@ornl.gov
*/
#include "Types.h"
#include "Types.tcc"

namespace adios2
{

#define declare_template_instantiation(T) \
template std::string GetType<T>() noexcept;

ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation

} // end namespace adios2
20 changes: 13 additions & 7 deletions bindings/CXX11/cxx11/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,29 @@
*
* Created on: Feb 11, 2019
* Author: Kai Germaschewski <kai.germaschewski@unh.edu>
* William F Godoy <godoywf@ornl.gov>
*/

#ifndef ADIOS2_BINDINGS_CXX11_TYPES_H_
#define ADIOS2_BINDINGS_CXX11_TYPES_H_

#include "adios2/helper/adiosType.h"
#include "Variable.h"

#include <vector>

namespace adios2
{

template <class T>
inline std::string GetType() noexcept
{
using IOType = typename TypeInfo<T>::IOType;
return helper::GetType<IOType>();
}
std::string GetType() noexcept;

} // end namespace adios2
// LIMIT TEMPLATE TYPES FOR adios2::GetType
#define declare_template_instantiation(T) \
\
extern template std::string GetType<T>() noexcept;

ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation

} // end namespace adios2
#endif /* ADIOS2_BINDINGS_CXX11_TYPES_H_ */
29 changes: 29 additions & 0 deletions bindings/CXX11/cxx11/Types.tcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* Types.tcc : implement template functions
*
* Created on: Feb 11, 2019
* Author: William F Godoy
*/

#ifndef ADIOS2_BINDINGS_CXX11_TYPES_TCC_
#define ADIOS2_BINDINGS_CXX11_TYPES_TCC_

#include "Types.h"

#include "adios2/helper/adiosFunctions.h"

namespace adios2
{

template <class T>
std::string GetType() noexcept
{
return helper::GetType<typename TypeInfo<T>::IOType>();
}

} // end namespace adios2

#endif /* ADIOS2_BINDINGS_CXX11_TYPES_TCC_ */
19 changes: 19 additions & 0 deletions bindings/CXX11/cxx11/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Author: William F Godoy godoywf@ornl.gov
*/
#include "Variable.h"
#include "Variable.tcc"

#include "adios2/ADIOSMacros.h"
#include "adios2/core/Variable.h"
Expand Down Expand Up @@ -200,6 +201,24 @@ namespace adios2
{ \
helper::CheckForNullptr(m_Variable, "in call to Variable<T>::Max"); \
return m_Variable->Max(step); \
} \
\
template <> \
std::vector<std::vector<typename Variable<T>::Info>> \
Variable<T>::AllStepsBlocksInfo() \
{ \
return DoAllStepsBlocksInfo(); \
} \
\
template <> \
const T *Variable<T>::Info::Data() const \
{ \
const core::Variable<T>::Info *coreInfo = \
reinterpret_cast<const core::Variable<T>::Info *>(m_Info); \
\
return m_Info ? (coreInfo->BufferP ? coreInfo->BufferP \
: coreInfo->BufferV.data()) \
: nullptr; \
}

ADIOS2_FOREACH_TYPE_1ARG(declare_type)
Expand Down
33 changes: 21 additions & 12 deletions bindings/CXX11/cxx11/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "Operator.h"

#include "adios2/ADIOSTypes.h"
#include "adios2/core/Variable.h"

namespace adios2
{
Expand Down Expand Up @@ -238,29 +237,39 @@ class Variable
/** Contains sub-block information for a particular Variable<T> */
struct Info
{
adios2::Dims Start; ///< block start
adios2::Dims Count; ///< block count
adios2::Dims Start; ///< block start
adios2::Dims Count; ///< block count
IOType Min = IOType(); ///< block Min, if IsValue is false
IOType Max = IOType(); ///< block Max, if IsValue is false
IOType Value = IOType(); ///< block Value, if IsValue is true
bool IsValue = false; ///< true: value, false: array
size_t BlockID = -1; ///< block ID for block selections
const T *Data() const
{
return m_Info ? (m_Info->BufferP ? m_Info->BufferP
: m_Info->BufferV.data())
: nullptr;
}; ///< block data for block selections. Provided by core Info.
bool IsValue = false; ///< true: value, false: array
size_t BlockID = -1; ///< block ID for block selections
size_t Step = 0;
const T *Data() const;

// allow Engine to set m_Info
friend class Engine;

private:
const typename core::Variable<IOType>::Info *m_Info;
class CoreInfo;
const CoreInfo *m_Info;
};

/**
* Read mode only and random-access (no BeginStep/EndStep) with file engines
* only. Allows inspection of variable info on a per relative step (returned
* vector index)
* basis
* @return first vector: relative steps, second vector: blocks info within a
* step
*/
std::vector<std::vector<typename Variable<T>::Info>> AllStepsBlocksInfo();

private:
Variable<T>(core::Variable<IOType> *variable);
core::Variable<IOType> *m_Variable = nullptr;

std::vector<std::vector<typename Variable<T>::Info>> DoAllStepsBlocksInfo();
};

} // end namespace adios2
Expand Down
85 changes: 85 additions & 0 deletions bindings/CXX11/cxx11/Variable.tcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* Variable.tcc : implementation of private template functions
*
* Created on: Feb 12, 2019
* Author: William F Godoy godoywf@ornl.gov
*/

#ifndef ADIOS2_BINDINGS_CXX11_CXX11_VARIABLE_TCC_
#define ADIOS2_BINDINGS_CXX11_CXX11_VARIABLE_TCC_

#include "Variable.h"

#include "adios2/helper/adiosFunctions.h"

namespace adios2
{

namespace
{

template <class T>
std::vector<typename Variable<T>::Info>
ToBlocksInfo(const std::vector<typename core::Variable<
typename TypeInfo<T>::IOType>::Info> &coreBlocksInfo)
{
using IOType = typename TypeInfo<T>::IOType;

std::vector<typename Variable<T>::Info> blocksInfo;
blocksInfo.reserve(coreBlocksInfo.size());

for (const typename core::Variable<IOType>::Info &coreBlockInfo :
coreBlocksInfo)
{
typename Variable<T>::Info blockInfo;
blockInfo.Start = coreBlockInfo.Start;
blockInfo.Count = coreBlockInfo.Count;
blockInfo.IsValue = coreBlockInfo.IsValue;
if (blockInfo.IsValue)
{
blockInfo.Value = coreBlockInfo.Value;
}
else
{
blockInfo.Min = coreBlockInfo.Min;
blockInfo.Max = coreBlockInfo.Max;
}
blockInfo.BlockID = coreBlockInfo.BlockID;
blockInfo.Step = coreBlockInfo.Step;
blocksInfo.push_back(blockInfo);
}

return blocksInfo;
}
} // end empty namespace

template <class T>
std::vector<std::vector<typename Variable<T>::Info>>
Variable<T>::DoAllStepsBlocksInfo()
{
helper::CheckForNullptr(m_Variable,
"in call to Variable<T>::AllStepsBlocksInfo");

// PRIVATE INPUT
const std::vector<std::vector<typename core::Variable<IOType>::Info>>
coreAllStepsBlocksInfo = m_Variable->AllStepsBlocksInfo();

// PUBLIC OUTPUT
std::vector<std::vector<typename Variable<T>::Info>> allStepsBlocksInfo(
coreAllStepsBlocksInfo.size());

size_t relativeStep = 0;
for (const auto &coreBlocksInfo : coreAllStepsBlocksInfo)
{
allStepsBlocksInfo[relativeStep] = ToBlocksInfo<T>(coreBlocksInfo);
++relativeStep;
}
return allStepsBlocksInfo;
}

} // end namespace adios2

#endif /* ADIOS2_BINDINGS_CXX11_CXX11_VARIABLE_TCC_ */
Loading