Skip to content

Commit

Permalink
MinInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
eisenhauer committed Jan 21, 2021
1 parent f986814 commit a496130
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 39 deletions.
60 changes: 60 additions & 0 deletions bindings/CXX11/adios2/cxx11/Engine.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,58 @@ ToBlocksInfo(const std::vector<typename core::Variable<

return blocksInfo;
}
template <class T>
static std::vector<typename Variable<T>::Info>
ToBlocksInfo(const core::Engine::MinVarInfo *coreVarInfo)
{
using IOType = typename TypeInfo<T>::IOType;

auto coreBlocksInfo = coreVarInfo->BlocksInfo;

std::vector<typename Variable<T>::Info> blocksInfo;
blocksInfo.reserve(coreBlocksInfo.size());

for (auto &coreBlockInfo : coreBlocksInfo)
{
typename Variable<T>::Info blockInfo;

if (coreVarInfo->Shape)
{
blockInfo.Start.reserve(coreVarInfo->Dims);
blockInfo.Count.reserve(coreVarInfo->Dims);
for (int i = 0; i < coreVarInfo->Dims; i++)
{
blockInfo.Start.push_back(coreBlockInfo.Start[i]);
blockInfo.Count.push_back(coreBlockInfo.Count[i]);
}
}
else
{
blockInfo.Count.reserve(coreVarInfo->Dims);
for (int i = 0; i < coreVarInfo->Dims; i++)
{
blockInfo.Count.push_back(coreBlockInfo.Count[i]);
}
}
blockInfo.WriterID = coreBlockInfo.WriterID;

blockInfo.IsValue = coreVarInfo->IsValue;
blockInfo.IsReverseDims = coreVarInfo->IsReverseDims;
if (blockInfo.IsValue)
{
blockInfo.Value = *((T *)coreBlockInfo.BufferP);
}
else
{
blockInfo.Min = *((T *)&coreBlockInfo.MinUnion);
blockInfo.Max = *((T *)&coreBlockInfo.MaxUnion);
}
blockInfo.BlockID = coreBlockInfo.BlockID;
blocksInfo.push_back(blockInfo);
}

return blocksInfo;
}
} // end empty namespace

template <class T>
Expand Down Expand Up @@ -333,6 +385,14 @@ Engine::BlocksInfo(const Variable<T> variable, const size_t step) const
adios2::helper::CheckForNullptr(
variable.m_Variable, "for variable in call to Engine::BlocksInfo");

const auto minBlocksInfo =
m_Engine->MinBlocksInfo(*variable.m_Variable, step);

if (minBlocksInfo)
{
return ToBlocksInfo<T>(minBlocksInfo);
}

const auto blocksInfo =
m_Engine->BlocksInfo<IOType>(*variable.m_Variable, step);
return ToBlocksInfo<T>(blocksInfo);
Expand Down
45 changes: 45 additions & 0 deletions source/adios2/core/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,51 @@ class Engine
/* for adios2 internal testing */
virtual size_t DebugGetDataBufferSize() const;

union PrimitiveStdtypeUnion
{
int8_t int8;
int16_t int16;
int32_t int32;
int64_t int64;
uint8_t uint8;
uint16_t uint16;
uint32_t uint32;
uint64_t uint64;
float f;
double d;
long double ld;
};

struct MinBlockInfo
{
int WriterID = 0;
size_t BlockID = 0;
size_t *Start;
size_t *Count;
union PrimitiveStdtypeUnion MinUnion;
union PrimitiveStdtypeUnion MaxUnion;
void *BufferP = NULL;
};
struct MinVarInfo
{
int Dims;
size_t *Shape;
bool IsValue = false;
bool IsReverseDims = false;
std::vector<struct MinBlockInfo> BlocksInfo;
MinVarInfo(int D, size_t *S)
: Dims(D), Shape(S), IsValue(false), IsReverseDims(false),
BlocksInfo({})
{
}
};

virtual MinVarInfo *MinBlocksInfo(const VariableBase &,
const size_t Step) const
{
return nullptr;
}

protected:
/** from ADIOS class passed to Engine created with Open
* if no communicator is passed */
Expand Down
2 changes: 2 additions & 0 deletions source/adios2/core/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class Variable : public VariableBase
DoAllStepsBlocksInfo() const;

