Skip to content

Commit

Permalink
Add flush function for the IO and fix test build warnings for testHDF5IO
Browse files Browse the repository at this point in the history
  • Loading branch information
oruebel committed Aug 9, 2024
1 parent bc4b68c commit 6aff062
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/BaseIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ class BaseIO
*/
virtual Status close() = 0;

/**
* @brief Flush data to disk
* @return The status of the flush operation.
*/
virtual Status flush() = 0;

/**
* @brief Creates an attribute at a given location in the file.
* @param type The base data type of the attribute.
Expand Down
8 changes: 7 additions & 1 deletion src/hdf5/HDF5IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ Status checkStatus(int status)
return Status::Success;
}

Status HDF5IO::flush()
{
int status = H5Fflush(this->file->getId(), H5F_SCOPE_GLOBAL);
return checkStatus(status);
}

Status HDF5IO::createAttribute(const BaseDataType& type,
const void* data,
const std::string& path,
Expand Down Expand Up @@ -407,7 +413,7 @@ Status HDF5IO::stopRecording()
if (!disableSWMRMode) {
close(); // SWMR mode cannot be disabled so close the file
} else {
H5Fflush(this->file->getId(), H5F_SCOPE_GLOBAL); // flush all data to disk
this->flush();
}
return Status::Success;
}
Expand Down
6 changes: 6 additions & 0 deletions src/hdf5/HDF5IO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class HDF5IO : public BaseIO
*/
Status close() override;

/**
* @brief Flush data to disk
* @return The status of the flush operation.
*/
Status flush() override;

/**
* @brief Creates an attribute at a given location in the file.
* @param type The base data type of the attribute.
Expand Down
13 changes: 10 additions & 3 deletions tests/testHDF5IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ TEST_CASE("writeDataset", "[hdf5io]")
dataPath);
Status status = dataset->writeDataBlock(
dataShape, positionOffset, BaseDataType::I32, testData.data());
REQUIRE(status == Status::Success);

// Read back the 1D data block from 3D dataset
std::unique_ptr<BaseRecordingData> dataRead1D =
Expand Down Expand Up @@ -129,6 +130,7 @@ TEST_CASE("writeDataset", "[hdf5io]")
// Write 2D data block
Status status = dataset->writeDataBlock(
dataShape, positionOffset, BaseDataType::I32, testData.data());
REQUIRE(status == Status::Success);

// Read back the 2D data block
std::unique_ptr<BaseRecordingData> dsetRead2D =
Expand Down Expand Up @@ -165,6 +167,7 @@ TEST_CASE("writeDataset", "[hdf5io]")
dataPath);
Status status = dataset->writeDataBlock(
dataShape, positionOffset, BaseDataType::I32, testData.data());
REQUIRE(status == Status::Success);

// Read back the 1D data block from 3D dataset
std::unique_ptr<BaseRecordingData> dataRead1D =
Expand Down Expand Up @@ -201,6 +204,7 @@ TEST_CASE("writeDataset", "[hdf5io]")
dataPath);
Status status = dataset->writeDataBlock(
dataShape, positionOffset, BaseDataType::I32, testData.data());
REQUIRE(status == Status::Success);

// Read back the 2D data block from 3D dataset
std::unique_ptr<BaseRecordingData> dataRead2D =
Expand Down Expand Up @@ -312,7 +316,7 @@ TEST_CASE("SWMRmode", "[hdf5io]")
std::move(promise));

// write to file
for (int b = 0; b <= numBlocks; b++) {
for (SizeType b = 0; b <= numBlocks; b++) {
// write data block and flush to file
std::vector<SizeType> dataShape = {numSamples};
dataset->writeDataBlock(dataShape, BaseDataType::I32, &testData[0]);
Expand All @@ -336,6 +340,9 @@ TEST_CASE("SWMRmode", "[hdf5io]")
REQUIRE(retSWMREnabled == 0); // process should succeed if data was written
// and read successfully

// test flush data to disk
REQUIRE(hdf5io->flush() == Status::Success);

// stop recording, check that file is closed and recording cannot be
// restarted
status = hdf5io->stopRecording();
Expand Down Expand Up @@ -365,7 +372,7 @@ TEST_CASE("SWMRmode", "[hdf5io]")
REQUIRE(hdf5io->canModifyObjects() == true);

// write to file
for (int b = 0; b <= numBlocks; b++) {
for (SizeType b = 0; b <= numBlocks; b++) {
// write data block and flush to file
std::vector<SizeType> dataShape = {numSamples};
dataset->writeDataBlock(dataShape, BaseDataType::I32, &testData[0]);
Expand Down Expand Up @@ -396,7 +403,7 @@ TEST_CASE("SWMRmode", "[hdf5io]")
SizeArray {1},
dataPathPostRestart);

for (int b = 0; b <= numBlocks; b++) {
for (SizeType b = 0; b <= numBlocks; b++) {
// write data block and flush to file
std::vector<SizeType> dataShape = {numSamples};
datasetPostRestart->writeDataBlock(
Expand Down

0 comments on commit 6aff062

Please sign in to comment.