added: parallel support to HDF5File / HDF5Serializer

This commit is contained in:
Arne Morten Kvarving
2023-02-09 23:30:02 +01:00
parent 0255bcebb1
commit 8c3400f562
10 changed files with 518 additions and 68 deletions

View File

@@ -26,6 +26,7 @@
#include <opm/input/eclipse/Schedule/Group/Group.hpp>
#define BOOST_TEST_MODULE HDF5FileTest
#define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp>
#include <filesystem>
@@ -38,15 +39,21 @@ BOOST_AUTO_TEST_CASE(Header)
auto path = std::filesystem::temp_directory_path() / Opm::unique_path("hdf5test%%%%%");
std::filesystem::create_directory(path);
auto rwpath = (path / "rw.hdf5").string();
#if HAVE_MPI
Parallel::Communication comm(MPI_COMM_SELF);
#else
Parallel::Communcation comm;
#endif
std::array<std::string,5> output{"foo", "bar", "foobar", "bob", "bobbar"};
{
HDF5Serializer ser(rwpath, HDF5File::OpenMode::OVERWRITE);
HDF5Serializer ser(rwpath, HDF5File::OpenMode::OVERWRITE, comm);
ser.writeHeader(output[0], output[1], output[2], output[3], output[4], 5);
}
{
HDF5Serializer ser(rwpath, HDF5File::OpenMode::READ);
HDF5Serializer ser(rwpath, HDF5File::OpenMode::READ, comm);
std::tuple<std::array<std::string,5>,int> input;
ser.read(input, "/", "simulator_info");
ser.read(input, "/", "simulator_info",
Opm::HDF5File::DataSetMode::ROOT_ONLY);
const auto& [strings, num_procs] = input;
BOOST_CHECK_EQUAL_COLLECTIONS(strings.begin(), strings.end(),
output.begin(), output.end());
@@ -62,13 +69,18 @@ BOOST_AUTO_TEST_CASE(WriteRead)
auto path = std::filesystem::temp_directory_path() / Opm::unique_path("hdf5test%%%%%");
std::filesystem::create_directory(path);
auto rwpath = (path / "rw.hdf5").string();
#if HAVE_MPI
Parallel::Communication comm(MPI_COMM_SELF);
#else
Parallel::Communcation comm;
#endif
auto output = Group::serializationTestObject();
{
HDF5Serializer ser(rwpath, HDF5File::OpenMode::OVERWRITE);
HDF5Serializer ser(rwpath, HDF5File::OpenMode::OVERWRITE, comm);
ser.write(output, "/report_step/10", "test");
}
{
HDF5Serializer ser(rwpath, HDF5File::OpenMode::READ);
HDF5Serializer ser(rwpath, HDF5File::OpenMode::READ, comm);
Group input;
ser.read(input, "/report_step/10", "test");
BOOST_CHECK_MESSAGE(input == output, "Deserialized data does not match input");
@@ -81,3 +93,14 @@ BOOST_AUTO_TEST_CASE(WriteRead)
std::filesystem::remove(rwpath);
std::filesystem::remove(path);
}
bool init_unit_test_func()
{
return true;
}
int main(int argc, char** argv)
{
Dune::MPIHelper::instance(argc, argv);
return boost::unit_test::unit_test_main(&init_unit_test_func, argc, argv);
}