diff --git a/src/opt/hdf5_mpi/CMakeLists.txt b/src/opt/hdf5_mpi/CMakeLists.txt index d923e80..0540c3c 100644 --- a/src/opt/hdf5_mpi/CMakeLists.txt +++ b/src/opt/hdf5_mpi/CMakeLists.txt @@ -25,8 +25,8 @@ if(HDF5_IS_PARALLEL) add_subdirectory(lib) add_subdirectory(tests) - install(DIRECTORY include/ DESTINATION ${INSTALL_PATH}/include/cnorxz/hdf5-mpi) - install(CODE "execute_process(COMMAND sed -i \"s|CXZ_H5_MPI_BUILD_MODE 1|CXZ_H5_MPI_BUILD_MODE 0|g;\" ${INSTALL_PATH}/include/cnorxz/hdf5-mpi/h5_mpi_base.h)") + install(DIRECTORY include/ DESTINATION ${INSTALL_PATH}/include/cnorxz/hdf5_mpi) + install(CODE "execute_process(COMMAND sed -i \"s|CXZ_H5_MPI_BUILD_MODE 1|CXZ_H5_MPI_BUILD_MODE 0|g;\" ${INSTALL_PATH}/include/cnorxz/hdf5_mpi/h5_mpi_base.h)") else() message(WARNING "no parallel support in available HDF5 library") endif() diff --git a/src/opt/hdf5_mpi/include/cnorxz_hdf5_mpi.cc.h b/src/opt/hdf5_mpi/include/cnorxz_hdf5_mpi.cc.h index 22fca2b..af25487 100644 --- a/src/opt/hdf5_mpi/include/cnorxz_hdf5_mpi.cc.h +++ b/src/opt/hdf5_mpi/include/cnorxz_hdf5_mpi.cc.h @@ -10,3 +10,4 @@ **/ #include "h5_rdataset.cc.h" +#include "h5_mpi_utils.cc.h" diff --git a/src/opt/hdf5_mpi/include/cnorxz_hdf5_mpi.h b/src/opt/hdf5_mpi/include/cnorxz_hdf5_mpi.h index 527ef9e..684b1d0 100644 --- a/src/opt/hdf5_mpi/include/cnorxz_hdf5_mpi.h +++ b/src/opt/hdf5_mpi/include/cnorxz_hdf5_mpi.h @@ -11,5 +11,6 @@ #include "h5_rfile.h" #include "h5_rdataset.h" +#include "h5_mpi_utils.h" #include "cnorxz_hdf5_mpi.cc.h" diff --git a/src/opt/hdf5_mpi/include/h5_mpi_utils.cc.h b/src/opt/hdf5_mpi/include/h5_mpi_utils.cc.h new file mode 100644 index 0000000..9977f2b --- /dev/null +++ b/src/opt/hdf5_mpi/include/h5_mpi_utils.cc.h @@ -0,0 +1,46 @@ +// -*- C++ -*- +/** + + @file opt/hdf5_mpi/include/h5_mpi_utils.cc.h + @brief CNORXZ utilities for HDF5 together with MPI. + + Copyright (c) 2024 Christian Zimmermann. All rights reserved. + Mail: chizeta@f3l.de + + **/ + +#ifndef __cxz_h5_mpi_utils_cc_h__ +#define __cxz_h5_mpi_utils_cc_h__ + +#include "h5_mpi_utils.h" + +namespace CNORXZ +{ + namespace hdf5 + { + template + Sptr> getRDataset(Group& group, const String& name) + { + return group.get(name, [](const String& name_, const ContentBase* par, auto& i) { + (*i)->close(); + auto dset = std::make_shared>(name_, par); + *i = dset; + return dset; + } ); + } + + template + Group& addRDataset(Group& group, const String& name, const mpi::RArray& data) + { + return group.add("dat", [](const String& name_, const ContentBase* par, + const mpi::RArray& d) { + auto o = std::make_shared>( name_, par ); + o->init(d); + return o; + }, data ); + } + + } +} + +#endif diff --git a/src/opt/hdf5_mpi/include/h5_mpi_utils.h b/src/opt/hdf5_mpi/include/h5_mpi_utils.h new file mode 100644 index 0000000..ef417e0 --- /dev/null +++ b/src/opt/hdf5_mpi/include/h5_mpi_utils.h @@ -0,0 +1,32 @@ +// -*- C++ -*- +/** + + @file opt/hdf5_mpi/include/h5_mpi_utils.h + @brief CNORXZ utilities for HDF5 together with MPI. + + Copyright (c) 2024 Christian Zimmermann. All rights reserved. + Mail: chizeta@f3l.de + + **/ + +#ifndef __cxz_h5_mpi_utils_h__ +#define __cxz_h5_mpi_utils_h__ + +#include "h5_group.h" +#include "h5_rdataset.h" + +namespace CNORXZ +{ + namespace hdf5 + { + + template + Sptr> getRDataset(Group& group, const String& name); + + template + Group& addRDataset(Group& group, const String& name, const mpi::RArray& data); + + } +} + +#endif diff --git a/src/opt/hdf5_mpi/tests/h5_mpi_basic_unit_test.cc b/src/opt/hdf5_mpi/tests/h5_mpi_basic_unit_test.cc index fc6d794..7eb0cc7 100644 --- a/src/opt/hdf5_mpi/tests/h5_mpi_basic_unit_test.cc +++ b/src/opt/hdf5_mpi/tests/h5_mpi_basic_unit_test.cc @@ -75,17 +75,19 @@ namespace h5f.open(); h5f.addGroup("dir"); auto dir = h5f.getGroup("dir"); - dir->add("dat", [](const String& name, const ContentBase* par, const RArray& d) - { auto o = std::make_shared>( name, par ); o->init(d); return o; }, mA ); + //dir->add("dat", [](const String& name, const ContentBase* par, const RArray& d) + //{ auto o = std::make_shared>( name, par ); o->init(d); return o; }, mA ); + addRDataset(*dir, "dat", mA); h5f.close(); } TEST_F(RDataset_test, Read) { RFile h5f(mFilename, false); - auto dat = h5f.open().getGroup("dir")->open().get("dat", [](const String& name, const ContentBase* par, auto& i) - { (*i)->close(); auto dset = std::make_shared>(name, par); *i = dset; - return dset; } ); + //auto dat = h5f.open().getGroup("dir")->open().get("dat", [](const String& name, const ContentBase* par, auto& i) + //{ (*i)->close(); auto dset = std::make_shared>(name, par); *i = dset; + // return dset; } ); + auto dat = getRDataset(h5f.open().getGroup("dir")->open(),"dat"); auto a = dat->read(mGeom); h5f.close();