Skip to content
Snippets Groups Projects
Unverified Commit 8f07fb99 authored by guj's avatar guj Committed by GitHub
Browse files

Merge pull request #329 from guj/1204

added GetPreferred for stream reading
parents 42a905fe 0dfa5f71
No related branches found
No related tags found
No related merge requests found
......@@ -32,8 +32,17 @@ adios2::Variable<unsigned int> *varGndx = nullptr;
IO::IO(const Settings &s, MPI_Comm comm)
{
rank_saved = s.rank;
// m_outputfilename = s.outputfile + ".h5";
m_outputfilename = s.outputfile;
std::string suffix = ".h5";
int ss = s.outputfile.size();
if ((ss > suffix.size()) && s.outputfile.find(suffix) != ss - suffix.size())
{
// Your code here
m_outputfilename += suffix;
}
/*ad = new adios2::ADIOS(std::string(DEFAULT_CONFIG_STR), comm,
adios2::DebugON);
*/
......
......@@ -276,7 +276,18 @@ std::shared_ptr<HDF5NativeWriter> h5writer;
IO::IO(const Settings &s, MPI_Comm comm)
{
m_outputfilename = s.outputfile + ".h5";
std::string suffix = ".h5";
m_outputfilename = s.outputfile + suffix;
int ss = s.outputfile.size();
int pos = s.outputfile.find(suffix);
if ((ss > suffix.size()) && (pos == ss - suffix.size()))
{
// Your code here
m_outputfilename = s.outputfile;
}
// m_outputfilename = s.outputfile + ".h5";
if (s.outputfile[0] == '0')
{
......
......@@ -21,7 +21,17 @@ adios2::Variable<unsigned int> *varGndx = nullptr;
IO::IO(const Settings &s, MPI_Comm comm)
{
m_outputfilename = s.outputfile + ".h5";
std::string suffix = ".h5";
m_outputfilename = s.outputfile + suffix;
int ss = s.outputfile.size();
int pos = s.outputfile.find(suffix);
if ((ss > suffix.size()) && (pos == ss - suffix.size()))
{
// Your code here
m_outputfilename = s.outputfile;
}
ad = new adios2::ADIOS(comm, adios2::DebugOFF);
// Define method for engine creation
......
......@@ -74,9 +74,16 @@ void HDF5ReaderP::UseHDFRead(Variable<T> &variable, T *data, hid_t h5Type)
{
int ts = 0;
T *values = data;
size_t variableStart = variable.m_StepsStart;
if (!m_InStreamMode && (variableStart == 1))
{ // variableBase::m_StepsStart min=1
variableStart = 0;
}
while (ts < variable.m_StepsCount)
{
m_H5File.SetTimeStep(variable.m_StepsStart + ts);
// m_H5File.SetTimeStep(variable.m_StepsStart + ts);
m_H5File.SetTimeStep(variableStart + ts);
hid_t dataSetId =
H5Dopen(m_H5File.m_GroupId, variable.m_Name.c_str(), H5P_DEFAULT);
......@@ -223,7 +230,50 @@ values); #endif
}
*/
void HDF5ReaderP::EndStep() { m_H5File.Advance(); }
StepStatus HDF5ReaderP::BeginStep(StepMode mode, const float timeoutSeconds)
{
m_InStreamMode = true;
int ts = m_H5File.GetNumTimeSteps();
if (m_StreamAt >= ts)
{
return StepStatus::EndOfStream;
}
return StepStatus::OK;
}
void HDF5ReaderP::EndStep()
{
m_StreamAt++;
m_H5File.Advance();
}
void HDF5ReaderP::PerformGets()
{
if (!m_InStreamMode)
{
throw std::runtime_error(
"PerformGets() needs to follow stream read sequeuences.");
}
#define declare_type(T) \
for (std::string variableName : m_DeferredStack) \
{ \
Variable<T> *var = m_IO.InquireVariable<T>(variableName); \
if (var != nullptr) \
{ \
var->m_StepsStart = m_StreamAt; \
var->m_StepsCount = 1; \
hid_t h5Type = m_H5File.GetHDF5Type<T>(); \
UseHDFRead(*var, var->GetData(), h5Type); \
break; \
} \
}
ADIOS2_FOREACH_TYPE_1ARG(declare_type)
#undef declare_type
m_DeferredStack.clear();
}
void HDF5ReaderP::Close(const int transportIndex) { m_H5File.Close(); }
......
......@@ -36,8 +36,11 @@ public:
bool IsValid();
StepStatus BeginStep(StepMode mode, const float timeoutSeconds = 0.f) final;
void EndStep() final;
void PerformGets() final;
void Close(const int transportIndex = -1) final;
private:
......@@ -45,6 +48,7 @@ private:
void Init() final;
bool m_InStreamMode = false; // default is not streaming
unsigned int m_StreamAt = 0; // stream step counter
#define declare_type(T) \
void DoGetSync(Variable<T> &, T *) final; \
void DoGetDeferred(Variable<T> &, T *) final; \
......@@ -62,6 +66,8 @@ private:
// void UseHDFRead(const std::string &variableName, T *values, hid_t
// h5Type);
void UseHDFRead(Variable<T> &variable, T *values, hid_t h5Type);
std::vector<std::string> m_DeferredStack;
};
};
#endif /* ADIOS2_ENGINE_HDF5_HDF5READERP_H_ */
......@@ -33,10 +33,21 @@ void HDF5ReaderP::GetSyncCommon(Variable<T> &variable, T *data)
template <class T>
void HDF5ReaderP::GetDeferredCommon(Variable<T> &variable, T *data)
{
#ifdef NEVER
// returns immediately
// m_HDF53Deserializer.GetDeferredVariable(variable, data);
throw std::runtime_error("Todo: GetDefCommon");
if (m_InStreamMode)
{
variable.m_StepsStart = m_StreamAt; // current step
variable.m_StepsCount = 1;
}
hid_t h5Type = m_H5File.GetHDF5Type<T>();
UseHDFRead(variable, data, h5Type);
#else
m_DeferredStack.push_back(variable.m_Name);
variable.SetData(data);
#endif
}
} // end namespace adios2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment