Skip to content

Commit

Permalink
Added support for Joined Arrays in the BP4 format and engine.
Browse files Browse the repository at this point in the history
Declaration:          auto var = outIO.DefineVariable<double>(table", {adios2::JoinedDim, Ncols}, {}, {1, Ncols});
Setting block size:   var.SetSelection({{}, {Nrows[block], Ncols}});
  • Loading branch information
pnorbert committed Feb 3, 2023
1 parent 119279c commit 2718050
Show file tree
Hide file tree
Showing 11 changed files with 492 additions and 71 deletions.
8 changes: 6 additions & 2 deletions examples/basics/joinedArray/joinedArray_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main(int argc, char *argv[])
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &nproc);
#endif
const int NSTEPS = 5;
const int NSTEPS = 3;

// generate different random numbers on each process,
// but always the same sequence at each run
Expand All @@ -73,6 +73,7 @@ int main(int argc, char *argv[])
// Get io settings from the config file or
// create one with default settings here
adios2::IO io = adios.DeclareIO("Output");
io.SetEngine("BP4");

/*
* Define joinable local array: type, name, global and local size
Expand All @@ -82,6 +83,9 @@ int main(int argc, char *argv[])
adios2::Variable<double> varTable = io.DefineVariable<double>(
"table", {adios2::JoinedDim, Ncols}, {}, {Nrows, Ncols});

// adios2::Operator op = adios.DefineOperator("blosc", "blosc");
// varTable.AddOperation(op, {{"clevel", std::to_string(1)}});

// Open file. "w" means we overwrite any existing file on disk,
// but Advance() will append steps to the same file.
adios2::Engine writer = io.Open("joinedArray.bp", adios2::Mode::Write);
Expand All @@ -95,7 +99,7 @@ int main(int argc, char *argv[])
for (unsigned int col = 0; col < Ncols; col++)
{
mytable[row * Ncols + col] = static_cast<double>(
rank * 1.0 + row * 0.1 + col * 0.01);
step * 10.0 + rank * 1.0 + row * 0.1 + col * 0.01);
}
}

Expand Down
2 changes: 2 additions & 0 deletions source/adios2/core/VariableBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class VariableBase
size_t m_StepsStart = 0;
size_t m_StepsCount = 1;

size_t m_JoinedDimPos = 0; // the joined dimension in a JoinedArray

/** Index Metadata Position in a serial metadata buffer */
size_t m_IndexStart = 0;

Expand Down
3 changes: 2 additions & 1 deletion source/adios2/toolkit/format/bp/BPBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ BPBase::TransformTypeEnum(const std::string transformType) const noexcept
template BPBase::Characteristics<T> \
BPBase::ReadElementIndexCharacteristics(const std::vector<char> &, \
size_t &, const BPBase::DataTypes, \
const bool, const bool) const;
size_t &, const bool, const bool) \
const;

ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
Expand Down
2 changes: 2 additions & 0 deletions source/adios2/toolkit/format/bp/BPBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ class BPBase
Characteristics<T>
ReadElementIndexCharacteristics(const std::vector<char> &buffer,
size_t &position, const DataTypes dataType,
size_t &joinedArrayShapePos,
const bool untilTimeStep = false,
const bool isLittleEndian = true) const;

Expand All @@ -644,6 +645,7 @@ class BPBase
const DataTypes dataType,
const bool untilTimeStep,
Characteristics<T> &characteristics,
size_t &joinedArrayShapePos,
const bool isLittleEndian = true) const;
};

Expand Down
42 changes: 32 additions & 10 deletions source/adios2/toolkit/format/bp/BPBase.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace format
template <class T>
BPBase::Characteristics<T> BPBase::ReadElementIndexCharacteristics(
const std::vector<char> &buffer, size_t &position, const DataTypes dataType,
const bool untilTimeStep, const bool isLittleEndian) const
size_t &joinedArrayShapePos, const bool untilTimeStep,
const bool isLittleEndian) const
{
Characteristics<T> characteristics;
characteristics.EntryCount =
Expand All @@ -34,21 +35,21 @@ BPBase::Characteristics<T> BPBase::ReadElementIndexCharacteristics(
helper::ReadValue<uint32_t>(buffer, position, isLittleEndian);

ParseCharacteristics(buffer, position, dataType, untilTimeStep,
characteristics, isLittleEndian);
characteristics, joinedArrayShapePos, isLittleEndian);

return characteristics;
}

