From 90ea2df846a5b71380d3333d855cc1cd0e9f00a8 Mon Sep 17 00:00:00 2001 From: Norbert Podhorszki Date: Fri, 12 Jun 2020 15:46:49 -0400 Subject: [PATCH] Do not extend buffer twice during PerformPuts, and maintain deferred datasize correctly in case of multiple calls of PerformPuts(). Addresses #2320 --- bindings/CXX11/adios2/cxx11/Engine.cpp | 11 + bindings/CXX11/adios2/cxx11/Engine.h | 3 + source/adios2/core/Engine.cpp | 8 +- source/adios2/core/Engine.h | 3 + source/adios2/engine/bp3/BP3Writer.cpp | 5 + source/adios2/engine/bp3/BP3Writer.h | 5 +- source/adios2/engine/bp3/BP3Writer.tcc | 22 +- source/adios2/engine/bp4/BP4Writer.cpp | 16 +- source/adios2/engine/bp4/BP4Writer.h | 5 +- source/adios2/engine/bp4/BP4Writer.tcc | 23 +- source/adios2/toolkit/format/bp/BPBase.cpp | 2 + source/adios2/toolkit/format/bp/BPBase.h | 2 + .../toolkit/format/buffer/heap/BufferSTL.cpp | 2 + .../toolkit/format/buffer/heap/BufferSTL.h | 2 + testing/adios2/engine/bp/CMakeLists.txt | 4 + testing/adios2/engine/bp/TestBPBufferSize.cpp | 286 ++++++++++++++++++ 16 files changed, 374 insertions(+), 25 deletions(-) create mode 100644 testing/adios2/engine/bp/TestBPBufferSize.cpp diff --git a/bindings/CXX11/adios2/cxx11/Engine.cpp b/bindings/CXX11/adios2/cxx11/Engine.cpp index 96a2db955a..5a223a6231 100644 --- a/bindings/CXX11/adios2/cxx11/Engine.cpp +++ b/bindings/CXX11/adios2/cxx11/Engine.cpp @@ -199,6 +199,17 @@ ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation) ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation +size_t Engine::DebugGetDataBufferSize() const +{ + helper::CheckForNullptr(m_Engine, + "in call to Engine::DebugGetDataBufferSize"); + if (m_Engine->m_EngineType == "NULL") + { + return 0; + } + return m_Engine->DebugGetDataBufferSize(); +} + std::string ToString(const Engine &engine) { return std::string("Engine(Name: \"" + engine.Name() + "\", Type: \"" + diff --git a/bindings/CXX11/adios2/cxx11/Engine.h b/bindings/CXX11/adios2/cxx11/Engine.h index 0a7b28aafb..f108d1788a 100644 --- a/bindings/CXX11/adios2/cxx11/Engine.h +++ b/bindings/CXX11/adios2/cxx11/Engine.h @@ -419,6 +419,9 @@ class Engine */ void LockReaderSelections(); + /* Debug function for adios2 testing framework */ + size_t DebugGetDataBufferSize() const; + private: Engine(core::Engine *engine); core::Engine *m_Engine = nullptr; diff --git a/source/adios2/core/Engine.cpp b/source/adios2/core/Engine.cpp index fe7c94fe89..bc22c37310 100644 --- a/source/adios2/core/Engine.cpp +++ b/source/adios2/core/Engine.cpp @@ -89,6 +89,12 @@ void Engine::LockReaderSelections() noexcept m_ReaderSelectionsLocked = true; } +size_t Engine::DebugGetDataBufferSize() const +{ + ThrowUp("DebugGetDataBufferSize"); + return 0; +} + // PROTECTED void Engine::Init() {} void Engine::InitParameters() {} @@ -171,7 +177,7 @@ ADIOS2_FOREACH_PRIMITVE_STDTYPE_2ARGS(declare_type) size_t Engine::DoSteps() const { - ThrowUp("DoPut"); + ThrowUp("DoSteps"); return MaxSizeT; } diff --git a/source/adios2/core/Engine.h b/source/adios2/core/Engine.h index eff087fe1a..cc8d265ecf 100644 --- a/source/adios2/core/Engine.h +++ b/source/adios2/core/Engine.h @@ -436,6 +436,9 @@ class Engine */ void LockReaderSelections() noexcept; + /* for adios2 internal testing */ + virtual size_t DebugGetDataBufferSize() const; + protected: /** from ADIOS class passed to Engine created with Open * if no communicator is passed */ diff --git a/source/adios2/engine/bp3/BP3Writer.cpp b/source/adios2/engine/bp3/BP3Writer.cpp index 3e2539869c..d5b75fbb39 100644 --- a/source/adios2/engine/bp3/BP3Writer.cpp +++ b/source/adios2/engine/bp3/BP3Writer.cpp @@ -79,6 +79,7 @@ void BP3Writer::PerformPuts() #undef declare_template_instantiation } m_BP3Serializer.m_DeferredVariables.clear(); + m_BP3Serializer.m_DeferredVariablesDataSize = 0; } void BP3Writer::EndStep() @@ -413,6 +414,10 @@ void BP3Writer::AggregateWriteData(const bool isFinal, const int transportIndex) ADIOS2_FOREACH_PRIMITVE_STDTYPE_2ARGS(declare_type) #undef declare_type +size_t BP3Writer::DebugGetDataBufferSize() const +{ + return m_BP3Serializer.DebugGetDataBufferSize(); +} } // end namespace engine } // end namespace core } // end namespace adios2 diff --git a/source/adios2/engine/bp3/BP3Writer.h b/source/adios2/engine/bp3/BP3Writer.h index 976e207a2e..6529eab47e 100644 --- a/source/adios2/engine/bp3/BP3Writer.h +++ b/source/adios2/engine/bp3/BP3Writer.h @@ -46,6 +46,8 @@ class BP3Writer : public core::Engine void EndStep() final; void Flush(const int transportIndex = -1) final; + size_t DebugGetDataBufferSize() const final; + private: /** Single object controlling BP buffering */ format::BP3Serializer m_BP3Serializer; @@ -85,7 +87,8 @@ class BP3Writer : public core::Engine template void PutSyncCommon(Variable &variable, - const typename Variable::Info &blockInfo); + const typename Variable::Info &blockInfo, + const bool resize = true); template void PutDeferredCommon(Variable &variable, const T *data); diff --git a/source/adios2/engine/bp3/BP3Writer.tcc b/source/adios2/engine/bp3/BP3Writer.tcc index 16ddd7b4d2..6ab0b8ef5f 100644 --- a/source/adios2/engine/bp3/BP3Writer.tcc +++ b/source/adios2/engine/bp3/BP3Writer.tcc @@ -63,15 +63,21 @@ void BP3Writer::PutCommon(Variable &variable, template void BP3Writer::PutSyncCommon(Variable &variable, - const typename Variable::Info &blockInfo) + const typename Variable::Info &blockInfo, + const bool resize) { - const size_t dataSize = - helper::PayloadSize(blockInfo.Data, blockInfo.Count) + - m_BP3Serializer.GetBPIndexSizeInData(variable.m_Name, blockInfo.Count); + format::BP3Base::ResizeResult resizeResult = + format::BP3Base::ResizeResult::Success; + if (resize) + { + const size_t dataSize = + helper::PayloadSize(blockInfo.Data, blockInfo.Count) + + m_BP3Serializer.GetBPIndexSizeInData(variable.m_Name, + blockInfo.Count); - const format::BP3Base::ResizeResult resizeResult = - m_BP3Serializer.ResizeBuffer(dataSize, "in call to variable " + - variable.m_Name + " Put"); + resizeResult = m_BP3Serializer.ResizeBuffer( + dataSize, "in call to variable " + variable.m_Name + " Put"); + } // if first timestep Write create a new pg index or in time aggregation if (!m_BP3Serializer.m_MetadataSet.DataPGIsOpen) @@ -133,7 +139,7 @@ void BP3Writer::PerformPutCommon(Variable &variable) auto itSpanBlock = variable.m_BlocksSpan.find(b); if (itSpanBlock == variable.m_BlocksSpan.end()) { - PutSyncCommon(variable, variable.m_BlocksInfo[b]); + PutSyncCommon(variable, variable.m_BlocksInfo[b], false); } else { diff --git a/source/adios2/engine/bp4/BP4Writer.cpp b/source/adios2/engine/bp4/BP4Writer.cpp index ae644fd37a..eef2caf4e9 100644 --- a/source/adios2/engine/bp4/BP4Writer.cpp +++ b/source/adios2/engine/bp4/BP4Writer.cpp @@ -84,6 +84,7 @@ void BP4Writer::PerformPuts() #undef declare_template_instantiation } m_BP4Serializer.m_DeferredVariables.clear(); + m_BP4Serializer.m_DeferredVariablesDataSize = 0; } void BP4Writer::EndStep() @@ -540,7 +541,7 @@ void BP4Writer::UpdateActiveFlag(const bool active) m_FileMetadataIndexManager.SeekToFileEnd(); if (m_DrainBB) { - for (int i = 0; i < m_MetadataIndexFileNames.size(); ++i) + for (size_t i = 0; i < m_MetadataIndexFileNames.size(); ++i) { m_FileDrainer.AddOperationWriteAt( m_DrainMetadataIndexFileNames[i], @@ -574,7 +575,7 @@ void BP4Writer::WriteCollectiveMetadataFile(const bool isFinal) if (m_DrainBB) { - for (int i = 0; i < m_MetadataFileNames.size(); ++i) + for (size_t i = 0; i < m_MetadataFileNames.size(); ++i) { m_FileDrainer.AddOperationCopy( m_MetadataFileNames[i], m_DrainMetadataFileNames[i], @@ -637,7 +638,7 @@ void BP4Writer::WriteCollectiveMetadataFile(const bool isFinal) if (m_DrainBB) { - for (int i = 0; i < m_MetadataIndexFileNames.size(); ++i) + for (size_t i = 0; i < m_MetadataIndexFileNames.size(); ++i) { m_FileDrainer.AddOperationWrite( m_DrainMetadataIndexFileNames[i], @@ -678,7 +679,7 @@ void BP4Writer::WriteData(const bool isFinal, const int transportIndex) m_FileDataManager.FlushFiles(transportIndex); if (m_DrainBB) { - for (int i = 0; i < m_SubStreamNames.size(); ++i) + for (size_t i = 0; i < m_SubStreamNames.size(); ++i) { m_FileDrainer.AddOperationCopy(m_SubStreamNames[i], m_DrainSubStreamNames[i], dataSize); @@ -728,7 +729,7 @@ void BP4Writer::AggregateWriteData(const bool isFinal, const int transportIndex) if (m_DrainBB) { - for (int i = 0; i < m_SubStreamNames.size(); ++i) + for (size_t i = 0; i < m_SubStreamNames.size(); ++i) { m_FileDrainer.AddOperationCopy(m_SubStreamNames[i], m_DrainSubStreamNames[i], @@ -756,6 +757,11 @@ void BP4Writer::AggregateWriteData(const bool isFinal, const int transportIndex) ADIOS2_FOREACH_PRIMITVE_STDTYPE_2ARGS(declare_type) #undef declare_type +size_t BP4Writer::DebugGetDataBufferSize() const +{ + return m_BP4Serializer.DebugGetDataBufferSize(); +} + } // end namespace engine } // end namespace core } // end namespace adios2 diff --git a/source/adios2/engine/bp4/BP4Writer.h b/source/adios2/engine/bp4/BP4Writer.h index 097ffd024b..1b04c07d0c 100644 --- a/source/adios2/engine/bp4/BP4Writer.h +++ b/source/adios2/engine/bp4/BP4Writer.h @@ -47,6 +47,8 @@ class BP4Writer : public core::Engine void EndStep() final; void Flush(const int transportIndex = -1) final; + size_t DebugGetDataBufferSize() const final; + private: /** Single object controlling BP buffering */ format::BP4Serializer m_BP4Serializer; @@ -115,7 +117,8 @@ class BP4Writer : public core::Engine template void PutSyncCommon(Variable &variable, - const typename Variable::Info &blockInfo); + const typename Variable::Info &blockInfo, + const bool resize = true); template void PutDeferredCommon(Variable &variable, const T *data); diff --git a/source/adios2/engine/bp4/BP4Writer.tcc b/source/adios2/engine/bp4/BP4Writer.tcc index 94d8791dbd..fd0460534b 100644 --- a/source/adios2/engine/bp4/BP4Writer.tcc +++ b/source/adios2/engine/bp4/BP4Writer.tcc @@ -63,16 +63,21 @@ void BP4Writer::PutCommon(Variable &variable, template void BP4Writer::PutSyncCommon(Variable &variable, - const typename Variable::Info &blockInfo) + const typename Variable::Info &blockInfo, + const bool resize) { - const size_t dataSize = - helper::PayloadSize(blockInfo.Data, blockInfo.Count) + - m_BP4Serializer.GetBPIndexSizeInData(variable.m_Name, blockInfo.Count); - - const format::BP4Base::ResizeResult resizeResult = - m_BP4Serializer.ResizeBuffer(dataSize, "in call to variable " + - variable.m_Name + " Put"); + format::BP4Base::ResizeResult resizeResult = + format::BP4Base::ResizeResult::Success; + if (resize) + { + const size_t dataSize = + helper::PayloadSize(blockInfo.Data, blockInfo.Count) + + m_BP4Serializer.GetBPIndexSizeInData(variable.m_Name, + blockInfo.Count); + resizeResult = m_BP4Serializer.ResizeBuffer( + dataSize, "in call to variable " + variable.m_Name + " Put"); + } // if first timestep Write create a new pg index if (!m_BP4Serializer.m_MetadataSet.DataPGIsOpen) { @@ -133,7 +138,7 @@ void BP4Writer::PerformPutCommon(Variable &variable) auto itSpanBlock = variable.m_BlocksSpan.find(b); if (itSpanBlock == variable.m_BlocksSpan.end()) { - PutSyncCommon(variable, variable.m_BlocksInfo[b]); + PutSyncCommon(variable, variable.m_BlocksInfo[b], false); } else { diff --git a/source/adios2/toolkit/format/bp/BPBase.cpp b/source/adios2/toolkit/format/bp/BPBase.cpp index 2f92a4cd62..10a9ddf079 100644 --- a/source/adios2/toolkit/format/bp/BPBase.cpp +++ b/source/adios2/toolkit/format/bp/BPBase.cpp @@ -505,5 +505,7 @@ std::map> BPBase::SetBPOperations( ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation +size_t BPBase::DebugGetDataBufferSize() const { return m_Data.DebugGetSize(); } + } // end namespace format } // end namespace adios2 diff --git a/source/adios2/toolkit/format/bp/BPBase.h b/source/adios2/toolkit/format/bp/BPBase.h index 99f1e65eee..c1285df588 100644 --- a/source/adios2/toolkit/format/bp/BPBase.h +++ b/source/adios2/toolkit/format/bp/BPBase.h @@ -318,6 +318,8 @@ class BPBase /** Delete buffer memory manually */ void DeleteBuffers(); + size_t DebugGetDataBufferSize() const; + protected: /** file I/O method type, adios1 legacy, only POSIX and MPI_AGG are used */ enum IO_METHOD diff --git a/source/adios2/toolkit/format/buffer/heap/BufferSTL.cpp b/source/adios2/toolkit/format/buffer/heap/BufferSTL.cpp index a08a9fc422..fcf2153a7f 100644 --- a/source/adios2/toolkit/format/buffer/heap/BufferSTL.cpp +++ b/source/adios2/toolkit/format/buffer/heap/BufferSTL.cpp @@ -68,5 +68,7 @@ ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(declare_template_instantiation) void BufferSTL::Delete() { std::vector().swap(m_Buffer); } +size_t BufferSTL::DebugGetSize() const { return m_Buffer.size(); }; + } // end namespace format } // end namespace adios2 diff --git a/source/adios2/toolkit/format/buffer/heap/BufferSTL.h b/source/adios2/toolkit/format/buffer/heap/BufferSTL.h index 9287701a63..f9b1fe2ffe 100644 --- a/source/adios2/toolkit/format/buffer/heap/BufferSTL.h +++ b/source/adios2/toolkit/format/buffer/heap/BufferSTL.h @@ -42,6 +42,8 @@ class BufferSTL : public Buffer size_t Align() const noexcept; void Delete(); + + size_t DebugGetSize() const; }; #define declare_template_instantiation(T) \ diff --git a/testing/adios2/engine/bp/CMakeLists.txt b/testing/adios2/engine/bp/CMakeLists.txt index 5b283070f9..f47d49ee46 100644 --- a/testing/adios2/engine/bp/CMakeLists.txt +++ b/testing/adios2/engine/bp/CMakeLists.txt @@ -42,6 +42,10 @@ bp3_bp4_gtest_add_tests_helper(WriteReadVariableSpan MPI_ALLOW) bp3_bp4_gtest_add_tests_helper(TimeAggregation MPI_ALLOW) bp3_bp4_gtest_add_tests_helper(NoXMLRecovery MPI_ALLOW) +if(NOT MSVC) + bp3_bp4_gtest_add_tests_helper(BufferSize MPI_NONE) +endif() + if(ADIOS2_HAVE_MPI) bp3_bp4_gtest_add_tests_helper(WriteAggregateRead MPI_ONLY) endif() diff --git a/testing/adios2/engine/bp/TestBPBufferSize.cpp b/testing/adios2/engine/bp/TestBPBufferSize.cpp new file mode 100644 index 0000000000..e9f2e71311 --- /dev/null +++ b/testing/adios2/engine/bp/TestBPBufferSize.cpp @@ -0,0 +1,286 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + */ +#include +#include + +#include +#include +#include + +#include +#include + +std::string engineName; // comes from command line + +class BPBufferSizeTest : public ::testing::Test +{ +public: + BPBufferSizeTest() = default; +}; + +std::ifstream vm_input; +void PrintVMStatus() +{ + std::string m_Name = "/proc/self/status"; + + if (!vm_input.is_open()) + { + vm_input.open(m_Name.c_str()); + } + + if (vm_input.is_open()) + { + vm_input.seekg(0); + for (std::string line; getline(vm_input, line);) + { + if (line.find("VmRSS") == 0) + std::cout << line << " "; + if (line.find("VmSize") == 0) + std::cout << line << " "; + } + vm_input.close(); + } +} + +void VMStatusClose() +{ + if (vm_input.is_open()) + { + vm_input.close(); + } +} + +size_t GetAndPrintBufferSize(adios2::Engine &engine, const std::string &info, + size_t step = 999999999) +{ + + size_t s = engine.DebugGetDataBufferSize(); + std::cout << std::left << std::setw(35) << info; + if (step < 999999999) + { + std::cout << " step " << std::setw(4) << std::to_string(step); + } + else + { + std::cout << std::setw(10) << " "; + } + std::cout << " buffer size = " << std::setw(12) << std::to_string(s) << " "; + PrintVMStatus(); + std::cout << std::endl; + return s; +} + +//****************************************************************************** +// 1D 1x8 test data +//****************************************************************************** + +// Put(Sync) and Put(Deferred) should have the same buffer consumption +TEST_F(BPBufferSizeTest, SyncDeferredIdenticalUsage) +{ + std::string fnameSync = "ADIOS2BPBufferSizeSync.bp"; + std::string fnameDeferred = "ADIOS2BPBufferSizeDeferred.bp"; + int mpiRank = 0, mpiSize = 1; + // Number of rows + const std::size_t Nx = 10485760; // 10M elements, 80MB variable + std::vector data; + data.resize(Nx); + + // Number of steps + const std::size_t NSteps = 3; + +#if ADIOS2_USE_MPI + MPI_Comm_rank(MPI_COMM_WORLD, &mpiRank); + MPI_Comm_size(MPI_COMM_WORLD, &mpiSize); +#endif + + // Write test data using BP + { +#if ADIOS2_USE_MPI + adios2::ADIOS adios(MPI_COMM_WORLD); +#else + adios2::ADIOS adios; +#endif + adios2::IO io = adios.DeclareIO("TestIO"); + adios2::Dims shape{static_cast(Nx * mpiSize)}; + adios2::Dims start{static_cast(Nx * mpiRank)}; + adios2::Dims count{static_cast(Nx)}; + + auto var1 = io.DefineVariable("r64_1", shape, start, count); + auto var2 = io.DefineVariable("r64_2", shape, start, count); + auto var3 = io.DefineVariable("r64_3", shape, start, count); + + if (!engineName.empty()) + { + io.SetEngine(engineName); + } + else + { + // Create the BP Engine + io.SetEngine("BPFile"); + } + + // Write with Sync + size_t bufsize_sync_init = 0; + size_t bufsize_sync_beginstep[NSteps]; + size_t bufsize_sync_v1[NSteps]; + size_t bufsize_sync_v2[NSteps]; + size_t bufsize_sync_v3[NSteps]; + size_t bufsize_sync_endstep[NSteps]; + { + adios2::Engine engine = io.Open(fnameSync, adios2::Mode::Write); + + bufsize_sync_init = GetAndPrintBufferSize(engine, "After Open():"); + for (size_t step = 0; step < NSteps; ++step) + { + engine.BeginStep(); + bufsize_sync_beginstep[step] = + GetAndPrintBufferSize(engine, "After BeginStep():"); + engine.Put(var1, data.data(), adios2::Mode::Sync); + bufsize_sync_v1[step] = + GetAndPrintBufferSize(engine, "After Put(v1, Sync):", step); + engine.Put(var2, data.data(), adios2::Mode::Sync); + bufsize_sync_v2[step] = + GetAndPrintBufferSize(engine, "After Put(v2, Sync):", step); + engine.Put(var3, data.data(), adios2::Mode::Sync); + bufsize_sync_v3[step] = + GetAndPrintBufferSize(engine, "After Put(v3, Sync):", step); + engine.EndStep(); + bufsize_sync_endstep[step] = + GetAndPrintBufferSize(engine, "After EndStep():", step); + } + + engine.Close(); + } + + // Write with Deferred + size_t bufsize_deferred_init = 0; + size_t bufsize_deferred_beginstep[NSteps]; + size_t bufsize_deferred_v1[NSteps]; + size_t bufsize_deferred_v2[NSteps]; + size_t bufsize_deferred_v3[NSteps]; + size_t bufsize_deferred_endstep[NSteps]; + { + adios2::Engine engine = io.Open(fnameDeferred, adios2::Mode::Write); + + bufsize_deferred_init = + GetAndPrintBufferSize(engine, "After Open():"); + for (size_t step = 0; step < NSteps; ++step) + { + engine.BeginStep(); + bufsize_deferred_beginstep[step] = + GetAndPrintBufferSize(engine, "After BeginStep():"); + engine.Put(var1, data.data(), adios2::Mode::Deferred); + bufsize_deferred_v1[step] = GetAndPrintBufferSize( + engine, "After Put(v1, Deferred):", step); + engine.Put(var2, data.data(), adios2::Mode::Deferred); + bufsize_deferred_v2[step] = GetAndPrintBufferSize( + engine, "After Put(v2, Deferred):", step); + engine.Put(var3, data.data(), adios2::Mode::Deferred); + bufsize_deferred_v3[step] = GetAndPrintBufferSize( + engine, "After Put(v3, Deferred):", step); + engine.EndStep(); + bufsize_deferred_endstep[step] = + GetAndPrintBufferSize(engine, "After EndStep():", step); + } + + engine.Close(); + } + + // Write with Deferred+PerformPuts + size_t bufsize_deferred_pp_init = 0; + size_t bufsize_deferred_pp_beginstep[NSteps]; + size_t bufsize_deferred_pp_v1[NSteps]; + size_t bufsize_deferred_pp_v2[NSteps]; + size_t bufsize_deferred_pp_v3[NSteps]; + size_t bufsize_deferred_pp_endstep[NSteps]; + { + adios2::Engine engine = io.Open(fnameDeferred, adios2::Mode::Write); + + bufsize_deferred_pp_init = + GetAndPrintBufferSize(engine, "After Open():"); + for (size_t step = 0; step < NSteps; ++step) + { + engine.BeginStep(); + bufsize_deferred_pp_beginstep[step] = + GetAndPrintBufferSize(engine, "After BeginStep():"); + engine.Put(var1, data.data(), adios2::Mode::Deferred); + engine.PerformPuts(); + bufsize_deferred_pp_v1[step] = GetAndPrintBufferSize( + engine, "After Put(v1, Def)+PerformPuts():", step); + engine.Put(var2, data.data(), adios2::Mode::Deferred); + engine.PerformPuts(); + bufsize_deferred_pp_v2[step] = GetAndPrintBufferSize( + engine, "After Put(v2, Def)+PerformPuts():", step); + engine.Put(var3, data.data(), adios2::Mode::Deferred); + engine.PerformPuts(); + bufsize_deferred_pp_v3[step] = GetAndPrintBufferSize( + engine, "After Put(v3, Def)+PerformPuts():", step); + engine.EndStep(); + bufsize_deferred_pp_endstep[step] = + GetAndPrintBufferSize(engine, "After EndStep():", step); + } + + engine.Close(); + } + + VMStatusClose(); + + /* Compare buffer size usage. + * Buffer size should never be substantially more than the total data + * size + * */ + const size_t TotalDataSize = Nx * sizeof(double) * 3; + const size_t MaxExtra = 16777216; /* 16MB extra allowed in buffer */ + for (size_t step = 0; step < NSteps; ++step) + { + EXPECT_LT(bufsize_sync_beginstep[step], TotalDataSize + MaxExtra); + EXPECT_LT(bufsize_sync_v1[step], TotalDataSize + MaxExtra); + EXPECT_LT(bufsize_sync_v2[step], TotalDataSize + MaxExtra); + EXPECT_LT(bufsize_sync_v3[step], TotalDataSize + MaxExtra); + EXPECT_LT(bufsize_sync_endstep[step], TotalDataSize + MaxExtra); + + EXPECT_LT(bufsize_deferred_beginstep[step], + TotalDataSize + MaxExtra); + EXPECT_LT(bufsize_deferred_v1[step], TotalDataSize + MaxExtra); + EXPECT_LT(bufsize_deferred_v2[step], TotalDataSize + MaxExtra); + EXPECT_LT(bufsize_deferred_v3[step], TotalDataSize + MaxExtra); + EXPECT_LT(bufsize_deferred_endstep[step], TotalDataSize + MaxExtra); + + EXPECT_LT(bufsize_deferred_pp_beginstep[step], + TotalDataSize + MaxExtra); + EXPECT_LT(bufsize_deferred_pp_v1[step], TotalDataSize + MaxExtra); + EXPECT_LT(bufsize_deferred_pp_v2[step], TotalDataSize + MaxExtra); + EXPECT_LT(bufsize_deferred_pp_v3[step], TotalDataSize + MaxExtra); + EXPECT_LT(bufsize_deferred_pp_endstep[step], + TotalDataSize + MaxExtra); + } + } +} + +//****************************************************************************** +// main +//****************************************************************************** + +int main(int argc, char **argv) +{ +#if ADIOS2_USE_MPI + MPI_Init(nullptr, nullptr); +#endif + + int result; + ::testing::InitGoogleTest(&argc, argv); + + if (argc > 1) + { + engineName = std::string(argv[1]); + } + result = RUN_ALL_TESTS(); + +#if ADIOS2_USE_MPI + MPI_Finalize(); +#endif + + return result; +}