Commit e60a18bb authored by Tobias Meisel's avatar Tobias Meisel
Browse files

[MeL/IO] Add abstraction layer for parallel and serial file IO for HDF5

parent a0ddf290
/**
* \file
* \author Tobias Meisel
* \date 2020-12-08
* \brief Dispatches HDF5 functions specific to execution plattform (w/o MPI).
* There are multiple implementation to this interface! \copyright Copyright (c)
* 2012-2020, OpenGeoSys Community (http://www.opengeosys.org) Distributed under
* a Modified BSD License. See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*/
#pragma once
#include <filesystem>
namespace MeshLib::IO
{
int64_t createFile(std::filesystem::path const& filepath);
int64_t openHDF5File(std::filesystem::path const& filepath);
int64_t createHDF5TransferPolicy();
} // namespace MeshLib::IO
/**
* \file
* \author Tobias Meisel
* \date 2020-12-08
* \brief Function specific to execution with MPI, never include directly!!
* \copyright Copyright (c) 2012-2020, OpenGeoSys Community
* (http://www.opengeosys.org) Distributed under a Modified BSD License. See
* accompanying file LICENSE.txt or http://www.opengeosys.org/project/license
*/
#include "../fileIO.h"
#include <hdf5.h>
#include <mpi.h>
#include "BaseLib/Logging.h"
namespace MeshLib::IO
{
hid_t createFile(std::filesystem::path const& filepath)
{
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Info info = MPI_INFO_NULL;
hid_t const plist_id = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_mpio(plist_id, comm, info);
hid_t file = H5Fcreate(filepath.string().c_str(), H5F_ACC_TRUNC,
H5P_DEFAULT, plist_id);
H5Pclose(plist_id);
return file;
}
hid_t openHDF5File(std::filesystem::path const& filepath)
{
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Info info = MPI_INFO_NULL;
hid_t const plist_id = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_mpio(plist_id, comm, info);
hid_t file = H5Fopen(filepath.string().c_str(), H5F_ACC_RDWR, plist_id);
H5Pclose(plist_id);
return file;
}
hid_t createHDF5TransferPolicy()
{
// property list for collective dataset write
hid_t io_transfer_property = H5Pcreate(H5P_DATASET_XFER);
H5Pset_dxpl_mpio(io_transfer_property, H5FD_MPIO_COLLECTIVE);
return io_transfer_property;
}
} // namespace MeshLib::IO
\ No newline at end of file
/**
* \file
* \author Tobias Meisel
* \date 2020-12-08
* \brief Function specific to execution without MPI
* \copyright Copyright (c) 2012-2020, OpenGeoSys Community
* (http://www.opengeosys.org) Distributed under a Modified BSD License. See
* accompanying file LICENSE.txt or http://www.opengeosys.org/project/license
*/
#include "../fileIO.h"
#include <hdf5.h>
namespace MeshLib::IO
{
int64_t createFile(std::filesystem::path const& filepath)
{
return H5Fcreate(filepath.string().c_str(), H5F_ACC_TRUNC, H5P_DEFAULT,
H5P_DEFAULT);
}
int64_t openHDF5File(std::filesystem::path const& filepath)
{
return H5Fopen(filepath.string().c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
}
int64_t createHDF5TransferPolicy()
{
return H5P_DEFAULT;
}
} // namespace MeshLib::IO
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment