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

Added "std::vector<size_t> GetAbsoluteSteps(const Variable<T> variabl… #2508

Merged
merged 2 commits into from
Nov 5, 2020
Merged
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
5 changes: 4 additions & 1 deletion bindings/CXX11/adios2/cxx11/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
Engine::AllStepsBlocksInfo(const Variable<T> variable) const; \
\
template std::vector<typename Variable<T>::Info> Engine::BlocksInfo( \
const Variable<T> variable, const size_t step) const;
const Variable<T> variable, const size_t step) const; \
\
template std::vector<size_t> Engine::GetAbsoluteSteps( \
const Variable<T> variable) const;

ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
Expand Down
8 changes: 8 additions & 0 deletions bindings/CXX11/adios2/cxx11/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,14 @@ class Engine
std::vector<typename Variable<T>::Info>
BlocksInfo(const Variable<T> variable, const size_t step) const;

/**
* Get the absolute steps of a variable in a file. This is for
* information purposes only, because absolute steps cannot be used
* in any ADIOS2 calls.
*/
template <class T>
std::vector<size_t> GetAbsoluteSteps(const Variable<T> variable) const;

/**
* Inspect total number of available steps, use for file engines in read
* mode only
Expand Down
18 changes: 18 additions & 0 deletions bindings/CXX11/adios2/cxx11/Engine.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,24 @@ Engine::BlocksInfo(const Variable<T> variable, const size_t step) const
return ToBlocksInfo<T>(blocksInfo);
}

template <class T>
std::vector<size_t> Engine::GetAbsoluteSteps(const Variable<T> variable) const
{
using IOType = typename TypeInfo<T>::IOType;
adios2::helper::CheckForNullptr(
m_Engine, "for Engine in call to Engine::GetAbsoluteSteps");
if (m_Engine->m_EngineType == "NULL")
{
return std::vector<size_t>();
}

adios2::helper::CheckForNullptr(
variable.m_Variable,
"for variable in call to Engine::GetAbsoluteSteps");

return m_Engine->GetAbsoluteSteps<IOType>(*variable.m_Variable);
}

} // end namespace adios2

#endif /* ADIOS2_BINDINGS_CXX11_CXX11_ENGINE_TCC_ */
10 changes: 9 additions & 1 deletion source/adios2/core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ ADIOS2_FOREACH_STDTYPE_1ARG(declare_type)
{ \
ThrowUp("DoBlocksInfo"); \
return std::vector<typename Variable<T>::Info>(); \
} \
std::vector<size_t> Engine::DoGetAbsoluteSteps( \
const Variable<T> &variable) const \
{ \
ThrowUp("DoGetAbsoluteSteps"); \
return std::vector<size_t>(); \
}

ADIOS2_FOREACH_STDTYPE_1ARG(declare_type)
Expand Down Expand Up @@ -233,7 +239,9 @@ void Engine::CheckOpenModes(const std::set<Mode> &modes,
Engine::AllRelativeStepsBlocksInfo(const Variable<T> &) const; \
\
template std::vector<typename Variable<T>::Info> Engine::BlocksInfo( \
const Variable<T> &, const size_t) const;
const Variable<T> &, const size_t) const; \
template std::vector<size_t> Engine::GetAbsoluteSteps(const Variable<T> &) \
const;

ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
Expand Down
17 changes: 15 additions & 2 deletions source/adios2/core/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,14 @@ class Engine
std::vector<typename Variable<T>::Info>
BlocksInfo(const Variable<T> &variable, const size_t step) const;

/**
* Get the absolute steps of a variable in a file. This is for
* information purposes only, because absolute steps cannot be used
* in any ADIOS2 calls.
*/
template <class T>
std::vector<size_t> GetAbsoluteSteps(const Variable<T> &variable) const;

template <class T>
T *BufferData(const size_t payloadOffset,
const size_t bufferID = 0) noexcept;
Expand Down Expand Up @@ -509,7 +517,9 @@ class Engine
DoAllRelativeStepsBlocksInfo(const Variable<T> &variable) const; \
\
virtual std::vector<typename Variable<T>::Info> DoBlocksInfo( \
const Variable<T> &variable, const size_t step) const;
const Variable<T> &variable, const size_t step) const; \
virtual std::vector<size_t> DoGetAbsoluteSteps( \
const Variable<T> &variable) const;

ADIOS2_FOREACH_STDTYPE_1ARG(declare_type)
#undef declare_type
Expand Down Expand Up @@ -595,7 +605,10 @@ class Engine
Engine::AllRelativeStepsBlocksInfo(const Variable<T> &) const; \
\
extern template std::vector<typename Variable<T>::Info> \
Engine::BlocksInfo(const Variable<T> &, const size_t) const;
Engine::BlocksInfo(const Variable<T> &, const size_t) const; \
\
extern template std::vector<size_t> Engine::GetAbsoluteSteps( \
const Variable<T> &) const;

ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
Expand Down
13 changes: 13 additions & 0 deletions source/adios2/core/Engine.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,19 @@ Engine::BlocksInfo(const Variable<T> &variable, const size_t step) const
return DoBlocksInfo(variable, step);
}

