diff --git a/examples/hello/hdf5Writer/helloHDF5Writer.cpp b/examples/hello/hdf5Writer/helloHDF5Writer.cpp index f7ffea4e1d9b1a4d03fecaed0acb76351214802d..71caa0d2b898b1d0e6c202bb9a8e22a38df92786 100644 --- a/examples/hello/hdf5Writer/helloHDF5Writer.cpp +++ b/examples/hello/hdf5Writer/helloHDF5Writer.cpp @@ -65,8 +65,11 @@ int main(int argc, char *argv[]) intCountDim1 = intDim1 - rank * (intDim1 / size); } - std::cout<<" rank="<<rank<<" of "<<size<<", dim1 count: "<<intCountDim1<<", offset: "<<intOffsetDim1<<std::endl; - std::cout<<" intOffsetDim2="<<intOffsetDim2<<" "<<intDim2<<std::endl; + std::cout << " rank=" << rank << " of " << size + << ", dim1 count: " << intCountDim1 + << ", offset: " << intOffsetDim1 << std::endl; + std::cout << " intOffsetDim2=" << intOffsetDim2 << " " << intDim2 + << std::endl; try { // Define variable and local size @@ -100,60 +103,66 @@ int main(int argc, char *argv[]) throw std::ios_base::failure( "ERROR: failed to create HDF5 I/O engine at Open\n"); - int ts = 0; - int totalts = 2; - while (true) { - if (rank == 0) { - std::cout<<" total timesteps: "<<totalts<<" curr: "<<ts<<" th"<<std::endl; - } - HDF5Writer->Write(ioMyDoubles, myDoubles.data() + - doubleVOffset); // Base class Engine - // own the Write<T> - // that will call - // overloaded Write - // from Derived - HDF5Writer->Write(ioMyInts, - myInts.data() + (intOffsetDim1 * intDim2 )); - - HDF5Writer->Write(ioMyCFloats, myCFloats.data() + complexOffset); - HDF5Writer->Write(ioMyCDoubles, myCDoubles.data() + complexOffset); - HDF5Writer->Write(ioMyCLongDoubles, - myCLongDoubles.data() + complexOffset); - ts++; - if (ts >= totalts) { - break; - } - HDF5Writer->Advance(); - } - HDF5Writer->Close(); - - // now read out: - /* - HDF5Settings.SetEngine("HDF5Reader"); - std::cout<<"... Testing a copy of test.h5, [test1.h5] , b/c engine does not decrease name count !! "<<std::endl; - auto HDF5Reader = adios.Open("test1.h5", "r", HDF5Settings); - - //int findts = HDF5Reader->getNumTimeSteps(); - //HDF5Reader->InquireVariableDouble("wrongMyDoubles", true); - HDF5Reader->InquireVariableDouble(ioMyDoubles.m_Name, true); - */ -/* - adios::HDF5Reader myReader(adios, "test.h5", "r", MPI_COMM_WORLD, HDF5Settings); - double values[15]; - -#ifndef NEVER - ts = 0; - while (ts < totalts) { - myReader.ReadMe(ioMyDoubles, values, H5T_NATIVE_DOUBLE); - myReader.Advance(); - ts++; - } - -#else - myReader.ReadMe(ioMyDoubles, values, H5T_NATIVE_DOUBLE); -#endif -*/ + int ts = 0; + int totalts = 2; + while (true) + { + if (rank == 0) + { + std::cout << " total timesteps: " << totalts << " curr: " << ts + << " th" << std::endl; + } + HDF5Writer->Write(ioMyDoubles, + myDoubles.data() + + doubleVOffset); // Base class Engine + // own the Write<T> + // that will call + // overloaded Write + // from Derived + HDF5Writer->Write(ioMyInts, + myInts.data() + (intOffsetDim1 * intDim2)); + + HDF5Writer->Write(ioMyCFloats, myCFloats.data() + complexOffset); + HDF5Writer->Write(ioMyCDoubles, myCDoubles.data() + complexOffset); + HDF5Writer->Write(ioMyCLongDoubles, + myCLongDoubles.data() + complexOffset); + ts++; + if (ts >= totalts) + { + break; + } + HDF5Writer->Advance(); + } + HDF5Writer->Close(); + // now read out: + /* + HDF5Settings.SetEngine("HDF5Reader"); + std::cout<<"... Testing a copy of test.h5, [test1.h5] , b/c engine does + not decrease name count !! "<<std::endl; + auto HDF5Reader = adios.Open("test1.h5", "r", HDF5Settings); + + //int findts = HDF5Reader->getNumTimeSteps(); + //HDF5Reader->InquireVariableDouble("wrongMyDoubles", true); + HDF5Reader->InquireVariableDouble(ioMyDoubles.m_Name, true); + */ + /* + adios::HDF5Reader myReader(adios, "test.h5", "r", + MPI_COMM_WORLD, HDF5Settings); + double values[15]; + + #ifndef NEVER + ts = 0; + while (ts < totalts) { + myReader.ReadMe(ioMyDoubles, values, H5T_NATIVE_DOUBLE); + myReader.Advance(); + ts++; + } + + #else + myReader.ReadMe(ioMyDoubles, values, H5T_NATIVE_DOUBLE); + #endif + */ } catch (std::invalid_argument &e) { diff --git a/source/adios2/ADIOS.cpp b/source/adios2/ADIOS.cpp index b39ebcc397d3ae71718145532630a7b81ee49a84..7144f668bb6ab9851b84f3ff3269c5d72274a3d0 100644 --- a/source/adios2/ADIOS.cpp +++ b/source/adios2/ADIOS.cpp @@ -202,7 +202,7 @@ std::shared_ptr<Engine> ADIOS::Open(const std::string &name, #else throw std::invalid_argument("ERROR: this version didn't compile with " "HDF5 library, can't use HDF5\n"); -#endif +#endif } else { diff --git a/source/adios2/engine/hdf5/HDF5Common.cpp b/source/adios2/engine/hdf5/HDF5Common.cpp index 0862a6babc21f8f2d417c01fbb0d9bc6b970e5b6..8753eaad9f85614f77a6071e314d63be5506fd05 100644 --- a/source/adios2/engine/hdf5/HDF5Common.cpp +++ b/source/adios2/engine/hdf5/HDF5Common.cpp @@ -17,12 +17,10 @@ namespace adios { -#define H5_ERROR std::cout<<"[ADIOS H5 ERROR] " +#define H5_ERROR std::cout << "[ADIOS H5 ERROR] " HDF5Common::HDF5Common() - :_writeMode(false), - _total_timestep(0), - _currentTimeStep(0) +: _writeMode(false), _total_timestep(0), _currentTimeStep(0) { DefH5T_COMPLEX_FLOAT = H5Tcreate(H5T_COMPOUND, sizeof(std::complex<float>)); H5Tinsert(DefH5T_COMPLEX_FLOAT, "freal", 0, H5T_NATIVE_FLOAT); @@ -39,88 +37,95 @@ HDF5Common::HDF5Common() H5Tcreate(H5T_COMPOUND, sizeof(std::complex<long double>)); H5Tinsert(DefH5T_COMPLEX_LongDOUBLE, "ldouble real", 0, H5T_NATIVE_LDOUBLE); H5Tinsert(DefH5T_COMPLEX_LongDOUBLE, "ldouble img", - H5Tget_size(H5T_NATIVE_LDOUBLE), H5T_NATIVE_LDOUBLE); + H5Tget_size(H5T_NATIVE_LDOUBLE), H5T_NATIVE_LDOUBLE); } - -void HDF5Common::H5_Init(const std::string name, MPI_Comm m_MPIComm, bool toWrite) +void HDF5Common::H5_Init(const std::string name, MPI_Comm m_MPIComm, + bool toWrite) { _writeMode = toWrite; // _plist_id = H5Pcreate(H5P_FILE_ACCESS); - + #ifdef ADIOS2_HAVE_MPI H5Pset_fapl_mpio(_plist_id, m_MPIComm, MPI_INFO_NULL); -#endif +#endif std::string ts0 = "/TimeStep0"; - if (toWrite) { - /* - * Create a new file collectively and release property list identifier. - */ - _file_id = H5Fcreate(name.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, _plist_id); - if (_file_id >= 0) - { - _group_id = - H5Gcreate2(_file_id, ts0.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - } - } else { - // read a file collectively - _file_id = H5Fopen(name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); - if (_file_id >= 0) - { - _group_id = H5Gopen(_file_id, ts0.c_str(), H5P_DEFAULT); - } + if (toWrite) + { + /* + * Create a new file collectively and release property list identifier. + */ + _file_id = + H5Fcreate(name.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, _plist_id); + if (_file_id >= 0) + { + _group_id = H5Gcreate2(_file_id, ts0.c_str(), H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT); + } + } + else + { + // read a file collectively + _file_id = H5Fopen(name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); + if (_file_id >= 0) + { + _group_id = H5Gopen(_file_id, ts0.c_str(), H5P_DEFAULT); + } } H5Pclose(_plist_id); } - + HDF5Common::~HDF5Common() {} void HDF5Common::WriteTimeSteps() { - if (_file_id < 0) - { - //std::cerr<<"[ADIOS HDF5Error]: Invalid file to record timestep to."<<std::endl; - H5_ERROR<<"Invalid file to record timestep to."<<std::endl; - return; - } + if (_file_id < 0) + { + // std::cerr<<"[ADIOS HDF5Error]: Invalid file to record timestep + // to."<<std::endl; + H5_ERROR << "Invalid file to record timestep to." << std::endl; + return; + } - hid_t s = H5Screate(H5S_SCALAR); + hid_t s = H5Screate(H5S_SCALAR); - hid_t attr = H5Acreate(_file_id, "NumTimeSteps", H5T_NATIVE_UINT, s, H5P_DEFAULT, H5P_DEFAULT); - uint totalts = _currentTimeStep+1; - H5Awrite(attr,H5T_NATIVE_UINT,&totalts); + hid_t attr = H5Acreate(_file_id, "NumTimeSteps", H5T_NATIVE_UINT, s, + H5P_DEFAULT, H5P_DEFAULT); + uint totalts = _currentTimeStep + 1; + H5Awrite(attr, H5T_NATIVE_UINT, &totalts); - H5Sclose(s); - H5Aclose(attr); + H5Sclose(s); + H5Aclose(attr); } - int HDF5Common::GetNumTimeSteps() { - if (_file_id < 0) - { - std::cerr<<"[ADIOS HDF5Error]: Invalid file to read timestep attribute."<<std::endl; - return -1; - } - - if (_total_timestep <= 0) { - hid_t attr = H5Aopen(_file_id, "NumTimeSteps", H5P_DEFAULT); - - H5Aread(attr,H5T_NATIVE_UINT, &_total_timestep); - H5Aclose(attr); - } + if (_file_id < 0) + { + std::cerr + << "[ADIOS HDF5Error]: Invalid file to read timestep attribute." + << std::endl; + return -1; + } - return _total_timestep; -} + if (_total_timestep <= 0) + { + hid_t attr = H5Aopen(_file_id, "NumTimeSteps", H5P_DEFAULT); + H5Aread(attr, H5T_NATIVE_UINT, &_total_timestep); + H5Aclose(attr); + } + return _total_timestep; +} -void HDF5Common::H5_Close() { +void HDF5Common::H5_Close() +{ WriteTimeSteps(); H5Gclose(_group_id); @@ -129,28 +134,28 @@ void HDF5Common::H5_Close() { void HDF5Common::H5_Advance(int totalts) { - _currentTimeStep++; - if (_currentTimeStep > 0) { - H5Gclose(_group_id); - } + _currentTimeStep++; + if (_currentTimeStep > 0) + { + H5Gclose(_group_id); + } - std::string tsname="/TimeStep"; - tsname.append(std::to_string(_currentTimeStep)); + std::string tsname = "/TimeStep"; + tsname.append(std::to_string(_currentTimeStep)); - if (_writeMode) { - _group_id = - H5Gcreate2(_file_id, tsname.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - } else { - if ((totalts > 0) && (totalts <= _currentTimeStep)) + if (_writeMode) + { + _group_id = H5Gcreate2(_file_id, tsname.c_str(), H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT); + } + else { - return; + if ((totalts > 0) && (totalts <= _currentTimeStep)) + { + return; + } + // std::cout<<" ... current group "<<tsname.c_str()<<std::endl; + _group_id = H5Gopen(_file_id, tsname.c_str(), H5P_DEFAULT); } - //std::cout<<" ... current group "<<tsname.c_str()<<std::endl; - _group_id = - H5Gopen(_file_id, tsname.c_str(), H5P_DEFAULT); - } } - - - } diff --git a/source/adios2/engine/hdf5/HDF5Common.h b/source/adios2/engine/hdf5/HDF5Common.h index d12994c1cdb24a08ee3c9741c007527812e91bc4..df0c173e4478e6e1cfb196b292a0032df84aa44b 100644 --- a/source/adios2/engine/hdf5/HDF5Common.h +++ b/source/adios2/engine/hdf5/HDF5Common.h @@ -11,23 +11,23 @@ #ifndef HDF5_COMMON_P_H_ #define HDF5_COMMON_P_H_ -#include "adios2/core/Engine.h" #include "adios2/ADIOSMPICommOnly.h" +#include "adios2/core/Engine.h" #include <hdf5.h> namespace adios { -class HDF5Common +class HDF5Common { public: /** - * Constructor for HDF5 file + * Constructor for HDF5 file * @param file name */ - HDF5Common(); + HDF5Common(); virtual ~HDF5Common(); @@ -35,19 +35,20 @@ public: void H5_Close(); void H5_Advance(int totalts); - int GetNumTimeSteps(); + int GetNumTimeSteps(); void WriteTimeSteps(); - hid_t _plist_id, _file_id; + hid_t _plist_id, _file_id; hid_t _group_id; - + hid_t DefH5T_COMPLEX_DOUBLE; hid_t DefH5T_COMPLEX_FLOAT; hid_t DefH5T_COMPLEX_LongDOUBLE; - int _currentTimeStep; - private: - void H5_AdvanceWrite(); + int _currentTimeStep; + +private: + void H5_AdvanceWrite(); bool _writeMode; int _total_timestep; }; diff --git a/source/adios2/engine/hdf5/HDF5ReaderP.cpp b/source/adios2/engine/hdf5/HDF5ReaderP.cpp index 9aa7f7b76fb89c95cedbe0efd9656ea263e97352..a70a3c79ca0b72b7964526f11ae6a3ca669ed917 100644 --- a/source/adios2/engine/hdf5/HDF5ReaderP.cpp +++ b/source/adios2/engine/hdf5/HDF5ReaderP.cpp @@ -18,21 +18,19 @@ namespace adios HDF5Reader::HDF5Reader(ADIOS &adios, const std::string name, const std::string accessMode, MPI_Comm mpiComm, const Method &method) -: Engine(adios, "HDF5Reader", name, accessMode, mpiComm, - method, +: Engine(adios, "HDF5Reader", name, accessMode, mpiComm, method, " HDF5Reader constructor (or call to ADIOS Open).\n") { - Init(); - MPI_Comm_rank(mpiComm, &_mpi_rank); - MPI_Comm_size(mpiComm, &_mpi_size); - + Init(); + MPI_Comm_rank(mpiComm, &_mpi_rank); + MPI_Comm_size(mpiComm, &_mpi_size); } HDF5Reader::~HDF5Reader() {} void HDF5Reader::Init() { - if (m_AccessMode != "r" && m_AccessMode != "read") + if (m_AccessMode != "r" && m_AccessMode != "read") { throw std::invalid_argument( "ERROR: HDF5Reader doesn't support access mode " + m_AccessMode + @@ -43,231 +41,268 @@ void HDF5Reader::Init() _H5File.GetNumTimeSteps(); } - -Variable<void> * HDF5Reader::InquireVariable(const std::string &variableName, - const bool readIn ) +Variable<void> *HDF5Reader::InquireVariable(const std::string &variableName, + const bool readIn) { - std::cout<<"Not implemented: HDF5Reder::InquireVariable()"<<std::endl; + std::cout << "Not implemented: HDF5Reder::InquireVariable()" << std::endl; } -Variable<char> * HDF5Reader::InquireVariableChar(const std::string &variableName, - const bool readIn ) -{} - -Variable<unsigned char> * HDF5Reader::InquireVariableUChar(const std::string &variableName, - const bool readIn ) -{} - -Variable<short> * HDF5Reader::InquireVariableShort(const std::string &variableName, - const bool readIn ) -{} +Variable<char> *HDF5Reader::InquireVariableChar(const std::string &variableName, + const bool readIn) +{ +} -Variable<unsigned short> * HDF5Reader::InquireVariableUShort(const std::string &variableName, - const bool readIn) -{} +Variable<unsigned char> * +HDF5Reader::InquireVariableUChar(const std::string &variableName, + const bool readIn) +{ +} +Variable<short> * +HDF5Reader::InquireVariableShort(const std::string &variableName, + const bool readIn) +{ +} +Variable<unsigned short> * +HDF5Reader::InquireVariableUShort(const std::string &variableName, + const bool readIn) +{ +} Variable<int> *HDF5Reader::InquireVariableInt(const std::string &variableName, - const bool) -{} + const bool) +{ +} -Variable<unsigned int> *HDF5Reader::InquireVariableUInt(const std::string &variableName, - const bool) -{} +Variable<unsigned int> * +HDF5Reader::InquireVariableUInt(const std::string &variableName, const bool) +{ +} -Variable<long int> *HDF5Reader::InquireVariableLInt(const std::string &variableName, - const bool) -{} +Variable<long int> * +HDF5Reader::InquireVariableLInt(const std::string &variableName, const bool) +{ +} Variable<unsigned long int> * -HDF5Reader::InquireVariableULInt(const std::string &variableName, - const bool) -{} +HDF5Reader::InquireVariableULInt(const std::string &variableName, const bool) +{ +} Variable<long long int> * -HDF5Reader::InquireVariableLLInt(const std::string &variableName, - const bool) -{} +HDF5Reader::InquireVariableLLInt(const std::string &variableName, const bool) +{ +} -Variable<unsigned long long int> * -HDF5Reader::InquireVariableULLInt(const std::string &variableName, - const bool) -{} +Variable<unsigned long long int> * +HDF5Reader::InquireVariableULLInt(const std::string &variableName, const bool) +{ +} -Variable<float> *HDF5Reader::InquireVariableFloat(const std::string &variableName, - const bool) -{} +Variable<float> * +HDF5Reader::InquireVariableFloat(const std::string &variableName, const bool) +{ +} -Variable<double> *HDF5Reader::InquireVariableDouble(const std::string &variableName, - const bool) +Variable<double> * +HDF5Reader::InquireVariableDouble(const std::string &variableName, const bool) { - - if (_mpi_rank == 0) { - std::cout<<" ... reading var: "<<variableName<<std::endl; - } - int totalts = _H5File.GetNumTimeSteps(); - - if (_mpi_rank == 0) { - std::cout<<" ... I saw total timesteps: "<<totalts<<std::endl; - } - - while (true) { - double values[1]; - UseHDFRead(variableName, values, H5T_NATIVE_DOUBLE); - Variable<double> v = m_ADIOS.DefineVariable<double>("junk", adios::Dims{8}); - ReadMe(v, values, H5T_NATIVE_DOUBLE); - if (_H5File._currentTimeStep >= totalts-1) { - break; + + if (_mpi_rank == 0) + { + std::cout << " ... reading var: " << variableName << std::endl; + } + int totalts = _H5File.GetNumTimeSteps(); + + if (_mpi_rank == 0) + { + std::cout << " ... I saw total timesteps: " << totalts << std::endl; + } + + while (true) + { + double values[1]; + UseHDFRead(variableName, values, H5T_NATIVE_DOUBLE); + Variable<double> v = + m_ADIOS.DefineVariable<double>("junk", adios::Dims{8}); + ReadMe(v, values, H5T_NATIVE_DOUBLE); + if (_H5File._currentTimeStep >= totalts - 1) + { + break; + } + _H5File.H5_Advance(totalts); } - _H5File.H5_Advance(totalts); - } } -Variable<long double> * HDF5Reader::InquireVariableLDouble(const std::string &variableName, - const bool) -{} +Variable<long double> * +HDF5Reader::InquireVariableLDouble(const std::string &variableName, const bool) +{ +} -Variable<std::complex<float>> * HDF5Reader::InquireVariableCFloat(const std::string &variableName, - const bool) -{} +Variable<std::complex<float>> * +HDF5Reader::InquireVariableCFloat(const std::string &variableName, const bool) +{ +} -Variable<std::complex<double>> * HDF5Reader::InquireVariableCDouble(const std::string &variableName, - const bool) -{} +Variable<std::complex<double>> * +HDF5Reader::InquireVariableCDouble(const std::string &variableName, const bool) +{ +} -Variable<std::complex<long double>>* HDF5Reader::InquireVariableCLDouble(const std::string &variableName, - const bool) -{} +Variable<std::complex<long double>> * +HDF5Reader::InquireVariableCLDouble(const std::string &variableName, const bool) +{ +} -VariableCompound * HDF5Reader::InquireVariableCompound(const std::string &variableName, - const bool readIn) -{} +VariableCompound * +HDF5Reader::InquireVariableCompound(const std::string &variableName, + const bool readIn) +{ +} template <class T> void HDF5Reader::ReadMe(Variable<T> variable, T *data_array, hid_t h5type) { - hid_t datasetID = H5Dopen(_H5File._group_id, variable.m_Name.c_str(), H5P_DEFAULT); + hid_t datasetID = + H5Dopen(_H5File._group_id, variable.m_Name.c_str(), H5P_DEFAULT); - if (_mpi_rank == 0) { - std::cout<<" hdf5 reading variable: "<<variable.m_Name<<" timestep: "<<_H5File._currentTimeStep<<std::endl; - } - - if (datasetID < 0) { - return; - } + if (_mpi_rank == 0) + { + std::cout << " hdf5 reading variable: " << variable.m_Name + << " timestep: " << _H5File._currentTimeStep << std::endl; + } - hid_t filespace = H5Dget_space(datasetID); + if (datasetID < 0) + { + return; + } - if (filespace < 0) { - return; - } + hid_t filespace = H5Dget_space(datasetID); - int ndims = variable.m_GlobalDimensions.size(); - std::vector<hsize_t> count, offset, stride; + if (filespace < 0) + { + return; + } - int elementsRead = 1; - for (int i = 0; i < ndims; i++) + int ndims = variable.m_GlobalDimensions.size(); + std::vector<hsize_t> count, offset, stride; + + int elementsRead = 1; + for (int i = 0; i < ndims; i++) { - count.push_back(variable.m_LocalDimensions[i]); - offset.push_back(variable.m_Offsets[i]); - stride.push_back(1); - elementsRead *= variable.m_LocalDimensions[i]; + count.push_back(variable.m_LocalDimensions[i]); + offset.push_back(variable.m_Offsets[i]); + stride.push_back(1); + elementsRead *= variable.m_LocalDimensions[i]; } - hid_t ret=H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset.data(), stride.data(), count.data(), NULL); - if (ret < 0) { - return; - } + hid_t ret = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset.data(), + stride.data(), count.data(), NULL); + if (ret < 0) + { + return; + } - hid_t mem_dataspace = H5Screate_simple (ndims, count.data(), NULL); + hid_t mem_dataspace = H5Screate_simple(ndims, count.data(), NULL); - //T data_array[elementsRead]; - ret = H5Dread(datasetID, h5type, mem_dataspace, filespace, H5P_DEFAULT, data_array); + // T data_array[elementsRead]; + ret = H5Dread(datasetID, h5type, mem_dataspace, filespace, H5P_DEFAULT, + data_array); - for (int i=0; i<elementsRead; i++) { - std::cout<<"... ts "<<_H5File._currentTimeStep<<", "<<data_array[i]<<std::endl; - } + for (int i = 0; i < elementsRead; i++) + { + std::cout << "... ts " << _H5File._currentTimeStep << ", " + << data_array[i] << std::endl; + } - H5Sclose(mem_dataspace); + H5Sclose(mem_dataspace); - H5Sclose(filespace); - H5Dclose(datasetID); + H5Sclose(filespace); + H5Dclose(datasetID); } - - -template<class T> -void HDF5Reader::UseHDFRead(const std::string& variableName, T* values, hid_t h5type) +template <class T> +void HDF5Reader::UseHDFRead(const std::string &variableName, T *values, + hid_t h5type) { - hid_t datasetID = H5Dopen(_H5File._group_id, variableName.c_str(), H5P_DEFAULT); - if (_mpi_rank == 0) { - std::cout<<" opened to read: "<<variableName<<std::endl; - } - - if (datasetID < 0) { - return; - } - hid_t filespace = H5Dget_space(datasetID); - - if (filespace < 0) { - return; - } - int ndims = H5Sget_simple_extent_ndims(filespace); - hsize_t dims[ndims]; - herr_t status_n = H5Sget_simple_extent_dims(filespace, dims, NULL); - - hsize_t start[ndims]={0}, count[ndims]={0}, stride[ndims]={1}; - - int totalElements = 1; - for (int i=0; i<ndims; i++) { - std::cout<<" ["<<i<<"] th dimension: "<<dims[i]<<std::endl; - count[i] = dims[i]; - totalElements *= dims[i]; - } - - start[0] = _mpi_rank * dims[0]/_mpi_size; - count[0] = dims[0]/_mpi_size; - if (_mpi_rank == _mpi_size -1) { - count[0] = dims[0] - count[0]*(_mpi_size - 1); - std::cout<<" rank = "<<_mpi_rank<<", count="<<count[0]<<std::endl; - } - - hid_t ret=H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, stride, count, NULL); - if (ret < 0) { - return; - } - - hid_t mem_dataspace = H5Screate_simple (ndims, count, NULL); - - int elementsRead = 1; - for (int i=0; i<ndims; i++) { - elementsRead *= count[i]; - } - - T data_array[elementsRead]; - ret = H5Dread(datasetID, h5type, mem_dataspace, filespace, H5P_DEFAULT, data_array); - - for (int i=0; i<elementsRead; i++) { - std::cout<<"... rank "<<_mpi_rank<<" , "<<data_array[i]<<std::endl; - } - - H5Sclose(mem_dataspace); - - H5Sclose(filespace); - H5Dclose(datasetID); + hid_t datasetID = + H5Dopen(_H5File._group_id, variableName.c_str(), H5P_DEFAULT); + if (_mpi_rank == 0) + { + std::cout << " opened to read: " << variableName << std::endl; + } + + if (datasetID < 0) + { + return; + } + hid_t filespace = H5Dget_space(datasetID); + + if (filespace < 0) + { + return; + } + int ndims = H5Sget_simple_extent_ndims(filespace); + hsize_t dims[ndims]; + herr_t status_n = H5Sget_simple_extent_dims(filespace, dims, NULL); + + hsize_t start[ndims] = {0}, count[ndims] = {0}, stride[ndims] = {1}; + + int totalElements = 1; + for (int i = 0; i < ndims; i++) + { + std::cout << " [" << i << "] th dimension: " << dims[i] << std::endl; + count[i] = dims[i]; + totalElements *= dims[i]; + } + + start[0] = _mpi_rank * dims[0] / _mpi_size; + count[0] = dims[0] / _mpi_size; + if (_mpi_rank == _mpi_size - 1) + { + count[0] = dims[0] - count[0] * (_mpi_size - 1); + std::cout << " rank = " << _mpi_rank << ", count=" << count[0] + << std::endl; + } + + hid_t ret = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, stride, + count, NULL); + if (ret < 0) + { + return; + } + + hid_t mem_dataspace = H5Screate_simple(ndims, count, NULL); + + int elementsRead = 1; + for (int i = 0; i < ndims; i++) + { + elementsRead *= count[i]; + } + + T data_array[elementsRead]; + ret = H5Dread(datasetID, h5type, mem_dataspace, filespace, H5P_DEFAULT, + data_array); + + for (int i = 0; i < elementsRead; i++) + { + std::cout << "... rank " << _mpi_rank << " , " << data_array[i] + << std::endl; + } + + H5Sclose(mem_dataspace); + + H5Sclose(filespace); + H5Dclose(datasetID); } - void HDF5Reader::Advance(float timeout_sec) { - int totalts = _H5File.GetNumTimeSteps(); - _H5File.H5_Advance(totalts); + int totalts = _H5File.GetNumTimeSteps(); + _H5File.H5_Advance(totalts); } -void HDF5Reader::Close(const int transportIndex) -{ - _H5File.H5_Close(); -} +void HDF5Reader::Close(const int transportIndex) { _H5File.H5_Close(); } } // end namespace adios diff --git a/source/adios2/engine/hdf5/HDF5ReaderP.h b/source/adios2/engine/hdf5/HDF5ReaderP.h index 5298be8f65681a18bf4978c4ad6851bd07e84888..d1ed06863ab80d29cbf5555bfccebffa099ac80b 100644 --- a/source/adios2/engine/hdf5/HDF5ReaderP.h +++ b/source/adios2/engine/hdf5/HDF5ReaderP.h @@ -13,8 +13,8 @@ #include "HDF5Common.h" -#include "adios2/core/Engine.h" #include "adios2/ADIOSMPICommOnly.h" +#include "adios2/core/Engine.h" namespace adios { @@ -24,15 +24,15 @@ class HDF5Reader : public Engine public: /** - * Constructor for single HDF5 reader engine, reads from HDF5 format + * Constructor for single HDF5 reader engine, reads from HDF5 format * @param name unique name given to the engine * @param accessMode * @param mpiComm * @param method */ HDF5Reader(ADIOS &adios, const std::string name, - const std::string accessMode, MPI_Comm mpiComm, - const Method &method); + const std::string accessMode, MPI_Comm mpiComm, + const Method &method); virtual ~HDF5Reader(); @@ -40,7 +40,7 @@ public: const bool readIn = true); Variable<char> *InquireVariableChar(const std::string &variableName, - const bool readIn = true); + const bool readIn = true); Variable<unsigned char> * InquireVariableUChar(const std::string &variableName, @@ -108,13 +108,11 @@ public: void Close(const int transportIndex = -1); - template <class T> - void UseHDFRead(const std::string& variableName, T *values, hid_t h5type); - - template <class T> - void ReadMe(Variable<T> variable, T *values, hid_t h5type); + void UseHDFRead(const std::string &variableName, T *values, hid_t h5type); + template <class T> + void ReadMe(Variable<T> variable, T *values, hid_t h5type); private: HDF5Common _H5File; diff --git a/source/adios2/engine/hdf5/HDF5WriterP.cpp b/source/adios2/engine/hdf5/HDF5WriterP.cpp index befa9e1a9bea637a0ccd253ec486bad200428949..18aeb1a0d6cdf498965a99a6d1425cb227e2fdab 100644 --- a/source/adios2/engine/hdf5/HDF5WriterP.cpp +++ b/source/adios2/engine/hdf5/HDF5WriterP.cpp @@ -25,7 +25,7 @@ HDF5Writer::HDF5Writer(ADIOS &adios, const std::string name, " HDF5Writer constructor (or call to ADIOS Open).\n"), m_Buffer(m_DebugMode) { - Init(); + Init(); } HDF5Writer::~HDF5Writer() {} @@ -239,26 +239,25 @@ void HDF5Writer::Write(const std::string variableName, values, _H5File.DefH5T_COMPLEX_LongDOUBLE); } -void HDF5Writer::Advance(float timeout_sec) -{ - _H5File.H5_Advance(0); -} +void HDF5Writer::Advance(float timeout_sec) { _H5File.H5_Advance(0); } void HDF5Writer::Close(const int transportIndex) { - /* - //void* hi = H5Iobject_verify(H5S_SCALAR, H5I_DATASPACE); - - hid_t s = H5Screate(H5S_SCALAR); - //hid_t attr = H5Acreate(_H5File._group_id, "NumTimeSteps", H5T_NATIVE_UINT, s, H5P_DEFAULT, H5P_DEFAULT); - hid_t attr = H5Acreate(_H5File._file_id, "NumTimeSteps", H5T_NATIVE_UINT, s, H5P_DEFAULT, H5P_DEFAULT); - uint totalts = _H5File._currentTimeStep+1; - H5Awrite(attr,H5T_NATIVE_UINT,&totalts); - - H5Sclose(s); - H5Aclose(attr); - */ - _H5File.H5_Close(); + /* + //void* hi = H5Iobject_verify(H5S_SCALAR, H5I_DATASPACE); + + hid_t s = H5Screate(H5S_SCALAR); + //hid_t attr = H5Acreate(_H5File._group_id, "NumTimeSteps", H5T_NATIVE_UINT, + s, H5P_DEFAULT, H5P_DEFAULT); + hid_t attr = H5Acreate(_H5File._file_id, "NumTimeSteps", H5T_NATIVE_UINT, s, + H5P_DEFAULT, H5P_DEFAULT); + uint totalts = _H5File._currentTimeStep+1; + H5Awrite(attr,H5T_NATIVE_UINT,&totalts); + + H5Sclose(s); + H5Aclose(attr); + */ + _H5File.H5_Close(); } template <class T> @@ -294,8 +293,9 @@ void HDF5Writer::UseHDFWrite(Variable<T> &variable, const T *values, hid_t _filespace = H5Screate_simple(dimSize, dimsf.data(), NULL); - hid_t _dset_id = H5Dcreate(_H5File._group_id, variable.m_Name.c_str(), h5type, _filespace, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + hid_t _dset_id = + H5Dcreate(_H5File._group_id, variable.m_Name.c_str(), h5type, + _filespace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); // H5Sclose(_filespace); hid_t _memspace = H5Screate_simple(dimSize, count.data(), NULL); diff --git a/source/adios2/engine/hdf5/HDF5WriterP.h b/source/adios2/engine/hdf5/HDF5WriterP.h index 6dd5c697249f8f6369d7bf735c39717ef7909192..3141cca753a27f7060c343f9f034c3f0a0d9fe51 100644 --- a/source/adios2/engine/hdf5/HDF5WriterP.h +++ b/source/adios2/engine/hdf5/HDF5WriterP.h @@ -29,7 +29,7 @@ class HDF5Writer : public Engine public: /** - * Constructor for HDF5 writer engine, writes in hdf5 format + * Constructor for HDF5 writer engine, writes in hdf5 format * @param name unique name given to the engine * @param accessMode * @param mpiComm @@ -94,7 +94,7 @@ private: capsule::STLVector m_Buffer; void Init(); - + HDF5Common _H5File; /* @@ -102,11 +102,11 @@ private: hid_t _memspace, _filespace; hid_t _group_id; - + hid_t DefH5T_COMPLEX_DOUBLE; hid_t DefH5T_COMPLEX_FLOAT; hid_t DefH5T_COMPLEX_LongDOUBLE; - + int _currentTimeStep; */ template <class T>