36 #include <lifev/core/filter/HDF5IO.hpp> 45 LifeV::HDF5IO::HDF5IO (
const std::string& fileName,
const commPtr_Type& comm,
48 openFile (fileName, comm, existing);
55 void LifeV::HDF5IO::openFile (
const std::string& fileName,
56 const commPtr_Type& comm,
60 MPI_Comm mpiComm = comm->Comm();
61 MPI_Info info = MPI_INFO_NULL;
64 plistId = H5Pcreate (H5P_FILE_ACCESS);
65 H5Pset_fapl_mpio (plistId, mpiComm, info);
70 M_fileId = H5Fopen (fileName.c_str(), H5F_ACC_RDONLY, plistId);
74 M_fileId = H5Fcreate (fileName.c_str(), H5F_ACC_TRUNC,
75 H5P_DEFAULT, plistId);
80 void LifeV::HDF5IO::createTable (
const std::string& tableName,
82 hsize_t tableDimensions[])
84 tableHandle& currentTable = M_tableList[tableName];
86 currentTable.filespace = H5Screate_simple (2, tableDimensions,
89 currentTable.dataset = H5Dcreate (M_fileId, tableName.c_str(), fileDataType,
90 currentTable.filespace, H5P_DEFAULT);
92 currentTable.dataset = H5Dcreate (M_fileId, tableName.c_str(), fileDataType,
93 currentTable.filespace, H5P_DEFAULT,
94 H5P_DEFAULT, H5P_DEFAULT);
96 currentTable.plist = H5Pcreate (H5P_DATASET_XFER);
97 H5Pset_dxpl_mpio (currentTable.plist, H5FD_MPIO_COLLECTIVE);
100 void LifeV::HDF5IO::openTable (
const std::string& tableName,
101 hsize_t tableDimensions[])
103 tableHandle& currentTable = M_tableList[tableName];
106 currentTable.dataset = H5Dopen (M_fileId, tableName.c_str() );
108 currentTable.dataset = H5Dopen (M_fileId, tableName.c_str(), H5P_DEFAULT);
110 currentTable.filespace = H5Dget_space (currentTable.dataset);
111 H5Sget_simple_extent_dims (currentTable.filespace, tableDimensions, NULL);
112 currentTable.plist = H5Pcreate (H5P_DATASET_XFER);
113 H5Pset_dxpl_mpio (currentTable.plist, H5FD_MPIO_COLLECTIVE);
116 void LifeV::HDF5IO::write (
const std::string& tableName,
117 hid_t& memDataType, hsize_t currentCount[],
118 hsize_t currentOffset[],
void* buffer)
120 tableHandle& currentTable = M_tableList[tableName];
122 hid_t memspace = H5Screate_simple (2, currentCount, currentCount);
124 H5Sselect_hyperslab (currentTable.filespace, H5S_SELECT_SET, currentOffset,
125 NULL, currentCount, NULL);
126 H5Dwrite (currentTable.dataset, memDataType, memspace,
127 currentTable.filespace, currentTable.plist, buffer);
132 void LifeV::HDF5IO::read (
const std::string& tableName,
133 hid_t& memDataType, hsize_t currentCount[],
134 hsize_t currentOffset[],
void* buffer)
136 tableHandle& currentTable = M_tableList[tableName];
138 hid_t memspace = H5Screate_simple (2, currentCount, currentCount);
140 H5Sselect_hyperslab (currentTable.filespace, H5S_SELECT_SET, currentOffset,
141 NULL, currentCount, NULL);
142 H5Dread (currentTable.dataset, memDataType, memspace,
143 currentTable.filespace, currentTable.plist,
149 void LifeV::HDF5IO::closeTable (
const std::string& tableName)
151 tableHandle& currentTable = M_tableList[tableName];
152 H5Sclose (currentTable.filespace);
153 H5Dclose (currentTable.dataset);
154 H5Pclose (currentTable.plist);
155 M_tableList.erase (tableName);
158 void LifeV::HDF5IO::closeFile()