Skip to content

Commit

Permalink
Merge pull request #1598 from pnorbert/bp4-fix-localvaluedim-reading
Browse files Browse the repository at this point in the history
Fix reading global arrays made from local values in BP4 the same way …
  • Loading branch information
pnorbert authored Jul 3, 2019
2 parents 84c7a54 + eafb7fa commit 3a9726f
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 7 deletions.
7 changes: 7 additions & 0 deletions source/adios2/engine/bp4/BP4Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ void BP4Reader::DoClose(const int transportIndex)
return m_BP4Deserializer.AllStepsBlocksInfo(variable); \
} \
\
std::vector<std::vector<typename Variable<T>::Info>> \
BP4Reader::DoAllRelativeStepsBlocksInfo(const Variable<T> &variable) const \
{ \
TAU_SCOPED_TIMER("BP3Reader::AllRelativeStepsBlocksInfo"); \
return m_BP4Deserializer.AllRelativeStepsBlocksInfo(variable); \
} \
\
std::vector<typename Variable<T>::Info> BP4Reader::DoBlocksInfo( \
const Variable<T> &variable, const size_t step) const \
{ \
Expand Down
3 changes: 3 additions & 0 deletions source/adios2/engine/bp4/BP4Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class BP4Reader : public Engine
std::map<size_t, std::vector<typename Variable<T>::Info>> \
DoAllStepsBlocksInfo(const Variable<T> &variable) const final; \
\
std::vector<std::vector<typename Variable<T>::Info>> \
DoAllRelativeStepsBlocksInfo(const Variable<T> &) const final; \
\
std::vector<typename Variable<T>::Info> DoBlocksInfo( \
const Variable<T> &variable, const size_t step) const final;

Expand Down
4 changes: 4 additions & 0 deletions source/adios2/toolkit/format/bp4/BP4Deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,10 @@ ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation)
template std::map<size_t, std::vector<typename core::Variable<T>::Info>> \
BP4Deserializer::AllStepsBlocksInfo(const core::Variable<T> &) const; \
\
template std::vector<std::vector<typename core::Variable<T>::Info>> \
BP4Deserializer::AllRelativeStepsBlocksInfo(const core::Variable<T> &) \
const; \
\
template std::vector<typename core::Variable<T>::Info> \
BP4Deserializer::BlocksInfo(const core::Variable<T> &, const size_t) \
const; \
Expand Down
4 changes: 4 additions & 0 deletions source/adios2/toolkit/format/bp4/BP4Deserializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ class BP4Deserializer : public BP4Base
std::map<size_t, std::vector<typename core::Variable<T>::Info>>
AllStepsBlocksInfo(const core::Variable<T> &variable) const;

template <class T>
std::vector<std::vector<typename core::Variable<T>::Info>>
AllRelativeStepsBlocksInfo(const core::Variable<T> &variable) const;

template <class T>
std::vector<typename core::Variable<T>::Info>
BlocksInfo(const core::Variable<T> &variable, const size_t step) const;
Expand Down
24 changes: 22 additions & 2 deletions source/adios2/toolkit/format/bp4/BP4Deserializer.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ void BP4Deserializer::GetValueFromMetadata(core::Variable<T> &variable,

// global values only read one block per step
const size_t blocksStart = (variable.m_ShapeID == ShapeID::GlobalArray)
? variable.m_Start.front()
? blockInfo.Start.front()
: 0;

const size_t blocksCount = (variable.m_ShapeID == ShapeID::GlobalArray)
Expand All @@ -461,7 +461,7 @@ void BP4Deserializer::GetValueFromMetadata(core::Variable<T> &variable,
}
}

for (size_t b = blocksStart; b < blocksCount; ++b)
for (size_t b = blocksStart; b < blocksStart + blocksCount; ++b)
{
size_t localPosition = positions[b];
const Characteristics<T> characteristics =
Expand Down Expand Up @@ -585,6 +585,26 @@ BP4Deserializer::AllStepsBlocksInfo(const core::Variable<T> &variable) const
return allStepsBlocksInfo;
}

