Skip to content

Commit

Permalink
Merge pull request #1353 from williamfgc/put_ambiguous
Browse files Browse the repository at this point in the history
Resolving Put ambiguity
  • Loading branch information
williamfgc authored Apr 3, 2019
2 parents e306c38 + 2114f08 commit da67b81
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 22 deletions.
4 changes: 3 additions & 1 deletion bindings/CXX11/cxx11/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ Engine::Engine(core::Engine *engine) : m_Engine(engine) {}
#define declare_template_instantiation(T) \
\
template typename Variable<T>::Span Engine::Put(Variable<T>, const size_t, \
const T &);
const T &); \
\
template typename Variable<T>::Span Engine::Put(Variable<T>);

ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
Expand Down
31 changes: 22 additions & 9 deletions bindings/CXX11/cxx11/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T>
typename Variable<T>::Span
Put(Variable<T> variable, const size_t bufferID = 0, const T &value = {});
typename Variable<T>::Span Put(Variable<T> 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 <class T>
typename Variable<T>::Span Put(Variable<T> variable);

/**
* Put data associated with a Variable in the Engine
Expand Down Expand Up @@ -388,7 +399,9 @@ class Engine
#define declare_template_instantiation(T) \
\
extern template typename Variable<T>::Span Engine::Put( \
Variable<T>, const size_t, const T &);
Variable<T>, const size_t, const T &); \
\
extern template typename Variable<T>::Span Engine::Put(Variable<T>);

ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
Expand Down
6 changes: 6 additions & 0 deletions bindings/CXX11/cxx11/Engine.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ typename Variable<T>::Span Engine::Put(Variable<T> variable,
return typename Variable<T>::Span(coreSpan);
}

template <class T>
typename Variable<T>::Span Engine::Put(Variable<T> variable)
{
return Put(variable, 0, T());
}

template <class T>
void Engine::Put(Variable<T> variable, const T *data, const Mode launch)
{
Expand Down
34 changes: 22 additions & 12 deletions testing/adios2/engine/bp/TestBPWriteReadVariableSpan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ TEST_F(BPWriteReadSpan, BPWriteRead1D8)
const adios2::Dims start{static_cast<size_t>(Nx * mpiRank)};
const adios2::Dims count{Nx};

auto var_Step = io.DefineVariable<size_t>("step");
auto var_String = io.DefineVariable<std::string>("iString");
auto var_i8 = io.DefineVariable<int8_t>("i8", shape, start, count,
adios2::ConstantDims);
Expand Down Expand Up @@ -97,6 +98,8 @@ TEST_F(BPWriteReadSpan, BPWriteRead1D8)
EXPECT_EQ(bpWriter.CurrentStep(), step);

bpWriter.BeginStep();

bpWriter.Put(var_Step, step);
bpWriter.Put<std::string>("iString", currentTestData.S1);

adios2::Variable<int8_t>::Span i8Span = bpWriter.Put(var_i8);
Expand Down Expand Up @@ -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<int8_t, Nx> I8;
std::array<int16_t, Nx> I16;
Expand Down Expand Up @@ -183,6 +187,7 @@ TEST_F(BPWriteReadSpan, BPWriteRead1D8)
SmallTestData currentTestData = generateNewSmallTestData(
m_TestData, static_cast<int>(currentStep), mpiRank, mpiSize);

auto var_iStep = io.InquireVariable<size_t>("step");
auto var_iString = io.InquireVariable<std::string>("iString");
auto var_i8 = io.InquireVariable<int8_t>("i8");
auto var_i16 = io.InquireVariable<int16_t>("i16");
Expand All @@ -197,6 +202,9 @@ TEST_F(BPWriteReadSpan, BPWriteRead1D8)
auto var_cr32 = io.InquireVariable<std::complex<float>>("cr32");
auto var_cr64 = io.InquireVariable<std::complex<double>>("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<size_t>(mpiSize * Nx));
Expand Down Expand Up @@ -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());
Expand All @@ -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)
Expand Down Expand Up @@ -1246,35 +1256,35 @@ TEST_F(BPWriteReadSpan, BPWriteRead1D8FillValue)
bpWriter.Put<std::string>("iString", std::to_string(step));

adios2::Variable<int8_t>::Span i8Span =
bpWriter.Put(var_i8, NULL, static_cast<int8_t>(step));
bpWriter.Put(var_i8, 0, static_cast<int8_t>(step));
adios2::Variable<int16_t>::Span i16Span =
bpWriter.Put(var_i16, NULL, static_cast<int16_t>(step));
bpWriter.Put(var_i16, 0, static_cast<int16_t>(step));
adios2::Variable<int32_t>::Span i32Span =
bpWriter.Put(var_i32, NULL, static_cast<int32_t>(step));
bpWriter.Put(var_i32, 0, static_cast<int32_t>(step));
adios2::Variable<int64_t>::Span i64Span =
bpWriter.Put(var_i64, NULL, static_cast<int64_t>(step));
bpWriter.Put(var_i64, 0, static_cast<int64_t>(step));

adios2::Variable<uint8_t>::Span u8Span =
bpWriter.Put(var_u8, NULL, static_cast<uint8_t>(step));
bpWriter.Put(var_u8, 0, static_cast<uint8_t>(step));
adios2::Variable<uint16_t>::Span u16Span =
bpWriter.Put(var_u16, NULL, static_cast<uint16_t>(step));
bpWriter.Put(var_u16, 0, static_cast<uint16_t>(step));
adios2::Variable<uint32_t>::Span u32Span =
bpWriter.Put(var_u32, NULL, static_cast<uint32_t>(step));
bpWriter.Put(var_u32, 0, static_cast<uint32_t>(step));
adios2::Variable<uint64_t>::Span u64Span =
bpWriter.Put(var_u64, NULL, static_cast<uint64_t>(step));
bpWriter.Put(var_u64, 0, static_cast<uint64_t>(step));

adios2::Variable<float>::Span r32Span =
bpWriter.Put(var_r32, NULL, static_cast<float>(step));
bpWriter.Put(var_r32, 0, static_cast<float>(step));

adios2::Variable<double>::Span r64Span =
bpWriter.Put(var_r64, NULL, static_cast<double>(step));
bpWriter.Put(var_r64, 0, static_cast<double>(step));

adios2::Variable<std::complex<float>>::Span cr32Span = bpWriter.Put(
var_cr32, NULL,
var_cr32, 0,
{static_cast<float>(step), static_cast<float>(step)});
adios2::Variable<std::complex<double>>::Span cr64Span =
bpWriter.Put(
var_cr64, NULL,
var_cr64, 0,
{static_cast<double>(step), static_cast<double>(step)});

bpWriter.EndStep();
Expand Down

0 comments on commit da67b81

Please sign in to comment.