void CheckRandomAccess(const size_t step, const std::string hint) const;

size_t WriterIndex;
};

} // end namespace core
Expand Down
175 changes: 139 additions & 36 deletions source/adios2/engine/sst/SstReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,42 +120,42 @@ SstReader::SstReader(IO &io, const std::string &name, const Mode mode,
return;
};

auto arrayFFSCallback = [](void *reader, const char *variableName,
const int type, int DimCount, size_t *Shape,
size_t *Start, size_t *Count) {
std::vector<size_t> VecShape;
std::vector<size_t> VecStart;
std::vector<size_t> VecCount;
adios2::DataType Type = (adios2::DataType)type;
class SstReader::SstReader *Reader =
reinterpret_cast<class SstReader::SstReader *>(reader);
/*
* setup shape of array variable as global (I.E. Count == Shape,
* Start == 0)
*/
if (Shape)
{
for (int i = 0; i < DimCount; i++)
auto arrayFFSCallback =
[](void *reader, const char *variableName, const int type, int DimCount,
size_t *Shape, size_t *Start, size_t *Count, void **MinVarInfoP) {
std::vector<size_t> VecShape;
std::vector<size_t> VecStart;
std::vector<size_t> VecCount;
adios2::DataType Type = (adios2::DataType)type;
class SstReader::SstReader *Reader =
reinterpret_cast<class SstReader::SstReader *>(reader);
/*
* setup shape of array variable as global (I.E. Count == Shape,
* Start == 0)
*/
if (Shape)
{
VecShape.push_back(Shape[i]);
VecStart.push_back(0);
VecCount.push_back(Shape[i]);
for (int i = 0; i < DimCount; i++)
{
VecShape.push_back(Shape[i]);
VecStart.push_back(0);
VecCount.push_back(Shape[i]);
}
}
}
else
{
VecShape = {};
VecStart = {};
for (int i = 0; i < DimCount; i++)
else
{
VecCount.push_back(Count[i]);
VecShape = {};
VecStart = {};
for (int i = 0; i < DimCount; i++)
{
VecCount.push_back(Count[i]);
}
}
}

if (Type == adios2::DataType::Compound)
{
return (void *)NULL;
}
if (Type == adios2::DataType::Compound)
{
return (void *)NULL;
}
#define declare_type(T) \
else if (Type == helper::GetDataType<T>()) \
{ \
Expand All @@ -164,10 +164,10 @@ SstReader::SstReader(IO &io, const std::string &name, const Mode mode,
variable->m_AvailableStepsCount = 1; \
return (void *)variable; \
}
ADIOS2_FOREACH_STDTYPE_1ARG(declare_type)
ADIOS2_FOREACH_STDTYPE_1ARG(declare_type)
#undef declare_type
return (void *)NULL;
};
return (void *)NULL;
};

auto arrayBlocksInfoCallback =
[](void *reader, void *variable, const int type, int WriterRank,
Expand All @@ -179,6 +179,7 @@ SstReader::SstReader(IO &io, const std::string &name, const Mode mode,
class SstReader::SstReader *Reader =
reinterpret_cast<class SstReader::SstReader *>(reader);
size_t currentStep = SstCurrentStep(Reader->m_Input);
struct MinBlockInfo BI;
/*
* setup shape of array variable as global (I.E. Count == Shape,
* Start == 0)
Expand Down Expand Up @@ -226,8 +227,99 @@ SstReader::SstReader(IO &io, const std::string &name, const Mode mode,
return;
};

SstReaderInitFFSCallback(m_Input, this, varFFSCallback, arrayFFSCallback,
attrFFSCallback, arrayBlocksInfoCallback);
auto arrayMinFFSCallback =
[](void *reader, const char *variableName, const int type, int DimCount,
size_t *Shape, size_t *Start, size_t *Count, void **MinVarInfoP) {
std::vector<size_t> VecShape;
std::vector<size_t> VecStart;
std::vector<size_t> VecCount;
adios2::DataType Type = (adios2::DataType)type;
class SstReader::SstReader *Reader =
reinterpret_cast<class SstReader::SstReader *>(reader);
struct MinVarInfo *MV = new MinVarInfo(DimCount, Shape);
/*
* setup shape of array variable as global (I.E. Count == Shape,
* Start == 0)
*/
if (Shape)
{
for (int i = 0; i < DimCount; i++)
{
VecShape.push_back(Shape[i]);
VecStart.push_back(0);
VecCount.push_back(Shape[i]);
}
}
else
{
VecShape = {};
VecStart = {};
for (int i = 0; i < DimCount; i++)
{
VecCount.push_back(Count[i]);
}
}
if (Type == adios2::DataType::Compound)
{
return (void *)NULL;
}
#define declare_type(T) \
else if (Type == helper::GetDataType<T>()) \
{ \
Variable<T> *variable = &(Reader->m_IO.DefineVariable<T>( \
variableName, VecShape, VecStart, VecCount)); \
variable->m_AvailableStepsCount = 1; \
Reader->m_InfoMap.emplace(variable, MV); \
*MinVarInfoP = (void *)MV; \
return (void *)variable; \
}
ADIOS2_FOREACH_STDTYPE_1ARG(declare_type)
#undef declare_type
return (void *)NULL;
};

auto arrayMinBlocksInfoCallback =
[](void *reader, void *MV, const int type, int WriterRank, int DimCount,
size_t *Shape, size_t *Start, size_t *Count) {
std::vector<size_t> VecShape;
std::vector<size_t> VecStart;
std::vector<size_t> VecCount;
adios2::DataType Type = (adios2::DataType)type;
struct MinBlockInfo MBI;
class SstReader::SstReader *Reader =
reinterpret_cast<class SstReader::SstReader *>(reader);
size_t currentStep = SstCurrentStep(Reader->m_Input);
struct MinVarInfo *MinVar = (struct MinVarInfo *)MV;

MBI.WriterID = WriterRank;
MBI.BlockID = 0;
MBI.Start = Start;
MBI.Count = Count;

MinVar->BlocksInfo.push_back(MBI);
return;
};

static int UseMin = -1;
if (UseMin == -1)
{
if (getenv("MinBlocksInfo") == NULL)
{
UseMin = 0;
}
else
{
UseMin = 1;
}
}
if (UseMin)
SstReaderInitFFSCallback(m_Input, this, varFFSCallback,
arrayMinFFSCallback, attrFFSCallback,
arrayMinBlocksInfoCallback);
else
SstReaderInitFFSCallback(m_Input, this, varFFSCallback,
arrayFFSCallback, attrFFSCallback,
arrayBlocksInfoCallback);

delete[] cstr;
}
Expand Down Expand Up @@ -397,6 +489,7 @@ void SstReader::EndStep()
// unknown marshaling method, shouldn't happen
}
SstReleaseStep(m_Input);
m_InfoMap.clear();
}