// String specialization
template <>
inline void
BPBase::ParseCharacteristics(const std::vector<char> &buffer, size_t &position,
const DataTypes dataType, const bool untilTimeStep,
Characteristics<std::string> &characteristics,
const bool isLittleEndian) const
inline void BPBase::ParseCharacteristics(
const std::vector<char> &buffer, size_t &position, const DataTypes dataType,
const bool untilTimeStep, Characteristics<std::string> &characteristics,
size_t &joinedArrayShapePos, const bool isLittleEndian) const
{
const size_t start = position;
size_t localPosition = 0;
joinedArrayShapePos = 0; // irrelevant here

bool foundTimeStep = false;

Expand Down Expand Up @@ -195,12 +196,14 @@ inline void BPBase::ParseCharacteristics(const std::vector<char> &buffer,
const DataTypes /*dataType*/,
const bool untilTimeStep,
Characteristics<T> &characteristics,
size_t &joinedArrayShapePos,
const bool isLittleEndian) const
{
const size_t start = position;
size_t localPosition = 0;

bool foundTimeStep = false;
bool foundJoinedDim = false;
size_t dimensionsSize = 0; // get it from dimensions characteristics

while (localPosition < characteristics.EntryLength)
Expand Down Expand Up @@ -356,9 +359,25 @@ inline void BPBase::ParseCharacteristics(const std::vector<char> &buffer,
static_cast<size_t>(helper::ReadValue<uint64_t>(
buffer, position, isLittleEndian)));

characteristics.Shape.push_back(
uint64_t shape =
static_cast<size_t>(helper::ReadValue<uint64_t>(
buffer, position, isLittleEndian)));
buffer, position, isLittleEndian));
characteristics.Shape.push_back(shape);

if (shape == JoinedDim)
{
if (foundJoinedDim)
{
helper::Throw<std::invalid_argument>(
"Toolkit", "format::bp::BPBase",
"ParseCharacteristics",
"Invalid Joined Array definition with multiple "
"JoinedDim in Shape.");
}
foundJoinedDim = true;
// this is the Joined Array Start value that must be updated
joinedArrayShapePos = position;
}

characteristics.Start.push_back(
static_cast<size_t>(helper::ReadValue<uint64_t>(
Expand Down Expand Up @@ -395,9 +414,12 @@ inline void BPBase::ParseCharacteristics(const std::vector<char> &buffer,
characteristics.Count.clear();
characteristics.EntryShapeID = ShapeID::GlobalValue;
}
else if (foundJoinedDim)
{
characteristics.EntryShapeID = ShapeID::JoinedArray;
}
else
{
// TODO joined dimension
characteristics.EntryShapeID = ShapeID::GlobalArray;
}

Expand Down
38 changes: 32 additions & 6 deletions source/adios2/toolkit/format/bp/BPSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,25 @@ void BPSerializer::PutDimensionsRecord(const Dims &localDimensions,
const Dims &offsets,
std::vector<char> &buffer) noexcept
{
if (offsets.empty())
{
if (offsets.empty() && globalDimensions.empty())
{ // local array
for (const auto localDimension : localDimensions)
{
helper::InsertU64(buffer, localDimension);
buffer.insert(buffer.end(), 2 * sizeof(uint64_t), '\0');
}
}
else if (offsets.empty())
{ // joined array has no offsets but has global dims
for (unsigned int d = 0; d < localDimensions.size(); ++d)
{
helper::InsertU64(buffer, localDimensions[d]);
helper::InsertU64(buffer, globalDimensions[d]);
buffer.insert(buffer.end(), sizeof(uint64_t), '\0');
}
}
else
{
{ // global array
for (unsigned int d = 0; d < localDimensions.size(); ++d)
{
helper::InsertU64(buffer, localDimensions[d]);
Expand Down Expand Up @@ -191,7 +200,7 @@ void BPSerializer::PutDimensionsRecord(const Dims &localDimensions,
};

// BODY Starts here
if (offsets.empty())
if (offsets.empty() && globalDimensions.empty())
{
unsigned int globalBoundsSkip = 18;
if (isCharacteristic)
Expand All @@ -206,6 +215,19 @@ void BPSerializer::PutDimensionsRecord(const Dims &localDimensions,
position += globalBoundsSkip;
}
}
else if (offsets.empty())
{
// joined array has no offsets but has global dims
size_t zeroOffset = 0;
for (unsigned int d = 0; d < localDimensions.size(); ++d)
{
lf_CopyDimension(buffer, position, localDimensions[d],
isCharacteristic);
lf_CopyDimension(buffer, position, globalDimensions[d],
isCharacteristic);
lf_CopyDimension(buffer, position, zeroOffset, isCharacteristic);
}
}
else
{
for (unsigned int d = 0; d < localDimensions.size(); ++d)
Expand Down Expand Up @@ -376,8 +398,10 @@ void BPSerializer::MergeSerializeIndices(
#define make_case(T) \
case (TypeTraits<T>::type_enum): \
{ \
size_t irrelevant; \
const auto characteristics = ReadElementIndexCharacteristics<T>( \
buffer, position, TypeTraits<T>::type_enum, true, isLittleEndian); \
buffer, position, TypeTraits<T>::type_enum, irrelevant, true, \
isLittleEndian); \
count = characteristics.EntryCount; \
length = characteristics.EntryLength; \
timeStep = characteristics.Statistics.Step; \
Expand All @@ -388,9 +412,11 @@ void BPSerializer::MergeSerializeIndices(

case (type_string_array):
{
size_t irrelevant;
const auto characteristics =
ReadElementIndexCharacteristics<std::string>(
buffer, position, type_string_array, true, isLittleEndian);
buffer, position, type_string_array, irrelevant, true,
isLittleEndian);
count = characteristics.EntryCount;
length = characteristics.EntryLength;
timeStep = characteristics.Statistics.Step;
Expand Down
Loading

0 comments on commit 2718050

Please sign in to comment.