hdf5_mpi: add h5_mpi_utils
This commit is contained in:
parent
82fb79a50e
commit
062f9cd19a
6 changed files with 89 additions and 7 deletions
|
@ -25,8 +25,8 @@ if(HDF5_IS_PARALLEL)
|
||||||
add_subdirectory(lib)
|
add_subdirectory(lib)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
|
||||||
install(DIRECTORY include/ DESTINATION ${INSTALL_PATH}/include/cnorxz/hdf5-mpi)
|
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(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()
|
else()
|
||||||
message(WARNING "no parallel support in available HDF5 library")
|
message(WARNING "no parallel support in available HDF5 library")
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -10,3 +10,4 @@
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "h5_rdataset.cc.h"
|
#include "h5_rdataset.cc.h"
|
||||||
|
#include "h5_mpi_utils.cc.h"
|
||||||
|
|
|
@ -11,5 +11,6 @@
|
||||||
|
|
||||||
#include "h5_rfile.h"
|
#include "h5_rfile.h"
|
||||||
#include "h5_rdataset.h"
|
#include "h5_rdataset.h"
|
||||||
|
#include "h5_mpi_utils.h"
|
||||||
|
|
||||||
#include "cnorxz_hdf5_mpi.cc.h"
|
#include "cnorxz_hdf5_mpi.cc.h"
|
||||||
|
|
46
src/opt/hdf5_mpi/include/h5_mpi_utils.cc.h
Normal file
46
src/opt/hdf5_mpi/include/h5_mpi_utils.cc.h
Normal file
|
@ -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 <typename T>
|
||||||
|
Sptr<SRDataset<T>> 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<SRDataset<Double>>(name_, par);
|
||||||
|
*i = dset;
|
||||||
|
return dset;
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
Group& addRDataset(Group& group, const String& name, const mpi::RArray<T>& data)
|
||||||
|
{
|
||||||
|
return group.add("dat", [](const String& name_, const ContentBase* par,
|
||||||
|
const mpi::RArray<Double>& d) {
|
||||||
|
auto o = std::make_shared<SRDataset<Double>>( name_, par );
|
||||||
|
o->init(d);
|
||||||
|
return o;
|
||||||
|
}, data );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
32
src/opt/hdf5_mpi/include/h5_mpi_utils.h
Normal file
32
src/opt/hdf5_mpi/include/h5_mpi_utils.h
Normal file
|
@ -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 <typename T>
|
||||||
|
Sptr<SRDataset<T>> getRDataset(Group& group, const String& name);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
Group& addRDataset(Group& group, const String& name, const mpi::RArray<T>& data);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -75,17 +75,19 @@ namespace
|
||||||
h5f.open();
|
h5f.open();
|
||||||
h5f.addGroup("dir");
|
h5f.addGroup("dir");
|
||||||
auto dir = h5f.getGroup("dir");
|
auto dir = h5f.getGroup("dir");
|
||||||
dir->add("dat", [](const String& name, const ContentBase* par, const RArray<Double>& d)
|
//dir->add("dat", [](const String& name, const ContentBase* par, const RArray<Double>& d)
|
||||||
{ auto o = std::make_shared<SRDataset<Double>>( name, par ); o->init(d); return o; }, mA );
|
//{ auto o = std::make_shared<SRDataset<Double>>( name, par ); o->init(d); return o; }, mA );
|
||||||
|
addRDataset(*dir, "dat", mA);
|
||||||
h5f.close();
|
h5f.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(RDataset_test, Read)
|
TEST_F(RDataset_test, Read)
|
||||||
{
|
{
|
||||||
RFile h5f(mFilename, false);
|
RFile h5f(mFilename, false);
|
||||||
auto dat = h5f.open().getGroup("dir")->open().get("dat", [](const String& name, const ContentBase* par, auto& i)
|
//auto dat = h5f.open().getGroup("dir")->open().get("dat", [](const String& name, const ContentBase* par, auto& i)
|
||||||
{ (*i)->close(); auto dset = std::make_shared<SRDataset<Double>>(name, par); *i = dset;
|
//{ (*i)->close(); auto dset = std::make_shared<SRDataset<Double>>(name, par); *i = dset;
|
||||||
return dset; } );
|
// return dset; } );
|
||||||
|
auto dat = getRDataset<Double>(h5f.open().getGroup("dir")->open(),"dat");
|
||||||
auto a = dat->read(mGeom);
|
auto a = dat->read(mGeom);
|
||||||
h5f.close();
|
h5f.close();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue