Commit b76d62c8 authored by kicici's avatar kicici

HDF5 real type as a template parameter

Removing _HDF5_DOUBLE_PRECISION_ from the library.
parent 6f279789
......@@ -17,13 +17,11 @@
#include <hdf5.h>
#endif
#ifndef _HDF5_DOUBLE_PRECISION_
#define HDF_REAL H5T_NATIVE_FLOAT
typedef float hdf5Real;
#else
#define HDF_REAL H5T_NATIVE_DOUBLE
typedef double hdf5Real;
#endif
// Function to retrieve HDF5 type (hid_t) for a given real type.
// If using custom types, the user should specialize this function.
template <typename T> hid_t get_hdf5_type();
template <> inline hid_t get_hdf5_type<float>() { return H5T_NATIVE_FLOAT; }
template <> inline hid_t get_hdf5_type<double>() { return H5T_NATIVE_DOUBLE; }
#include "BlockInfo.h"
#include "MeshMap.h"
......@@ -34,7 +32,7 @@ CUBISM_NAMESPACE_BEGIN
// TStreamer::NCHANNELS : Number of data elements (1=Scalar, 3=Vector, 9=Tensor)
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TGrid>
template<typename TStreamer, typename hdf5Real, typename TGrid>
void DumpHDF5(const TGrid &grid,
const int iCounter,
const typename TGrid::Real absTime,
......@@ -138,9 +136,9 @@ void DumpHDF5(const TGrid &grid,
fspace_id = H5Screate_simple(4, dims, NULL);
#ifndef _ON_FERMI_
dataset_id = H5Dcreate(file_id, "data", HDF_REAL, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset_id = H5Dcreate(file_id, "data", get_hdf5_type<hdf5Real>(), fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
#else
dataset_id = H5Dcreate2(file_id, "data", HDF_REAL, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset_id = H5Dcreate2(file_id, "data", get_hdf5_type<hdf5Real>(), fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
#endif
fspace_id = H5Dget_space(dataset_id);
......@@ -149,7 +147,8 @@ void DumpHDF5(const TGrid &grid,
mspace_id = H5Screate_simple(4, count, NULL);
status = H5Dwrite(dataset_id, HDF_REAL, mspace_id, fspace_id, fapl_id, array_all); if(status<0) H5Eprint1(stdout);
status = H5Dwrite(dataset_id, get_hdf5_type<hdf5Real>(), mspace_id, fspace_id, fapl_id, array_all);
if (status < 0) H5Eprint1(stdout);
status = H5Sclose(mspace_id); if(status<0) H5Eprint1(stdout);
status = H5Sclose(fspace_id); if(status<0) H5Eprint1(stdout);
......@@ -198,7 +197,7 @@ void DumpHDF5(const TGrid &grid,
}
template<typename TStreamer, typename TGrid>
template<typename TStreamer, typename hdf5Real, typename TGrid>
void ReadHDF5(TGrid &grid, const std::string fname, const std::string dpath=".")
{
#ifdef _USE_HDF_
......@@ -238,7 +237,8 @@ void ReadHDF5(TGrid &grid, const std::string fname, const std::string dpath=".")
H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, offset, NULL, count, NULL);
mspace_id = H5Screate_simple(4, count, NULL);
status = H5Dread(dataset_id, HDF_REAL, mspace_id, fspace_id, fapl_id, array_all); if(status<0) H5Eprint1(stdout);
status = H5Dread(dataset_id, get_hdf5_type<hdf5Real>(), mspace_id, fspace_id, fapl_id, array_all);
if (status < 0) H5Eprint1(stdout);
#pragma omp parallel for
for(size_t i=0; i<vInfo_local.size(); i++)
......
......@@ -17,20 +17,8 @@
#include <sstream>
#include <mpi.h>
#ifdef _USE_HDF_
#include <hdf5.h>
#endif
#ifndef _HDF5_DOUBLE_PRECISION_
#define HDF_REAL H5T_NATIVE_FLOAT
typedef float hdf5Real;
#else
#define HDF_REAL H5T_NATIVE_DOUBLE
typedef double hdf5Real;
#endif
#include "HDF5Dumper.h"
#include "BlockInfo.h"
#include "MeshMap.h"
CUBISM_NAMESPACE_BEGIN
......@@ -38,7 +26,7 @@ CUBISM_NAMESPACE_BEGIN
// TStreamer::NCHANNELS : Number of data elements (1=Scalar, 3=Vector, 9=Tensor)
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TGrid>
template<typename TStreamer, typename hdf5Real, typename TGrid>
void DumpHDF5_MPI(const TGrid &grid,
const int iCounter,
const typename TGrid::Real absTime,
......@@ -192,15 +180,16 @@ void DumpHDF5_MPI(const TGrid &grid,
fspace_id = H5Screate_simple(4, dims, NULL);
#ifndef _ON_FERMI_
dataset_id = H5Dcreate(file_id, "data", HDF_REAL, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset_id = H5Dcreate(file_id, "data", get_hdf5_type<hdf5Real>(), fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
#else
dataset_id = H5Dcreate2(file_id, "data", HDF_REAL, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset_id = H5Dcreate2(file_id, "data", get_hdf5_type<hdf5Real>(), fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
#endif
fspace_id = H5Dget_space(dataset_id);
H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, offset, NULL, count, NULL);
mspace_id = H5Screate_simple(4, count, NULL);
status = H5Dwrite(dataset_id, HDF_REAL, mspace_id, fspace_id, fapl_id, array_all); if(status<0) H5Eprint1(stdout);
status = H5Dwrite(dataset_id, get_hdf5_type<hdf5Real>(), mspace_id, fspace_id, fapl_id, array_all);
if (status < 0) H5Eprint1(stdout);
status = H5Sclose(mspace_id); if(status<0) H5Eprint1(stdout);
status = H5Sclose(fspace_id); if(status<0) H5Eprint1(stdout);
......@@ -248,7 +237,7 @@ void DumpHDF5_MPI(const TGrid &grid,
#endif
}
template<typename TStreamer, typename TGrid>
template<typename TStreamer, typename hdf5Real, typename TGrid>
void ReadHDF5_MPI(TGrid &grid, const std::string fname, const std::string dpath=".")
{
#ifdef _USE_HDF_
......@@ -303,7 +292,8 @@ void ReadHDF5_MPI(TGrid &grid, const std::string fname, const std::string dpath=
H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, offset, NULL, count, NULL);
mspace_id = H5Screate_simple(4, count, NULL);
status = H5Dread(dataset_id, HDF_REAL, mspace_id, fspace_id, fapl_id, array_all); if(status<0) H5Eprint1(stdout);
status = H5Dread(dataset_id, get_hdf5_type<hdf5Real>(), mspace_id, fspace_id, fapl_id, array_all);
if (status < 0) H5Eprint1(stdout);
#pragma omp parallel for
for(size_t i=0; i<vInfo_local.size(); i++)
......
......@@ -14,20 +14,7 @@
#include <string>
#include <sstream>
#ifdef _USE_HDF_
#include <hdf5.h>
#endif
#ifndef _HDF5_DOUBLE_PRECISION_
#define HDF_REAL H5T_NATIVE_FLOAT
typedef float hdf5Real;
#else
#define HDF_REAL H5T_NATIVE_DOUBLE
typedef double hdf5Real;
#endif
#include "BlockInfo.h"
#include "MeshMap.h"
#include "HDF5Dumper.h"
CUBISM_NAMESPACE_BEGIN
......@@ -175,7 +162,7 @@ namespace SliceTypes
std::cout << prefix << "NUMBER OF BLOCKS = " << m_intersecting_blocks.size() << std::endl;
}
template <typename TStreamer>
template <typename TStreamer, typename hdf5Real>
inline void extract(hdf5Real* const data) const
{
if (0 == m_dir)
......@@ -201,7 +188,7 @@ namespace SliceTypes
std::vector<BlockInfo> m_intersecting_blocks;
private:
template <typename TStreamer>
template <typename TStreamer, typename hdf5Real>
void _YZ(hdf5Real * const data) const
{
const int ix = m_idx % _BLOCKSIZE_;
......@@ -234,7 +221,7 @@ namespace SliceTypes
}
}
template <typename TStreamer>
template <typename TStreamer, typename hdf5Real>
void _XZ(hdf5Real * const data) const
{
const int iy = m_idx % _BLOCKSIZE_;
......@@ -267,7 +254,7 @@ namespace SliceTypes
}
}
template <typename TStreamer>
template <typename TStreamer, typename hdf5Real>
void _YX(hdf5Real * const data) const
{
const int iz = m_idx % _BLOCKSIZE_;
......@@ -309,7 +296,7 @@ namespace SliceTypes
// TStreamer::NCHANNELS : Number of data elements (1=Scalar, 3=Vector, 9=Tensor)
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TSlice>
template<typename TStreamer, typename hdf5Real, typename TSlice>
void DumpSliceHDF5(const TSlice& slice,
const int stepID,
const typename TSlice::GridType::Real t,
......@@ -394,9 +381,9 @@ void DumpSliceHDF5(const TSlice& slice,
fapl_id = H5Pcreate(H5P_DATASET_XFER);
fspace_id = H5Screate_simple(3, dims, NULL);
#ifndef _ON_FERMI_
dataset_id = H5Dcreate(file_id, "data", HDF_REAL, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset_id = H5Dcreate(file_id, "data", get_hdf5_type<hdf5Real>(), fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
#else
dataset_id = H5Dcreate2(file_id, "data", HDF_REAL, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset_id = H5Dcreate2(file_id, "data", get_hdf5_type<hdf5Real>(), fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
#endif
fspace_id = H5Dget_space(dataset_id);
......@@ -407,7 +394,8 @@ void DumpSliceHDF5(const TSlice& slice,
H5Sselect_none(fspace_id);
H5Sselect_none(mspace_id);
}
status = H5Dwrite(dataset_id, HDF_REAL, mspace_id, fspace_id, fapl_id, array_all); if(status<0) H5Eprint1(stdout);
status = H5Dwrite(dataset_id, get_hdf5_type<hdf5Real>(), mspace_id, fspace_id, fapl_id, array_all);
if (status < 0) H5Eprint1(stdout);
status = H5Sclose(mspace_id); if(status<0) H5Eprint1(stdout);
status = H5Sclose(fspace_id); if(status<0) H5Eprint1(stdout);
......
......@@ -97,7 +97,7 @@ namespace SliceTypesMPI
// TStreamer::NCHANNELS : Number of data elements (1=Scalar, 3=Vector, 9=Tensor)
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TSlice>
template<typename TStreamer, typename hdf5Real, typename TSlice>
void DumpSliceHDF5MPI(const TSlice& slice,
const int stepID,
const typename TSlice::GridType::Real t,
......@@ -212,9 +212,9 @@ void DumpSliceHDF5MPI(const TSlice& slice,
fspace_id = H5Screate_simple(3, dims, NULL);
#ifndef _ON_FERMI_
dataset_id = H5Dcreate(file_id, "data", HDF_REAL, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset_id = H5Dcreate(file_id, "data", get_hdf5_type<hdf5Real>(), fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
#else
dataset_id = H5Dcreate2(file_id, "data", HDF_REAL, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset_id = H5Dcreate2(file_id, "data", get_hdf5_type<hdf5Real>(), fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
#endif
fspace_id = H5Dget_space(dataset_id);
......@@ -225,7 +225,8 @@ void DumpSliceHDF5MPI(const TSlice& slice,
H5Sselect_none(fspace_id);
H5Sselect_none(mspace_id);
}
status = H5Dwrite(dataset_id, HDF_REAL, mspace_id, fspace_id, fapl_id, array_all); if(status<0) H5Eprint1(stdout);
status = H5Dwrite(dataset_id, get_hdf5_type<hdf5Real>(), mspace_id, fspace_id, fapl_id, array_all);
if (status < 0) H5Eprint1(stdout);
status = H5Sclose(mspace_id); if(status<0) H5Eprint1(stdout);
status = H5Sclose(fspace_id); if(status<0) H5Eprint1(stdout);
......
......@@ -14,20 +14,7 @@
#include <string>
#include <sstream>
#ifdef _USE_HDF_
#include <hdf5.h>
#endif
#ifndef _HDF5_DOUBLE_PRECISION_
#define HDF_REAL H5T_NATIVE_FLOAT
typedef float hdf5Real;
#else
#define HDF_REAL H5T_NATIVE_DOUBLE
typedef double hdf5Real;
#endif
#include "BlockInfo.h"
#include "MeshMap.h"
#include "HDF5Dumper.h"
CUBISM_NAMESPACE_BEGIN
......@@ -308,7 +295,7 @@ namespace SubdomainTypes
// TStreamer::NCHANNELS : Number of data elements (1=Scalar, 3=Vector, 9=Tensor)
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TSubdomain>
template<typename TStreamer, typename hdf5Real, typename TSubdomain>
void DumpSubdomainHDF5(const TSubdomain& subdomain,
const int stepID,
const typename TSubdomain::GridType::Real t,
......@@ -440,9 +427,9 @@ void DumpSubdomainHDF5(const TSubdomain& subdomain,
fspace_id = H5Screate_simple(4, dims, NULL);
#ifndef _ON_FERMI_
dataset_id = H5Dcreate(file_id, "data", HDF_REAL, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset_id = H5Dcreate(file_id, "data", get_hdf5_type<hdf5Real>(), fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
#else
dataset_id = H5Dcreate2(file_id, "data", HDF_REAL, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset_id = H5Dcreate2(file_id, "data", get_hdf5_type<hdf5Real>(), fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
#endif
fspace_id = H5Dget_space(dataset_id);
......@@ -456,7 +443,8 @@ void DumpSubdomainHDF5(const TSubdomain& subdomain,
H5Sselect_none(fspace_id);
H5Sselect_none(mspace_id);
}
status = H5Dwrite(dataset_id, HDF_REAL, mspace_id, fspace_id, fapl_id, array_all); if(status<0) H5Eprint1(stdout);
status = H5Dwrite(dataset_id, get_hdf5_type<hdf5Real>(), mspace_id, fspace_id, fapl_id, array_all);
if (status < 0) H5Eprint1(stdout);
status = H5Sclose(mspace_id); if(status<0) H5Eprint1(stdout);
status = H5Sclose(fspace_id); if(status<0) H5Eprint1(stdout);
......
......@@ -15,20 +15,7 @@
#include <sstream>
#include <mpi.h>
#ifdef _USE_HDF_
#include <hdf5.h>
#endif
#ifndef _HDF5_DOUBLE_PRECISION_
#define HDF_REAL H5T_NATIVE_FLOAT
typedef float hdf5Real;
#else
#define HDF_REAL H5T_NATIVE_DOUBLE
typedef double hdf5Real;
#endif
#include "BlockInfo.h"
#include "MeshMap.h"
#include "HDF5Dumper.h"
CUBISM_NAMESPACE_BEGIN
......@@ -152,7 +139,7 @@ namespace SubdomainTypesMPI
// TStreamer::NCHANNELS : Number of data elements (1=Scalar, 3=Vector, 9=Tensor)
// TStreamer::operate : Data access methods for read and write
// TStreamer::getAttributeName : Attribute name of the date ("Scalar", "Vector", "Tensor")
template<typename TStreamer, typename TSubdomain>
template<typename TStreamer, typename hdf5Real, typename TSubdomain>
void DumpSubdomainHDF5MPI(const TSubdomain& subdomain,
const int stepID,
const typename TSubdomain::GridType::Real t,
......@@ -319,9 +306,9 @@ void DumpSubdomainHDF5MPI(const TSubdomain& subdomain,
fspace_id = H5Screate_simple(4, dims, NULL);
#ifndef _ON_FERMI_
dataset_id = H5Dcreate(file_id, "data", HDF_REAL, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset_id = H5Dcreate(file_id, "data", get_hdf5_type<hdf5Real>(), fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
#else
dataset_id = H5Dcreate2(file_id, "data", HDF_REAL, fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
dataset_id = H5Dcreate2(file_id, "data", get_hdf5_type<hdf5Real>(), fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
#endif
fspace_id = H5Dget_space(dataset_id);
......@@ -332,7 +319,8 @@ void DumpSubdomainHDF5MPI(const TSubdomain& subdomain,
H5Sselect_none(fspace_id);
H5Sselect_none(mspace_id);
}
status = H5Dwrite(dataset_id, HDF_REAL, mspace_id, fspace_id, fapl_id, array_all); if(status<0) H5Eprint1(stdout);
status = H5Dwrite(dataset_id, get_hdf5_type<hdf5Real>(), mspace_id, fspace_id, fapl_id, array_all);
if (status < 0) H5Eprint1(stdout);
status = H5Sclose(mspace_id); if(status<0) H5Eprint1(stdout);
status = H5Sclose(fspace_id); if(status<0) H5Eprint1(stdout);
......
......@@ -32,8 +32,10 @@ using namespace std;
// dumpers
#ifndef _HDF5_DOUBLE_PRECISION_
typedef float hdf5Real;
const string prec_string = "4byte";
#else
typedef double hdf5Real;
const string prec_string = "8byte";
#endif
......@@ -91,13 +93,13 @@ int main(int argc, char* argv[])
{
ostringstream fname;
fname << "serial_rank" << myrank << "_hdf5_" << prec_string;
DumpHDF5<MyStreamer>(*(MyGrid*)grid, 0, 0, fname.str());
DumpHDF5<MyStreamer, hdf5Real>(*(MyGrid*)grid, 0, 0, fname.str());
}
{
ostringstream fname;
fname << "mpi_hdf5_" << prec_string;
DumpHDF5_MPI<MyStreamer>(*grid, 0, 0, fname.str());
DumpHDF5_MPI<MyStreamer, hdf5Real>(*grid, 0, 0, fname.str());
}
///////////////////////////////////////////////////////////////////////////
......@@ -124,7 +126,7 @@ int main(int argc, char* argv[])
ostringstream fname;
fname << "serial_rank" << myrank << "_hdf5_slice" << (i+1) << "_" << prec_string;
DumpSliceHDF5<MyStreamer>(slice, 0, 0, fname.str());
DumpSliceHDF5<MyStreamer, hdf5Real>(slice, 0, 0, fname.str());
}
for (size_t i = 0; i < slices_mpi.size(); ++i)
......@@ -133,7 +135,7 @@ int main(int argc, char* argv[])
ostringstream fname;
fname << "mpi_hdf5_slice" << (i+1) << "_" << prec_string;
DumpSliceHDF5MPI<MyStreamer>(slice, 0, 0, fname.str());
DumpSliceHDF5MPI<MyStreamer, hdf5Real>(slice, 0, 0, fname.str());
}
}
///////////////////////////////////////////////////////////////////////////
......@@ -198,7 +200,7 @@ int main(int argc, char* argv[])
ostringstream fname;
fname << "serial_rank" << myrank << "_hdf5_subdomain" << (i+1) << "_" << prec_string;
DumpSubdomainHDF5<MyStreamer>(subdomain, 0, 0, fname.str());
DumpSubdomainHDF5<MyStreamer, hdf5Real>(subdomain, 0, 0, fname.str());
}
for (size_t i = 0; i < subdomains_mpi.size(); ++i)
......@@ -207,7 +209,7 @@ int main(int argc, char* argv[])
ostringstream fname;
fname << "mpi_hdf5_subdomain" << (i+1) << "_" << prec_string;
DumpSubdomainHDF5MPI<MyStreamer>(subdomain, 0, 0, fname.str());
DumpSubdomainHDF5MPI<MyStreamer, hdf5Real>(subdomain, 0, 0, fname.str());
}
}
///////////////////////////////////////////////////////////////////////////
......
Markdown is supported
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