Skip to content

Commit

Permalink
Merge pull request #3027 from eisenhauer/BP5MultiBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
eisenhauer authored Jan 31, 2022
2 parents a382cc0 + dc76630 commit 7194de9
Show file tree
Hide file tree
Showing 23 changed files with 521 additions and 302 deletions.
53 changes: 44 additions & 9 deletions bindings/C/adios2/c/adios2_c_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,31 +685,66 @@ adios2_varinfo *adios2_inquire_blockinfo(adios2_engine *engine,
{
varinfo = (adios2_varinfo *)malloc(sizeof(adios2_varinfo));
varinfo->nblocks = minBlocksInfo->BlocksInfo.size();
varinfo->Shape = NULL;
varinfo->BlocksInfo = (adios2_blockinfo *)malloc(
varinfo->nblocks * sizeof(adios2_blockinfo));
auto *b = varinfo->BlocksInfo;

varinfo->Dims = minBlocksInfo->Dims;
varinfo->Shape = minBlocksInfo->Shape;
if (minBlocksInfo->WasLocalVar)
{
varinfo->Shape = (size_t *)malloc(sizeof(size_t));
varinfo->Shape[0] = (intptr_t)minBlocksInfo->Shape;
}
else
{
if (minBlocksInfo->Shape)
{
varinfo->Shape =
(size_t *)malloc(sizeof(size_t) * minBlocksInfo->Dims);
memcpy(varinfo->Shape, minBlocksInfo->Shape,
sizeof(size_t) * minBlocksInfo->Dims);
}
}
varinfo->IsValue = (int)minBlocksInfo->IsValue;
varinfo->IsReverseDims = (int)minBlocksInfo->IsReverseDims;
for (size_t i = 0; i < varinfo->nblocks; ++i)
{
b[i].WriterID = minBlocksInfo->BlocksInfo[i].WriterID;
b[i].BlockID = minBlocksInfo->BlocksInfo[i].BlockID;
b[i].Start = minBlocksInfo->BlocksInfo[i].Start;
b[i].Count = minBlocksInfo->BlocksInfo[i].Count;
if (minBlocksInfo->WasLocalVar)
{
b[i].Start = (size_t *)malloc(sizeof(size_t));
b[i].Start[0] =
(intptr_t)minBlocksInfo->BlocksInfo[i].Start;
b[i].Count = (size_t *)malloc(sizeof(size_t));
b[i].Count[0] =
(intptr_t)minBlocksInfo->BlocksInfo[i].Count;
}
else
{
b[i].Start =
(size_t *)malloc(sizeof(size_t) * minBlocksInfo->Dims);
memcpy(b[i].Start, minBlocksInfo->BlocksInfo[i].Start,
sizeof(size_t) * minBlocksInfo->Dims);
b[i].Count =
(size_t *)malloc(sizeof(size_t) * minBlocksInfo->Dims);
memcpy(b[i].Count, minBlocksInfo->BlocksInfo[i].Count,
sizeof(size_t) * minBlocksInfo->Dims);
}
if (minBlocksInfo->IsValue)
{
b[i].Value.uint64 = 0;
// = *((T *)minBlocksInfo->BlocksInfo[i].BufferP);
memcpy(&b[i].Value, minBlocksInfo->BlocksInfo[i].BufferP,
sizeof(b[i].Value));
}
else
{
b[i].MinUnion.uint64 = 0;
// = minBlocksInfo->BlocksInfo[i].MinUnion;
b[i].MaxUnion.uint64 = 0;
// = minBlocksInfo->BlocksInfo[i].MaxUnion;
memcpy(&b[i].MinUnion,
&minBlocksInfo->BlocksInfo[i].MinMax.MinUnion,
sizeof(b[i].MinUnion));
memcpy(&b[i].MaxUnion,
&minBlocksInfo->BlocksInfo[i].MinMax.MaxUnion,
sizeof(b[i].MaxUnion));
}
}
delete minBlocksInfo;
Expand Down
1 change: 1 addition & 0 deletions bindings/CXX11/adios2/cxx11/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Engine.tcc"

#include "adios2/core/Engine.h"

#include "adios2/helper/adiosFunctions.h"

namespace adios2
Expand Down
1 change: 1 addition & 0 deletions bindings/CXX11/adios2/cxx11/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Query; // friend
namespace core
{
class Engine; // private implementation

}
/// \endcond

Expand Down
61 changes: 10 additions & 51 deletions bindings/CXX11/adios2/cxx11/Engine.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -59,56 +59,6 @@ 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)
{
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.MinMax.MinUnion;
blockInfo.Max = *(T *)&coreBlockInfo.MinMax.MaxUnion;
}
blockInfo.BlockID = coreBlockInfo.BlockID;
blocksInfo.push_back(blockInfo);
}