template <class T>
std::vector<std::vector<typename core::Variable<T>::Info>>
BP4Deserializer::AllRelativeStepsBlocksInfo(
const core::Variable<T> &variable) const
{
std::vector<std::vector<typename core::Variable<T>::Info>>
allRelativeStepsBlocksInfo(
variable.m_AvailableStepBlockIndexOffsets.size());

size_t relativeStep = 0;
for (const auto &pair : variable.m_AvailableStepBlockIndexOffsets)
{
const std::vector<size_t> &blockPositions = pair.second;
allRelativeStepsBlocksInfo[relativeStep] =
BlocksInfoCommon(variable, blockPositions);
++relativeStep;
}
return allRelativeStepsBlocksInfo;
}

template <class T>
std::vector<typename core::Variable<T>::Info>
BP4Deserializer::BlocksInfo(const core::Variable<T> &variable,
Expand Down
3 changes: 2 additions & 1 deletion testing/adios2/engine/bp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ gtest_add_tests(TARGET TestBPWriteReadLocalVariables ${extra_test_args} WORKING_
gtest_add_tests(TARGET TestBPWriteReadLocalVariablesSel ${extra_test_args} WORKING_DIRECTORY ${BP3_DIR})
gtest_add_tests(TARGET TestBPWriteReadLocalVariablesSelHighLevel ${extra_test_args} WORKING_DIRECTORY ${BP3_DIR})
gtest_add_tests(TARGET TestBPChangingShape ${extra_test_args} WORKING_DIRECTORY ${BP3_DIR})
gtest_add_tests(TARGET TestBPWriteReadBlockInfo ${extra_test_args} WORKING_DIRECTORY ${BP3_DIR})

gtest_add_tests(TARGET TestBPWriteReadADIOS2 ${extra_test_args} WORKING_DIRECTORY ${BP4_DIR} EXTRA_ARGS "BP4" TEST_SUFFIX _BP4)
gtest_add_tests(TARGET TestBPWriteReadADIOS2fstream ${extra_test_args} WORKING_DIRECTORY ${BP4_DIR} EXTRA_ARGS "BP4" TEST_SUFFIX _BP4)
Expand All @@ -155,9 +156,9 @@ gtest_add_tests(TARGET TestBPWriteReadLocalVariables ${extra_test_args} WORKING_
gtest_add_tests(TARGET TestBPWriteReadLocalVariablesSel ${extra_test_args} WORKING_DIRECTORY ${BP4_DIR} EXTRA_ARGS "BP4" TEST_SUFFIX _BP4)
gtest_add_tests(TARGET TestBPWriteReadLocalVariablesSelHighLevel ${extra_test_args} WORKING_DIRECTORY ${BP4_DIR} EXTRA_ARGS "BP4" TEST_SUFFIX _BP4)
gtest_add_tests(TARGET TestBPChangingShape ${extra_test_args} WORKING_DIRECTORY ${BP4_DIR} EXTRA_ARGS "BP4" TEST_SUFFIX _BP4)
gtest_add_tests(TARGET TestBPWriteReadBlockInfo ${extra_test_args} WORKING_DIRECTORY ${BP4_DIR} EXTRA_ARGS "BP4" TEST_SUFFIX _BP4)

# BP3 only for now
gtest_add_tests(TARGET TestBPWriteReadBlockInfo ${extra_test_args} WORKING_DIRECTORY ${BP3_DIR})
gtest_add_tests(TARGET TestBPWriteReadVariableSpan ${extra_test_args} WORKING_DIRECTORY ${BP3_DIR})
gtest_add_tests(TARGET TestBPWriteNull ${extra_test_args} WORKING_DIRECTORY ${BP3_DIR})

Expand Down
67 changes: 63 additions & 4 deletions testing/adios2/engine/bp/TestBPWriteReadBlockInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include "../SmallTestData.h"

std::string engineName; // comes from command line

class BPWriteReadBlockInfo : public ::testing::Test
{
public:
Expand Down Expand Up @@ -124,6 +126,16 @@ TEST_F(BPWriteReadBlockInfo, BPWriteReadBlockInfo1D8)
auto var_cr64 = io.DefineVariable<std::complex<double>>("cr64", shape,
start, count);

if (!engineName.empty())
{
io.SetEngine(engineName);
}
else
{
// Create the BP Engine
io.SetEngine("BPFile");
}

adios2::Engine bpWriter = io.Open(fname, adios2::Mode::Write);

for (size_t step = 0; step < NSteps; ++step)
Expand Down Expand Up @@ -159,7 +171,14 @@ TEST_F(BPWriteReadBlockInfo, BPWriteReadBlockInfo1D8)

{
adios2::IO io = adios.DeclareIO("ReadIO");

if (!engineName.empty())
{
io.SetEngine(engineName);
}
else
{
io.SetEngine("BPFile");
}
adios2::Engine bpReader = io.Open(fname, adios2::Mode::Read);

auto var_local = io.InquireVariable<int32_t>("local");
Expand Down Expand Up @@ -239,8 +258,6 @@ TEST_F(BPWriteReadBlockInfo, BPWriteReadBlockInfo1D8)
// TODO: other types

SmallTestData testData;
std::vector<int32_t> ILocal;
std::vector<std::string> ILocalStr;

std::string IString;
std::array<int8_t, Nx> I8;
Expand Down Expand Up @@ -341,19 +358,38 @@ TEST_F(BPWriteReadBlockInfo, BPWriteReadBlockInfo1D8)
const size_t domainSize = static_cast<size_t>(mpiSize);
for (size_t i = 0; i < domainSize; ++i)
{
std::vector<int32_t> ILocal;
std::vector<std::string> ILocalStr;

var_local.SetSelection({{i}, {domainSize - i}});
var_localStr.SetSelection({{i}, {domainSize - i}});

bpReader.Get(var_local, ILocal);
bpReader.Get(var_localStr, ILocalStr);
bpReader.PerformGets();

/*std::cout << "rank=" << mpiRank << " local["
<< std::to_string(i) << ":"
<< std::to_string(domainSize) << "] = {";
for (size_t j = i; j < domainSize; ++j)
{
std::cout << std::to_string(ILocal[j - i]) << " ";
}
std::cout << "]" << std::endl;*/

for (size_t j = i; j < domainSize; ++j)
{
std::stringstream ss;
ss << "t=" << t << " i=" << i << " j=" << j;
std::string msg = ss.str();

/*std::cout << "rank=" << mpiRank << " t=" << t << " i=" <<
i
<< " j=" << j
<< " data=" << std::to_string(ILocal[j - i])
<< " expect = " << std::to_string(j + t)
<< std::endl;*/

EXPECT_EQ(ILocal[j - i], j + t) << msg;
EXPECT_EQ(ILocalStr[j - i], std::to_string(j + t)) << msg;
}
Expand Down Expand Up @@ -412,6 +448,16 @@ TEST_F(BPWriteReadBlockInfo, BPWriteReadBlockInfo2D2x4)
auto var_cr64 = io.DefineVariable<std::complex<double>>("cr64", shape,
start, count);

if (!engineName.empty())
{
io.SetEngine(engineName);
}
else
{
// Create the BP Engine
io.SetEngine("BPFile");
}

adios2::Engine bpWriter = io.Open(fname, adios2::Mode::Write);

for (size_t step = 0; step < NSteps; ++step)
Expand Down Expand Up @@ -443,7 +489,15 @@ TEST_F(BPWriteReadBlockInfo, BPWriteReadBlockInfo2D2x4)

{
adios2::IO io = adios.DeclareIO("ReadIO");

if (!engineName.empty())
{
io.SetEngine(engineName);
}
else
{
// Create the BP Engine
io.SetEngine("BPFile");
}
adios2::Engine bpReader = io.Open(fname, adios2::Mode::Read);

auto var_iString = io.InquireVariable<std::string>("iString");
Expand Down Expand Up @@ -625,6 +679,11 @@ int main(int argc, char **argv)

int result;
::testing::InitGoogleTest(&argc, argv);

if (argc > 1)
{
engineName = std::string(argv[1]);
}
result = RUN_ALL_TESTS();

#ifdef ADIOS2_HAVE_MPI
Expand Down

0 comments on commit 3a9726f

Please sign in to comment.