template <class T>
std::vector<size_t> Engine::GetAbsoluteSteps(const Variable<T> &variable) const
{
const auto &m = variable.m_AvailableStepBlockIndexOffsets;
std::vector<size_t> keys;
keys.reserve(m.size());
for (auto it = m.cbegin(); it != m.cend(); ++it)
{
keys.push_back(it->first - 1);
}
return keys;
}

#define declare_type(T, L) \
template <> \
T *Engine::BufferData(const size_t payloadPosition, \
Expand Down
39 changes: 31 additions & 8 deletions testing/adios2/engine/bp/TestBPStepsFileGlobalArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ TEST_P(BPStepsFileGlobalArrayReaders, EveryStep)
EXPECT_EQ(var_i32.Steps(), NSteps);
EXPECT_EQ(var_i32.StepsStart(), 0);

auto absSteps = engine.GetAbsoluteSteps(var_i32);
EXPECT_EQ(absSteps.size(), NSteps);
std::cout << "Absolute steps of i32 = { ";
for (const auto s : absSteps)
{
std::cout << s << " ";
}
std::cout << "}" << std::endl;
for (std::size_t i = 0; i < NSteps; ++i)
{
EXPECT_EQ(absSteps[i], i);
}

var_i32.SetStepSelection({0, NSteps});
size_t start = static_cast<size_t>(mpiRank) * Nx;
var_i32.SetSelection({{start}, {Nx}});
Expand Down Expand Up @@ -356,7 +369,7 @@ TEST_P(BPStepsFileGlobalArrayReaders, NewVarPerStep)
fname = fname_prefix + ".Serial.bp";
#endif

auto lf_VarName = [](int step) -> std::string {
auto lf_VarName = [](std::size_t step) -> std::string {
return "i32_" + std::to_string(step);
};

Expand Down Expand Up @@ -412,13 +425,23 @@ TEST_P(BPStepsFileGlobalArrayReaders, NewVarPerStep)
<< "Read with File reading mode using explicit SetStepSelection"
<< std::endl;
}
for (int step = 0; step < NSteps; ++step)
for (size_t step = 0; step < NSteps; ++step)
{
const std::string varName = lf_VarName(step);
auto var = io.InquireVariable<int32_t>(varName);
EXPECT_TRUE(var);
EXPECT_EQ(var.Steps(), 1);
EXPECT_EQ(var.StepsStart(), 0);
auto absSteps = engine.GetAbsoluteSteps(var);
/*std::cout << "Absolute steps of " << varName << " = { ";
for (const auto s : absSteps)
{
std::cout << s << " ";
}
std::cout << "}" << std::endl;*/
EXPECT_EQ(absSteps.size(), 1);
EXPECT_EQ(absSteps[0], step);

var.SetStepSelection({0, 1});
size_t start = static_cast<size_t>(mpiRank) * Nx;
var.SetSelection({{start}, {Nx}});
Expand All @@ -444,7 +467,7 @@ TEST_P(BPStepsFileGlobalArrayReaders, NewVarPerStep)
std::cout << "Read with File reading mode without SetStepSelection"
<< std::endl;
}
for (int step = 0; step < NSteps; ++step)
for (size_t step = 0; step < NSteps; ++step)
{
const std::string varName = lf_VarName(step);
auto var = io.InquireVariable<int32_t>(varName);
Expand Down Expand Up @@ -476,7 +499,7 @@ TEST_P(BPStepsFileGlobalArrayReaders, NewVarPerStep)
", block by block"
<< std::endl;
}
for (int step = 0; step < NSteps; ++step)
for (size_t step = 0; step < NSteps; ++step)
{
const std::string varName = lf_VarName(step);
auto var = io.InquireVariable<int32_t>(varName);
Expand Down Expand Up @@ -510,7 +533,7 @@ TEST_P(BPStepsFileGlobalArrayReaders, NewVarPerStep)
std::cout << "Read with Stream reading mode step by step"
<< std::endl;
}
for (int step = 0; step < NSteps; ++step)
for (size_t step = 0; step < NSteps; ++step)
{
engine.BeginStep();
const std::string varName = lf_VarName(step);
Expand Down Expand Up @@ -545,7 +568,7 @@ TEST_P(BPStepsFileGlobalArrayReaders, NewVarPerStep)
<< "Read with Stream reading mode step by step, block by block"
<< std::endl;
}
for (int step = 0; step < NSteps; ++step)
for (size_t step = 0; step < NSteps; ++step)
{
engine.BeginStep();
const std::string varName = lf_VarName(step);
Expand Down Expand Up @@ -667,7 +690,7 @@ TEST_P(BPStepsFileGlobalArrayParameters, EveryOtherStep)
}
engine.Close();
}
#if ADIOS2_USE_MPI
#if ADIOS2_USE_MPIstepsWritten
MPI_Barrier(MPI_COMM_WORLD);
#endif

Expand Down Expand Up @@ -790,7 +813,7 @@ TEST_P(BPStepsFileGlobalArrayParameters, EveryOtherStep)
}

size_t writtenStep = 0;
for (int step = 0; step < NSteps; ++step)
for (std::size_t step = 0; step < NSteps; ++step)
{
engine.BeginStep();
if (step % 2 == Oddity)
Expand Down