return blocksInfo;
}
} // end empty namespace

template <class T>
Expand Down Expand Up @@ -358,6 +308,15 @@ Engine::AllStepsBlocksInfo(const Variable<T> variable) const
variable.m_Variable,
"for variable in call to Engine::AllStepsBlocksInfo");

try
{
auto Info = variable.AllStepsBlocksInfoMap();
return Info;
}
catch (...)
{
}

const std::map<size_t, std::vector<typename core::Variable<IOType>::BPInfo>>
coreAllStepsBlockInfo =
m_Engine->AllStepsBlocksInfo(*variable.m_Variable);
Expand Down Expand Up @@ -403,7 +362,7 @@ Engine::BlocksInfo(const Variable<T> variable, const size_t step) const
if (minBlocksInfo)
{
std::vector<typename Variable<T>::Info> Ret =
ToBlocksInfo<T>(minBlocksInfo);
variable.ToBlocksInfoMin(minBlocksInfo);
delete minBlocksInfo;
return Ret;
}
Expand Down
7 changes: 7 additions & 0 deletions bindings/CXX11/adios2/cxx11/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ namespace adios2
} \
\
template <> \
std::map<size_t, std::vector<typename Variable<T>::Info>> \
Variable<T>::AllStepsBlocksInfoMap() const \
{ \
return DoAllStepsBlocksInfoMap(); \
} \
\
template <> \
const T *Variable<T>::Info::Data() const \
{ \
const core::Variable<T>::BPInfo *coreInfo = \
Expand Down
12 changes: 12 additions & 0 deletions bindings/CXX11/adios2/cxx11/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Group; // friend
namespace core
{

class VariableBase;

template <class T>
class Variable; // private implementation

Expand Down Expand Up @@ -376,13 +378,23 @@ class Variable
*/
std::vector<std::vector<typename Variable<T>::Info>> AllStepsBlocksInfo();

/**
*/
std::map<size_t, std::vector<typename Variable<T>::Info>>
AllStepsBlocksInfoMap() const;

std::vector<typename Variable<T>::Info>
ToBlocksInfoMin(const MinVarInfo *coreVarInfo) const;

using Span = adios2::detail::Span<T>;

private:
Variable<T>(core::Variable<IOType> *variable);
core::Variable<IOType> *m_Variable = nullptr;

std::vector<std::vector<typename Variable<T>::Info>> DoAllStepsBlocksInfo();
std::map<size_t, std::vector<typename Variable<T>::Info>>
DoAllStepsBlocksInfoMap() const;
};

template <typename T>
Expand Down
135 changes: 134 additions & 1 deletion bindings/CXX11/adios2/cxx11/Variable.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#ifndef ADIOS2_BINDINGS_CXX11_CXX11_VARIABLE_TCC_
#define ADIOS2_BINDINGS_CXX11_CXX11_VARIABLE_TCC_

#include "Engine.h"
#include "Variable.h"

#include "adios2/core/Engine.h"
#include "adios2/helper/adiosFunctions.h"

namespace adios2
Expand Down Expand Up @@ -61,13 +62,75 @@ ToBlocksInfo(const std::vector<typename core::Variable<
}
} // end empty namespace