void SstReader::Flush(const int transportIndex) {}
Expand Down Expand Up @@ -603,6 +696,16 @@ void SstReader::PerformGets()

void SstReader::DoClose(const int transportIndex) { SstReaderClose(m_Input); }

Engine::MinVarInfo *SstReader::MinBlocksInfo(const VariableBase &Var,
const size_t Step) const
{
auto it = m_InfoMap.find(&Var);
if (it == m_InfoMap.end())
return nullptr;
else
return it->second;
}

#define declare_type(T) \
std::map<size_t, std::vector<typename Variable<T>::BPInfo>> \
SstReader::DoAllStepsBlocksInfo(const Variable<T> &variable) const \
Expand Down
2 changes: 2 additions & 0 deletions source/adios2/engine/sst/SstReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class SstReader : public Engine
void EndStep();
void PerformGets();
void Flush(const int transportIndex = -1) final;
MinVarInfo *MinBlocksInfo(const VariableBase &, const size_t Step) const;

private:
template <class T>
Expand Down Expand Up @@ -76,6 +77,7 @@ class SstReader : public Engine

struct _SstParams Params;

std::unordered_map<const VariableBase *, MinVarInfo *> m_InfoMap;
#define declare_type(T) \
void DoGetSync(Variable<T> &, T *) final; \
void DoGetDeferred(Variable<T> &, T *) final; \
Expand Down
Loading

0 comments on commit a496130

Please sign in to comment.