Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for APPEND in HDF5 engine #2459

Merged
merged 7 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/adios2/engine/hdf5/HDF5ReaderP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ void HDF5ReaderP::DoClose(const int transportIndex)
m_H5File.Close();
}

size_t HDF5ReaderP::DoSteps() const { return m_H5File.GetAdiosStep(); }
} // end namespace engine
} // end namespace core
} // end namespace adios2
2 changes: 2 additions & 0 deletions source/adios2/engine/hdf5/HDF5ReaderP.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class HDF5ReaderP : public Engine
void UseHDFRead(Variable<T> &variable, T *values, hid_t h5Type);

std::vector<std::string> m_DeferredStack;

size_t DoSteps() const final;
};

} // end namespace engine
Expand Down
16 changes: 14 additions & 2 deletions source/adios2/engine/hdf5/HDF5WriterP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,25 @@ void HDF5WriterP::Init()
{
// is a file with .bp ending
std::string updatedName = m_Name.substr(0, wpos) + suffix;
m_H5File.Init(updatedName, m_Comm, true);
if (m_OpenMode == Mode::Append)
m_H5File.Append(updatedName, m_Comm);
else
m_H5File.Init(updatedName, m_Comm, true);
}
else
{
m_H5File.Init(m_Name, m_Comm, true);
if (m_OpenMode == Mode::Append)
m_H5File.Append(m_Name, m_Comm);
else
m_H5File.Init(m_Name, m_Comm, true);
}
m_H5File.ParseParameters(m_IO);

if (m_OpenMode == Mode::Append)
{
m_H5File.ReadAttrToIO(m_IO);
m_H5File.ReadAllVariables(m_IO);
}
#endif
}

Expand Down
58 changes: 55 additions & 3 deletions source/adios2/toolkit/interop/hdf5/HDF5Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,52 @@ void HDF5Common::ParseParameters(core::IO &io)
}
}

void HDF5Common::Append(const std::string &name, helper::Comm const &comm)
{
m_PropertyListId = H5Pcreate(H5P_FILE_ACCESS);

if (MPI_API const *mpi = GetHDF5Common_MPI_API())
{
if (mpi && mpi->init(comm, m_PropertyListId, &m_CommRank, &m_CommSize))
{
m_MPI = mpi;
}
}

m_FileId = H5Fopen(name.c_str(), H5F_ACC_RDWR, m_PropertyListId);
H5Pclose(m_PropertyListId);

std::string ts0;
StaticGetAdiosStepString(ts0, 0);

if (m_FileId >= 0)
{
if (H5Lexists(m_FileId, ts0.c_str(), H5P_DEFAULT) != 0)
{
m_IsGeneratedByAdios = true;
}
if (!m_IsGeneratedByAdios)
throw std::ios_base::failure(
"HDF5Engine Append error. Likely no such file." + name);

GetNumAdiosSteps(); // read how many steps exists in this file

if (0 == m_NumAdiosSteps)
throw std::ios_base::failure(
"HDF5Engine Append error. No valid steps found in " + name);
if (1 == m_NumAdiosSteps)
m_GroupId = H5Gopen(m_FileId, ts0.c_str(), H5P_DEFAULT);
else
SetAdiosStep(m_NumAdiosSteps - 1);

m_WriteMode = true;
Advance();
}
else
throw std::ios_base::failure(
"HDF5Engine Append error. Likely no such file." + name);
}

void HDF5Common::Init(const std::string &name, helper::Comm const &comm,
bool toWrite)
{
Expand Down Expand Up @@ -204,9 +250,13 @@ void HDF5Common::WriteAdiosSteps()
}

hid_t s = H5Screate(H5S_SCALAR);
hid_t attr =
H5Acreate(m_FileId, ATTRNAME_NUM_STEPS.c_str(),
/*"NumSteps",*/ H5T_NATIVE_UINT, s, H5P_DEFAULT, H5P_DEFAULT);
hid_t attr = H5Aexists(m_FileId, ATTRNAME_NUM_STEPS.c_str());
if (0 == attr)
attr = H5Acreate(m_FileId, ATTRNAME_NUM_STEPS.c_str(), H5T_NATIVE_UINT,
s, H5P_DEFAULT, H5P_DEFAULT);
else
attr = H5Aopen(m_FileId, ATTRNAME_NUM_STEPS.c_str(), H5P_DEFAULT);

unsigned int totalAdiosSteps = m_CurrentAdiosStep + 1;

if (m_GroupId < 0)
Expand All @@ -220,6 +270,8 @@ void HDF5Common::WriteAdiosSteps()
H5Aclose(attr);
}

unsigned int HDF5Common::GetAdiosStep() const { return m_NumAdiosSteps; }

unsigned int HDF5Common::GetNumAdiosSteps()
{
if (m_WriteMode)
Expand Down
2 changes: 2 additions & 0 deletions source/adios2/toolkit/interop/hdf5/HDF5Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class HDF5Common

void ParseParameters(core::IO &io);
void Init(const std::string &name, helper::Comm const &comm, bool toWrite);
void Append(const std::string &name, helper::Comm const &comm);

template <class T>
void Write(core::Variable<T> &variable, const T *values);
Expand Down Expand Up @@ -172,6 +173,7 @@ class HDF5Common
void SetAdiosStep(int ts);

unsigned int GetNumAdiosSteps();
unsigned int GetAdiosStep() const;
void WriteAdiosSteps();

void ReadVariables(unsigned int ts, core::IO &io);
Expand Down
4 changes: 4 additions & 0 deletions testing/adios2/engine/hdf5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ gtest_add_tests_helper(WriteMemorySelectionRead ${hdf5_mpi}
HDF5 Engine.HDF5. ""
)

gtest_add_tests_helper(Append ${hdf5_mpi}
HDF5 Engine.HDF5. ""
)

gtest_add_tests_helper(NativeHDF5WriteRead ${hdf5_mpi} "" Engine.HDF5. "")
if(HDF5_C_INCLUDE_DIRS)
target_include_directories(Test.Engine.HDF5.NativeHDF5WriteRead${hdf5_sfx}
Expand Down
Loading