template <class T>
std::map<size_t, std::vector<typename Variable<T>::Info>>
Variable<T>::DoAllStepsBlocksInfoMap() const
{
MinVarInfo *minBlocksInfo = nullptr;
minBlocksInfo = m_Variable->m_Engine->MinBlocksInfo(*m_Variable, 0);
if (!minBlocksInfo)
throw std::logic_error("no implemented");
std::map<size_t, std::vector<typename Variable<T>::Info>>
allStepsBlocksInfo;

size_t gotCount = 1;
size_t curStep = 1;
allStepsBlocksInfo.insert({0, ToBlocksInfoMin(minBlocksInfo)});
delete (minBlocksInfo);
while (gotCount < m_Variable->m_AvailableStepsCount)
{
minBlocksInfo =
m_Variable->m_Engine->MinBlocksInfo(*m_Variable, curStep);
if (minBlocksInfo)
{
allStepsBlocksInfo.insert(
{curStep, ToBlocksInfoMin(minBlocksInfo)});
delete (minBlocksInfo);
gotCount++;
}
curStep++;
}
return allStepsBlocksInfo;
}

template <class T>
std::vector<std::vector<typename Variable<T>::Info>>
Variable<T>::DoAllStepsBlocksInfo()
{
helper::CheckForNullptr(m_Variable,
"in call to Variable<T>::AllStepsBlocksInfo");

MinVarInfo *minBlocksInfo = nullptr;
if (m_Variable->m_Engine)
{
minBlocksInfo = m_Variable->m_Engine->MinBlocksInfo(
*m_Variable, m_Variable->m_AvailableStepsStart);
if (minBlocksInfo)
{
std::vector<std::vector<typename Variable<T>::Info>>
allStepsBlocksInfo;
// PUBLIC OUTPUT
size_t gotCount = 1;
size_t curStep = m_Variable->m_AvailableStepsStart + 1;
allStepsBlocksInfo.push_back(ToBlocksInfoMin(minBlocksInfo));
delete (minBlocksInfo);
while (gotCount < m_Variable->m_AvailableStepsCount)
{
minBlocksInfo =
m_Variable->m_Engine->MinBlocksInfo(*m_Variable, curStep);
if (minBlocksInfo)
{
allStepsBlocksInfo.push_back(
ToBlocksInfoMin(minBlocksInfo));
delete (minBlocksInfo);
gotCount++;
}
curStep++;
}
return allStepsBlocksInfo;
}
}

// PRIVATE INPUT
const std::vector<std::vector<typename core::Variable<IOType>::BPInfo>>
coreAllStepsBlocksInfo = m_Variable->AllStepsBlocksInfo();
Expand All @@ -85,6 +148,76 @@ Variable<T>::DoAllStepsBlocksInfo()
return allStepsBlocksInfo;
}

template <typename T>
std::vector<typename Variable<T>::Info>
Variable<T>::ToBlocksInfoMin(const MinVarInfo *coreVarInfo) const
{
auto coreBlocksInfo = coreVarInfo->BlocksInfo;
size_t Step = coreVarInfo->Step;

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

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

blockInfo.Step = Step;
if (coreVarInfo->Shape)
{
blockInfo.Start.reserve(coreVarInfo->Dims);
blockInfo.Count.reserve(coreVarInfo->Dims);
if (coreVarInfo->WasLocalVar)
{
/* Start and count are really values, not pointers */
blockInfo.Start.push_back((size_t)coreBlockInfo.Start);
blockInfo.Count.push_back((size_t)coreBlockInfo.Count);
}
else
{
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)
{
if (std::is_same<T, std::string>::value)
{
std::string *Tmp = (std::string *)&blockInfo.Value;
Tmp->assign(*(const char **)coreBlockInfo.BufferP);
}
else
{
blockInfo.Value = *((T *)coreBlockInfo.BufferP);
}
}
else
{
blockInfo.Min = *(T *)&coreBlockInfo.MinMax.MinUnion;
blockInfo.Max = *(T *)&coreBlockInfo.MinMax.MaxUnion;
}
blockInfo.BlockID = coreBlockInfo.BlockID;
blocksInfo.push_back(blockInfo);
}

return blocksInfo;
}

template <typename T>
std::string ToString(const Variable<T> &variable)
{
Expand Down
Loading

0 comments on commit 7194de9

Please sign in to comment.