From 2114f08b50bec8f308c52f4c9a1a5aa28314978c Mon Sep 17 00:00:00 2001 From: William F Godoy Date: Wed, 3 Apr 2019 13:28:10 -0400 Subject: [PATCH] Resolving Put ambiguity Separate Variable::Span Put into two Add single value Put in Span test This doesn't break or changes current functionality, just fixes a broken signature --- bindings/CXX11/cxx11/Engine.cpp | 4 ++- bindings/CXX11/cxx11/Engine.h | 31 ++++++++++++----- bindings/CXX11/cxx11/Engine.tcc | 6 ++++ .../engine/bp/TestBPWriteReadVariableSpan.cpp | 34 ++++++++++++------- 4 files changed, 53 insertions(+), 22 deletions(-) diff --git a/bindings/CXX11/cxx11/Engine.cpp b/bindings/CXX11/cxx11/Engine.cpp index 62884bacaa..220b1ec035 100644 --- a/bindings/CXX11/cxx11/Engine.cpp +++ b/bindings/CXX11/cxx11/Engine.cpp @@ -93,7 +93,9 @@ Engine::Engine(core::Engine *engine) : m_Engine(engine) {} #define declare_template_instantiation(T) \ \ template typename Variable::Span Engine::Put(Variable, const size_t, \ - const T &); + const T &); \ + \ + template typename Variable::Span Engine::Put(Variable); ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation diff --git a/bindings/CXX11/cxx11/Engine.h b/bindings/CXX11/cxx11/Engine.h index cd88e799a8..2044ed095d 100644 --- a/bindings/CXX11/cxx11/Engine.h +++ b/bindings/CXX11/cxx11/Engine.h @@ -91,18 +91,29 @@ class Engine /** * Put signature that provides access to the internal engine buffer for a - * pre-allocated variable. Returns a fixed size Span (based on C++20 - * std::span) so applications can populate data value after this Put. - * Requires a call to PerformPuts, EndStep, or Close to extract the Min/Max - * bounds. + * pre-allocated variable including a fill value. Returns a fixed size Span + * (based on C++20 std::span) so applications can populate data value after + * this Put. Requires a call to PerformPuts, EndStep, or Close to extract + * the Min/Max bounds. * @param variable input variable - * @param bufferID (default = 0) optional, if engine has multiple buffers - * @param value (default is zeros) optional initial value + * @param bufferID if engine has multiple buffers, input 0 when this + * information is not known + * @param value provide an initial fill value * @return span to variable data in engine internal buffer */ template - typename Variable::Span - Put(Variable variable, const size_t bufferID = 0, const T &value = {}); + typename Variable::Span Put(Variable variable, const size_t bufferID, + const T &value); + + /** + * Put signature that provides access to an internal engine buffer (decided + * by the engine) for a pre-allocated variable with the default fill value + * T(). + * @param variable input variable + * @return span to variable data in engine internal buffer + */ + template + typename Variable::Span Put(Variable variable); /** * Put data associated with a Variable in the Engine @@ -388,7 +399,9 @@ class Engine #define declare_template_instantiation(T) \ \ extern template typename Variable::Span Engine::Put( \ - Variable, const size_t, const T &); + Variable, const size_t, const T &); \ + \ + extern template typename Variable::Span Engine::Put(Variable); ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation diff --git a/bindings/CXX11/cxx11/Engine.tcc b/bindings/CXX11/cxx11/Engine.tcc index 2fd8fad55d..ec9b15009f 100644 --- a/bindings/CXX11/cxx11/Engine.tcc +++ b/bindings/CXX11/cxx11/Engine.tcc @@ -76,6 +76,12 @@ typename Variable::Span Engine::Put(Variable variable, return typename Variable::Span(coreSpan); } +template +typename Variable::Span Engine::Put(Variable variable) +{ + return Put(variable, 0, T()); +} + template void Engine::Put(Variable variable, const T *data, const Mode launch) { diff --git a/testing/adios2/engine/bp/TestBPWriteReadVariableSpan.cpp b/testing/adios2/engine/bp/TestBPWriteReadVariableSpan.cpp index 0d9f4e0e92..4314595183 100644 --- a/testing/adios2/engine/bp/TestBPWriteReadVariableSpan.cpp +++ b/testing/adios2/engine/bp/TestBPWriteReadVariableSpan.cpp @@ -61,6 +61,7 @@ TEST_F(BPWriteReadSpan, BPWriteRead1D8) const adios2::Dims start{static_cast(Nx * mpiRank)}; const adios2::Dims count{Nx}; + auto var_Step = io.DefineVariable("step"); auto var_String = io.DefineVariable("iString"); auto var_i8 = io.DefineVariable("i8", shape, start, count, adios2::ConstantDims); @@ -97,6 +98,8 @@ TEST_F(BPWriteReadSpan, BPWriteRead1D8) EXPECT_EQ(bpWriter.CurrentStep(), step); bpWriter.BeginStep(); + + bpWriter.Put(var_Step, step); bpWriter.Put("iString", currentTestData.S1); adios2::Variable::Span i8Span = bpWriter.Put(var_i8); @@ -154,6 +157,7 @@ TEST_F(BPWriteReadSpan, BPWriteRead1D8) adios2::Engine bpReader = io.Open(fname, adios2::Mode::Read); + size_t IStep; std::string IString; std::array I8; std::array I16; @@ -183,6 +187,7 @@ TEST_F(BPWriteReadSpan, BPWriteRead1D8) SmallTestData currentTestData = generateNewSmallTestData( m_TestData, static_cast(currentStep), mpiRank, mpiSize); + auto var_iStep = io.InquireVariable("step"); auto var_iString = io.InquireVariable("iString"); auto var_i8 = io.InquireVariable("i8"); auto var_i16 = io.InquireVariable("i16"); @@ -197,6 +202,9 @@ TEST_F(BPWriteReadSpan, BPWriteRead1D8) auto var_cr32 = io.InquireVariable>("cr32"); auto var_cr64 = io.InquireVariable>("cr64"); + ASSERT_EQ(var_iStep.ShapeID(), adios2::ShapeID::GlobalValue); + ASSERT_EQ(var_iStep.Steps(), NSteps); + ASSERT_EQ(var_i8.ShapeID(), adios2::ShapeID::GlobalArray); ASSERT_EQ(var_i8.Steps(), NSteps); ASSERT_EQ(var_i8.Shape()[0], static_cast(mpiSize * Nx)); @@ -258,6 +266,7 @@ TEST_F(BPWriteReadSpan, BPWriteRead1D8) var_cr32.SetSelection(sel); var_cr64.SetSelection(sel); + bpReader.Get(var_iStep, IStep); bpReader.Get(var_iString, IString); bpReader.Get(var_i8, I8.data()); bpReader.Get(var_i16, I16.data()); @@ -274,6 +283,7 @@ TEST_F(BPWriteReadSpan, BPWriteRead1D8) bpReader.EndStep(); + EXPECT_EQ(IStep, currentStep); EXPECT_EQ(IString, currentTestData.S1); for (size_t i = 0; i < Nx; ++i) @@ -1246,35 +1256,35 @@ TEST_F(BPWriteReadSpan, BPWriteRead1D8FillValue) bpWriter.Put("iString", std::to_string(step)); adios2::Variable::Span i8Span = - bpWriter.Put(var_i8, NULL, static_cast(step)); + bpWriter.Put(var_i8, 0, static_cast(step)); adios2::Variable::Span i16Span = - bpWriter.Put(var_i16, NULL, static_cast(step)); + bpWriter.Put(var_i16, 0, static_cast(step)); adios2::Variable::Span i32Span = - bpWriter.Put(var_i32, NULL, static_cast(step)); + bpWriter.Put(var_i32, 0, static_cast(step)); adios2::Variable::Span i64Span = - bpWriter.Put(var_i64, NULL, static_cast(step)); + bpWriter.Put(var_i64, 0, static_cast(step)); adios2::Variable::Span u8Span = - bpWriter.Put(var_u8, NULL, static_cast(step)); + bpWriter.Put(var_u8, 0, static_cast(step)); adios2::Variable::Span u16Span = - bpWriter.Put(var_u16, NULL, static_cast(step)); + bpWriter.Put(var_u16, 0, static_cast(step)); adios2::Variable::Span u32Span = - bpWriter.Put(var_u32, NULL, static_cast(step)); + bpWriter.Put(var_u32, 0, static_cast(step)); adios2::Variable::Span u64Span = - bpWriter.Put(var_u64, NULL, static_cast(step)); + bpWriter.Put(var_u64, 0, static_cast(step)); adios2::Variable::Span r32Span = - bpWriter.Put(var_r32, NULL, static_cast(step)); + bpWriter.Put(var_r32, 0, static_cast(step)); adios2::Variable::Span r64Span = - bpWriter.Put(var_r64, NULL, static_cast(step)); + bpWriter.Put(var_r64, 0, static_cast(step)); adios2::Variable>::Span cr32Span = bpWriter.Put( - var_cr32, NULL, + var_cr32, 0, {static_cast(step), static_cast(step)}); adios2::Variable>::Span cr64Span = bpWriter.Put( - var_cr64, NULL, + var_cr64, 0, {static_cast(step), static_cast(step)}); bpWriter.EndStep();