diff --git a/examples/hello/hdf5Writer/helloHDF5Writer.cpp b/examples/hello/hdf5Writer/helloHDF5Writer.cpp index e666f96e5882d7bd02fb106bea27be036d7183e0..65e8fe86d9db032f70b289aa068d44c945c360e8 100644 --- a/examples/hello/hdf5Writer/helloHDF5Writer.cpp +++ b/examples/hello/hdf5Writer/helloHDF5Writer.cpp @@ -140,20 +140,27 @@ int main(int argc, char *argv[]) //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 + adios::HDF5Common myReader; + myReader.H5_Init("test.h5", MPI_COMM_WORLD, false); + double values[15]; ts = 0; + while (ts < totalts) { - myReader.ReadMe(ioMyDoubles, values, H5T_NATIVE_DOUBLE); - myReader.Advance(); + //myReader.ReadMe(ioMyDoubles, values, H5T_NATIVE_DOUBLE); + myReader.H5_Advance(totalts); ts++; } #else + /* + adios::HDF5Reader myReader(adios, "test.h5", "r", MPI_COMM_WORLD, HDF5Settings); + double values[15]; + myReader.ReadMe(ioMyDoubles, values, H5T_NATIVE_DOUBLE); myReader.Close(); + */ #endif } diff --git a/source/adios2/engine/hdf5/HDF5Common.cpp b/source/adios2/engine/hdf5/HDF5Common.cpp index 00eeee36ec5c758ccf244845fcdf9512f11ea92f..d931686294386adfe9231a5dac0f0ad63820d14e 100644 --- a/source/adios2/engine/hdf5/HDF5Common.cpp +++ b/source/adios2/engine/hdf5/HDF5Common.cpp @@ -12,7 +12,7 @@ #include <iostream> //needs to go away, this is just for demo purposes -#include "adios2/ADIOSMPI.h" +//#include "adios2/ADIOSMPI.h" namespace adios { @@ -197,4 +197,96 @@ void HDF5Common::CheckWriteGroup() m_Group_id = H5Gcreate2(m_File_id, tsname.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); } + + + +template <class T> +void HDF5Common::ReadMe(Variable<T> &variable, T *data_array, hid_t h5type) +{ + hid_t datasetID = + H5Dopen(m_Group_id, variable.m_Name.c_str(), H5P_DEFAULT); + +#ifdef NEVER + if (_mpi_rank == 0) + { + std::cout << " hdf5 reading variable: " << variable.m_Name + << " timestep: " << m_CurrentTimeStep << std::endl; + } +#endif + + if (datasetID < 0) + { + return; + } + + hid_t filespace = H5Dget_space(datasetID); + + if (filespace < 0) + { + return; + } + + const int ndims = H5Sget_simple_extent_ndims(filespace); + hsize_t dims[ndims]; + H5Sget_simple_extent_dims(filespace, dims, NULL); + + // int dims_in = variable.m_GlobalDimensions.size(); + variable.m_GlobalDimensions.clear(); + for (int i = 0; i < ndims; i++) + { + variable.m_GlobalDimensions.push_back(dims[i]); + } + + std::vector<hsize_t> count, offset, stride; + + int elementsRead = 1; + for (int i = 0; i < ndims; i++) + { + if (variable.m_LocalDimensions.size() == ndims) + { + count.push_back(variable.m_LocalDimensions[i]); + elementsRead *= variable.m_LocalDimensions[i]; + } + else + { + count.push_back(variable.m_GlobalDimensions[i]); + elementsRead *= variable.m_GlobalDimensions[i]; + } + + if (variable.m_Offsets.size() == ndims) + { + offset.push_back(variable.m_Offsets[i]); + } + else + { + offset.push_back(0); + } + + stride.push_back(1); + } + + 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); + + // 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 " << m_CurrentTimeStep << ", " + << data_array[i] << std::endl; + } + */ + H5Sclose(mem_dataspace); + + H5Sclose(filespace); + H5Dclose(datasetID); +} } diff --git a/source/adios2/engine/hdf5/HDF5Common.h b/source/adios2/engine/hdf5/HDF5Common.h index bd69126ce60f8ea43dc0b40c771d9a234223f970..876c76fe2e22e92d9e0fdf4c3fef84bd0c41eb05 100644 --- a/source/adios2/engine/hdf5/HDF5Common.h +++ b/source/adios2/engine/hdf5/HDF5Common.h @@ -11,7 +11,7 @@ #ifndef HDF5_COMMON_P_H_ #define HDF5_COMMON_P_H_ -#include "adios2/ADIOSMPICommOnly.h" +//#include "adios2/ADIOSMPICommOnly.h" #include "adios2/core/Engine.h" #include <hdf5.h> @@ -38,6 +38,11 @@ public: int GetNumTimeSteps(); void WriteTimeSteps(); + template <class T> + void ReadMe(Variable<T> &variable, T *data_array, hid_t h5type); + + //void ReadFromHDF5(const char* name, void* data_array); + hid_t m_Plist_id, m_File_id; hid_t m_Group_id; @@ -50,7 +55,7 @@ public: void CheckWriteGroup(); private: - void H5_AdvanceWrite(); + //void H5_AdvanceWrite(); bool m_WriteMode; int m_Total_timestep; }; diff --git a/source/adios2/engine/hdf5/HDF5ReaderP.cpp b/source/adios2/engine/hdf5/HDF5ReaderP.cpp index 3f12421061539abc9088f2dc5471642f7075aff2..8e7a01952a4869bc0eee2ce005e93e5374d417e1 100644 --- a/source/adios2/engine/hdf5/HDF5ReaderP.cpp +++ b/source/adios2/engine/hdf5/HDF5ReaderP.cpp @@ -149,52 +149,52 @@ HDF5Reader::InquireVariableDouble(const std::string &variableName, const bool) UseHDFRead(variableName, values, H5T_NATIVE_DOUBLE); Variable<double> v = m_ADIOS.DefineVariable<double>("junk", adios::Dims{8}); - ReadMe(v, values, H5T_NATIVE_DOUBLE); + _H5File.ReadMe(v, values, H5T_NATIVE_DOUBLE); Variable<char> v1 = m_ADIOS.DefineVariable<char>("junk1", adios::Dims{8}); char vv1[1]; - ReadMe(v1, vv1, H5T_NATIVE_CHAR); + _H5File.ReadMe(v1, vv1, H5T_NATIVE_CHAR); Variable<unsigned char> v2 = m_ADIOS.DefineVariable<unsigned char>("junk2", adios::Dims{8}); unsigned char vv2[1]; - ReadMe(v2, vv2, H5T_NATIVE_UCHAR); + _H5File.ReadMe(v2, vv2, H5T_NATIVE_UCHAR); Variable<unsigned int> v3 = m_ADIOS.DefineVariable<unsigned int>("junk3", adios::Dims{8}); unsigned int vv3[1]; - ReadMe(v3, vv3, H5T_NATIVE_UINT); + _H5File.ReadMe(v3, vv3, H5T_NATIVE_UINT); Variable<int> v4 = m_ADIOS.DefineVariable<int>("junk4", adios::Dims{8}); int vv4[1]; - ReadMe(v4, vv4, H5T_NATIVE_INT); + _H5File.ReadMe(v4, vv4, H5T_NATIVE_INT); Variable<float> v5 = m_ADIOS.DefineVariable<float>("junk5", adios::Dims{8}); float vv5[1]; - ReadMe(v5, vv5, H5T_NATIVE_FLOAT); + _H5File.ReadMe(v5, vv5, H5T_NATIVE_FLOAT); Variable<short> v6 = m_ADIOS.DefineVariable<short>("junk6", adios::Dims{8}); short vv6[1]; - ReadMe(v6, vv6, H5T_NATIVE_SHORT); + _H5File.ReadMe(v6, vv6, H5T_NATIVE_SHORT); Variable<unsigned short> v7 = m_ADIOS.DefineVariable<unsigned short>("junk7", adios::Dims{8}); unsigned short vv7[1]; - ReadMe(v7, vv7, H5T_NATIVE_USHORT); + _H5File.ReadMe(v7, vv7, H5T_NATIVE_USHORT); Variable<long> v8 = m_ADIOS.DefineVariable<long>("junk8", adios::Dims{8}); long vv8[1]; - ReadMe(v8, vv8, H5T_NATIVE_LONG); + _H5File.ReadMe(v8, vv8, H5T_NATIVE_LONG); Variable<unsigned long> v9 = m_ADIOS.DefineVariable<unsigned long>("junk9", adios::Dims{8}); unsigned long vv9[1]; - ReadMe(v9, vv9, H5T_NATIVE_ULONG); + _H5File.ReadMe(v9, vv9, H5T_NATIVE_ULONG); if (_H5File.m_CurrentTimeStep >= totalts - 1) { @@ -236,95 +236,6 @@ HDF5Reader::InquireVariableCompound(const std::string &variableName, return NULL; } -template <class T> -void HDF5Reader::ReadMe(Variable<T> &variable, T *data_array, hid_t h5type) -{ - hid_t datasetID = - H5Dopen(_H5File.m_Group_id, variable.m_Name.c_str(), H5P_DEFAULT); - -#ifdef NEVER - if (_mpi_rank == 0) - { - std::cout << " hdf5 reading variable: " << variable.m_Name - << " timestep: " << _H5File.m_CurrentTimeStep << std::endl; - } -#endif - - if (datasetID < 0) - { - return; - } - - hid_t filespace = H5Dget_space(datasetID); - - if (filespace < 0) - { - return; - } - - const int ndims = H5Sget_simple_extent_ndims(filespace); - hsize_t dims[ndims]; - H5Sget_simple_extent_dims(filespace, dims, NULL); - - // int dims_in = variable.m_GlobalDimensions.size(); - variable.m_GlobalDimensions.clear(); - for (int i = 0; i < ndims; i++) - { - variable.m_GlobalDimensions.push_back(dims[i]); - } - - std::vector<hsize_t> count, offset, stride; - - int elementsRead = 1; - for (int i = 0; i < ndims; i++) - { - if (variable.m_LocalDimensions.size() == ndims) - { - count.push_back(variable.m_LocalDimensions[i]); - elementsRead *= variable.m_LocalDimensions[i]; - } - else - { - count.push_back(variable.m_GlobalDimensions[i]); - elementsRead *= variable.m_GlobalDimensions[i]; - } - - if (variable.m_Offsets.size() == ndims) - { - offset.push_back(variable.m_Offsets[i]); - } - else - { - offset.push_back(0); - } - - stride.push_back(1); - } - - 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); - - // 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.m_CurrentTimeStep << ", " - << data_array[i] << std::endl; - } - */ - H5Sclose(mem_dataspace); - - H5Sclose(filespace); - H5Dclose(datasetID); -} template <class T> void HDF5Reader::UseHDFRead(const std::string &variableName, T *values, diff --git a/source/adios2/engine/hdf5/HDF5ReaderP.h b/source/adios2/engine/hdf5/HDF5ReaderP.h index 1821d45aa9d637669285899481898fd8240598d5..7b05ba221b5bd8cbd3e293903d8696125fbf910a 100644 --- a/source/adios2/engine/hdf5/HDF5ReaderP.h +++ b/source/adios2/engine/hdf5/HDF5ReaderP.h @@ -110,12 +110,13 @@ public: void Close(const int transportIndex = -1); - template <class T> + template <typename 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); - + */ private: HDF5Common _H5File; void Init(); diff --git a/testing/adios2/engine/hdf5/TestHDF5WriteRead.cpp b/testing/adios2/engine/hdf5/TestHDF5WriteRead.cpp index a540da6ebfacd8715ff64f51f118e60c13ef347e..b3e4f51a7db0d25c2b41a7143b92f662a830f79d 100644 --- a/testing/adios2/engine/hdf5/TestHDF5WriteRead.cpp +++ b/testing/adios2/engine/hdf5/TestHDF5WriteRead.cpp @@ -24,6 +24,132 @@ public: SmallTestData m_TestData; }; +class HDF5Direct +{ + +public: + /** + * Constructor for HDF5 file + * @param file name + */ + HDF5Direct(const std::string name, MPI_Comm m_MPIComm); + + bool isValid(); + void H5_Close(); + void H5_Advance(); + + void Read(const std::string name, void *data_array, std::vector<int> &); + + hid_t m_Plist_id, m_File_id; + hid_t m_Group_id; + + // hid_t DefH5T_COMPLEX_DOUBLE; + // hid_t DefH5T_COMPLEX_FLOAT; + // hid_t DefH5T_COMPLEX_LongDOUBLE; + + int m_CurrentTimeStep; + +private: + int m_Total_timestep; +}; + +HDF5Direct::HDF5Direct(const std::string name, MPI_Comm m_MPIComm) +: m_Total_timestep(0), m_CurrentTimeStep(0) +{ + // + m_Plist_id = H5Pcreate(H5P_FILE_ACCESS); + +#ifdef ADIOS2_HAVE_MPI + H5Pset_fapl_mpio(m_Plist_id, m_MPIComm, MPI_INFO_NULL); +#endif + + std::string ts0 = "/TimeStep0"; + + { + // read a file collectively + m_File_id = H5Fopen(name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); + if (m_File_id >= 0) + { + m_Group_id = H5Gopen(m_File_id, ts0.c_str(), H5P_DEFAULT); + } + } + + H5Pclose(m_Plist_id); + + hid_t attr = H5Aopen(m_File_id, "NumTimeSteps", H5P_DEFAULT); + H5Aread(attr, H5T_NATIVE_UINT, &m_Total_timestep); + H5Aclose(attr); +} + +bool HDF5Direct::isValid() { return (m_File_id >= 0); } + +void HDF5Direct::H5_Close() +{ + if (m_Group_id >= 0) + { + H5Gclose(m_Group_id); + } + + H5Fclose(m_File_id); +} + +void HDF5Direct::H5_Advance() +{ + m_CurrentTimeStep++; + if (m_CurrentTimeStep > 0) + { + H5Gclose(m_Group_id); + m_Group_id = -1; + } + + std::string tsname = "/TimeStep"; + tsname.append(std::to_string(m_CurrentTimeStep)); + int totalts = m_Total_timestep; + { + if ((totalts > 0) && (totalts <= m_CurrentTimeStep)) + { + return; + } + // std::cout<<" ... current group "<<tsname.c_str()<<std::endl; + m_Group_id = H5Gopen(m_File_id, tsname.c_str(), H5P_DEFAULT); + } +} + +void HDF5Direct::Read(const std::string name, void *data_array, + std::vector<int> &gdims) +{ + hid_t datasetID = H5Dopen(m_Group_id, name.c_str(), H5P_DEFAULT); + + if (datasetID < 0) + { + return; + } + + hid_t filespace = H5Dget_space(datasetID); + + if (filespace < 0) + { + return; + } + + const int ndims = H5Sget_simple_extent_ndims(filespace); + hsize_t dims[ndims]; + H5Sget_simple_extent_dims(filespace, dims, NULL); + + gdims.clear(); + for (int i = 0; i < ndims; i++) + { + gdims.push_back(dims[i]); + } + + hid_t h5type = H5Dget_type(datasetID); + hid_t ret = + H5Dread(datasetID, h5type, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_array); + + H5Sclose(filespace); + H5Dclose(datasetID); +} + //****************************************************************************** // 1D 1x8 test data //****************************************************************************** @@ -96,7 +222,7 @@ TEST_F(HDF5WriteReadTest, ADIOS2HDF5WriteHDF5Read1D8) engine->Close(); } - // Read test data using HDF5 +// Read test data using HDF5 #ifdef ADIOS2_HAVE_MPI // Read everything from rank 0 int rank; @@ -104,16 +230,9 @@ TEST_F(HDF5WriteReadTest, ADIOS2HDF5WriteHDF5Read1D8) if (rank == 0) #endif { - adios::ADIOS adios(adios::Verbose::WARN, true); - // call reader directly - auto method = adios.DeclareMethod("TestMethod"); - method.SetEngine("HDF5Reader"); - - adios::HDF5Reader hdf5Reader(adios, fname, "r", MPI_COMM_WORLD, method); - - ASSERT_TRUE(hdf5Reader.isValid()); + HDF5Direct hdf5Reader(fname, MPI_COMM_WORLD); + ASSERT_TRUE(hdf5Reader.isValid()); - std::array<char, 8> I8; std::array<int16_t, 8> I16; std::array<int32_t, 8> I32; @@ -125,69 +244,95 @@ TEST_F(HDF5WriteReadTest, ADIOS2HDF5WriteHDF5Read1D8) std::array<float, 8> R32; std::array<double, 8> R64; - - auto &var_i8 = adios.DefineVariable<char>("i8"); - auto &var_i16 = adios.DefineVariable<short>("i16"); - auto &var_i32 = adios.DefineVariable<int>("i32" ); - auto &var_i64 = adios.DefineVariable<long>("i64" ); - auto &var_u8 = - adios.DefineVariable<unsigned char>("u8"); - auto &var_u16 = - adios.DefineVariable<unsigned short>("u16"); - auto &var_u32 = - adios.DefineVariable<unsigned int>("u32"); - auto &var_u64 = - adios.DefineVariable<unsigned long>("u64"); - auto &var_r32 = adios.DefineVariable<float>("r32"); - auto &var_r64 = adios.DefineVariable<double>("r64"); - // Read stuff for (size_t t = 0; t < 3; ++t) { - // Read the current step - hdf5Reader.ReadMe(var_i8, I8.data(), H5T_NATIVE_CHAR); - hdf5Reader.ReadMe(var_i16, I16.data(), H5T_NATIVE_SHORT); - hdf5Reader.ReadMe(var_i32, I32.data(), H5T_NATIVE_INT); - hdf5Reader.ReadMe(var_i64, I64.data(), H5T_NATIVE_LONG); - hdf5Reader.ReadMe(var_u8, U8.data(), H5T_NATIVE_UCHAR); - hdf5Reader.ReadMe(var_u16, U16.data(), H5T_NATIVE_USHORT); - hdf5Reader.ReadMe(var_u32, U32.data(), H5T_NATIVE_UINT); - hdf5Reader.ReadMe(var_u64, U64.data(), H5T_NATIVE_ULONG); - hdf5Reader.ReadMe(var_r32, R32.data(), H5T_NATIVE_FLOAT); - hdf5Reader.ReadMe(var_r64, R64.data(), H5T_NATIVE_DOUBLE); + std::vector<int> gDims; + hdf5Reader.Read("i8", I8.data(), gDims); + ASSERT_EQ(gDims.size(), 1); + ASSERT_EQ(gDims[0], 8); + + hdf5Reader.Read("i16", I16.data(), gDims); + ASSERT_EQ(gDims.size(), 1); + ASSERT_EQ(gDims[0], 8); + + hdf5Reader.Read("i32", I32.data(), gDims); + ASSERT_EQ(gDims.size(), 1); + ASSERT_EQ(gDims[0], 8); + + hdf5Reader.Read("i64", I64.data(), gDims); + ASSERT_EQ(gDims.size(), 1); + ASSERT_EQ(gDims[0], 8); + + hdf5Reader.Read("u8", U8.data(), gDims); + ASSERT_EQ(gDims.size(), 1); + ASSERT_EQ(gDims[0], 8); + + hdf5Reader.Read("u16", U16.data(), gDims); + ASSERT_EQ(gDims.size(), 1); + ASSERT_EQ(gDims[0], 8); - // Check the variables exist - ASSERT_EQ(var_i8.m_GlobalDimensions.size(), 1); - ASSERT_EQ(var_i8.m_GlobalDimensions[0], 8); + hdf5Reader.Read("u32", U32.data(), gDims); + ASSERT_EQ(gDims.size(), 1); + ASSERT_EQ(gDims[0], 8); - ASSERT_EQ(var_i16.m_GlobalDimensions.size(), 1); - ASSERT_EQ(var_i16.m_GlobalDimensions[0], 8); + hdf5Reader.Read("u64", U64.data(), gDims); + ASSERT_EQ(gDims.size(), 1); + ASSERT_EQ(gDims[0], 8); - ASSERT_EQ(var_i32.m_GlobalDimensions.size(), 1); - ASSERT_EQ(var_i32.m_GlobalDimensions[0], 8); + hdf5Reader.Read("r32", R32.data(), gDims); + ASSERT_EQ(gDims.size(), 1); + ASSERT_EQ(gDims[0], 8); - ASSERT_EQ(var_i64.m_GlobalDimensions.size(), 1); - ASSERT_EQ(var_i64.m_GlobalDimensions[0], 8); + hdf5Reader.Read("r64", R64.data(), gDims); + ASSERT_EQ(gDims.size(), 1); + ASSERT_EQ(gDims[0], 8); - ASSERT_EQ(var_u8.m_GlobalDimensions.size(), 1); - ASSERT_EQ(var_u8.m_GlobalDimensions[0], 8); + /* + // Read the current step + hdf5Reader.ReadMe(var_i8, I8.data(), H5T_NATIVE_CHAR); + hdf5Reader.ReadMe(var_i16, I16.data(), H5T_NATIVE_SHORT); + hdf5Reader.ReadMe(var_i32, I32.data(), H5T_NATIVE_INT); + hdf5Reader.ReadMe(var_i64, I64.data(), H5T_NATIVE_LONG); + hdf5Reader.ReadMe(var_u8, U8.data(), H5T_NATIVE_UCHAR); + hdf5Reader.ReadMe(var_u16, U16.data(), H5T_NATIVE_USHORT); + hdf5Reader.ReadMe(var_u32, U32.data(), H5T_NATIVE_UINT); + hdf5Reader.ReadMe(var_u64, U64.data(), H5T_NATIVE_ULONG); + hdf5Reader.ReadMe(var_r32, R32.data(), H5T_NATIVE_FLOAT); + hdf5Reader.ReadMe(var_r64, R64.data(), H5T_NATIVE_DOUBLE); - ASSERT_EQ(var_u16.m_GlobalDimensions.size(), 1); - ASSERT_EQ(var_u16.m_GlobalDimensions[0], 8); + // Check the variables exist + ASSERT_EQ(var_i8.m_GlobalDimensions.size(), 1); + ASSERT_EQ(var_i8.m_GlobalDimensions[0], 8); - ASSERT_EQ(var_u32.m_GlobalDimensions.size(), 1); - ASSERT_EQ(var_u32.m_GlobalDimensions[0], 8); + ASSERT_EQ(var_i16.m_GlobalDimensions.size(), 1); + ASSERT_EQ(var_i16.m_GlobalDimensions[0], 8); - ASSERT_EQ(var_u64.m_GlobalDimensions.size(), 1); - ASSERT_EQ(var_u64.m_GlobalDimensions[0], 8); + ASSERT_EQ(var_i32.m_GlobalDimensions.size(), 1); + ASSERT_EQ(var_i32.m_GlobalDimensions[0], 8); - ASSERT_EQ(var_r32.m_GlobalDimensions.size(), 1); - ASSERT_EQ(var_r32.m_GlobalDimensions[0], 8); + ASSERT_EQ(var_i64.m_GlobalDimensions.size(), 1); + ASSERT_EQ(var_i64.m_GlobalDimensions[0], 8); - ASSERT_EQ(var_r64.m_GlobalDimensions.size(), 1); - ASSERT_EQ(var_r64.m_GlobalDimensions[0], 8); + ASSERT_EQ(var_u8.m_GlobalDimensions.size(), 1); + ASSERT_EQ(var_u8.m_GlobalDimensions[0], 8); + ASSERT_EQ(var_u16.m_GlobalDimensions.size(), 1); + ASSERT_EQ(var_u16.m_GlobalDimensions[0], 8); + ASSERT_EQ(var_u32.m_GlobalDimensions.size(), 1); + ASSERT_EQ(var_u32.m_GlobalDimensions[0], 8); + + ASSERT_EQ(var_u64.m_GlobalDimensions.size(), 1); + ASSERT_EQ(var_u64.m_GlobalDimensions[0], 8); + + ASSERT_EQ(var_r32.m_GlobalDimensions.size(), 1); + ASSERT_EQ(var_r32.m_GlobalDimensions[0], 8); + + ASSERT_EQ(var_r64.m_GlobalDimensions.size(), 1); + ASSERT_EQ(var_r64.m_GlobalDimensions[0], 8); + + */ // Check if it's correct for (size_t i = 0; i < 8; ++i) { @@ -206,13 +351,13 @@ TEST_F(HDF5WriteReadTest, ADIOS2HDF5WriteHDF5Read1D8) EXPECT_EQ(R32[i], m_TestData.R32[i + t]) << msg; EXPECT_EQ(R64[i], m_TestData.R64[i + t]) << msg; } - hdf5Reader.Advance(); + + hdf5Reader.H5_Advance(); } // Cleanup file - hdf5Reader.Close(); + hdf5Reader.H5_Close(); } - } // ADIOS2 write, ADIOS2 read @@ -308,7 +453,7 @@ TEST_F(HDF5WriteReadTest, ADIOS2HDF5WriteHDF5Read2D2x4) engine->Close(); } - // Read test data using HDF5 +// Read test data using HDF5 #ifdef ADIOS2_HAVE_MPI // Read everything from rank 0 int rank; @@ -316,98 +461,73 @@ TEST_F(HDF5WriteReadTest, ADIOS2HDF5WriteHDF5Read2D2x4) if (rank == 0) #endif { - adios::ADIOS adios(adios::Verbose::WARN, true); - // call reader directly - auto method = adios.DeclareMethod("TestMethod"); - method.SetEngine("HDF5Reader"); - - adios::HDF5Reader hdf5Reader(adios, fname, "r", MPI_COMM_WORLD, method); - - ASSERT_TRUE(hdf5Reader.isValid()); - - std::array<char, 8> I8; - std::array<int16_t, 8> I16; - std::array<int32_t, 8> I32; - std::array<int64_t, 8> I64; - std::array<unsigned char, 8> U8; - std::array<uint16_t, 8> U16; - std::array<uint32_t, 8> U32; - std::array<uint64_t, 8> U64; - std::array<float, 8> R32; - std::array<double, 8> R64; - - - auto &var_i8 = adios.DefineVariable<char>("i8"); - auto &var_i16 = adios.DefineVariable<short>("i16"); - auto &var_i32 = adios.DefineVariable<int>("i32" ); - auto &var_i64 = adios.DefineVariable<long>("i64" ); - auto &var_u8 = - adios.DefineVariable<unsigned char>("u8"); - auto &var_u16 = - adios.DefineVariable<unsigned short>("u16"); - auto &var_u32 = - adios.DefineVariable<unsigned int>("u32"); - auto &var_u64 = - adios.DefineVariable<unsigned long>("u64"); - auto &var_r32 = adios.DefineVariable<float>("r32"); - auto &var_r64 = adios.DefineVariable<double>("r64"); - - // Read stuff - for (size_t t = 0; t < 3; ++t) - { - // Read the current step - hdf5Reader.ReadMe(var_i8, I8.data(), H5T_NATIVE_CHAR); - hdf5Reader.ReadMe(var_i16, I16.data(), H5T_NATIVE_SHORT); - hdf5Reader.ReadMe(var_i32, I32.data(), H5T_NATIVE_INT); - hdf5Reader.ReadMe(var_i64, I64.data(), H5T_NATIVE_LONG); - hdf5Reader.ReadMe(var_u8, U8.data(), H5T_NATIVE_UCHAR); - hdf5Reader.ReadMe(var_u16, U16.data(), H5T_NATIVE_USHORT); - hdf5Reader.ReadMe(var_u32, U32.data(), H5T_NATIVE_UINT); - hdf5Reader.ReadMe(var_u64, U64.data(), H5T_NATIVE_ULONG); - hdf5Reader.ReadMe(var_r32, R32.data(), H5T_NATIVE_FLOAT); - hdf5Reader.ReadMe(var_r64, R64.data(), H5T_NATIVE_DOUBLE); - - // Check the variables exist - ASSERT_EQ(var_i8.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_i8.m_GlobalDimensions[0], 2); - ASSERT_EQ(var_i8.m_GlobalDimensions[1], 4); - - ASSERT_EQ(var_i16.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_i16.m_GlobalDimensions[0], 2); - ASSERT_EQ(var_i16.m_GlobalDimensions[1], 4); - - ASSERT_EQ(var_i32.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_i32.m_GlobalDimensions[0], 2); - ASSERT_EQ(var_i32.m_GlobalDimensions[1], 4); - - ASSERT_EQ(var_i64.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_i64.m_GlobalDimensions[0], 2); - ASSERT_EQ(var_i64.m_GlobalDimensions[1], 4); - - ASSERT_EQ(var_u8.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_u8.m_GlobalDimensions[0], 2); - ASSERT_EQ(var_u8.m_GlobalDimensions[1], 4); - - ASSERT_EQ(var_u16.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_u16.m_GlobalDimensions[0], 2); - ASSERT_EQ(var_u16.m_GlobalDimensions[1], 4); - - ASSERT_EQ(var_u32.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_u32.m_GlobalDimensions[0], 2); - ASSERT_EQ(var_u32.m_GlobalDimensions[1], 4); - - ASSERT_EQ(var_u64.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_u64.m_GlobalDimensions[0], 2); - ASSERT_EQ(var_u64.m_GlobalDimensions[1], 4); - - ASSERT_EQ(var_r32.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_r32.m_GlobalDimensions[0], 2); - ASSERT_EQ(var_r32.m_GlobalDimensions[1], 4); - - ASSERT_EQ(var_r64.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_r64.m_GlobalDimensions[0], 2); - ASSERT_EQ(var_r64.m_GlobalDimensions[1], 4); + HDF5Direct hdf5Reader(fname, MPI_COMM_WORLD); + ASSERT_TRUE(hdf5Reader.isValid()); + std::array<char, 8> I8; + std::array<int16_t, 8> I16; + std::array<int32_t, 8> I32; + std::array<int64_t, 8> I64; + std::array<unsigned char, 8> U8; + std::array<uint16_t, 8> U16; + std::array<uint32_t, 8> U32; + std::array<uint64_t, 8> U64; + std::array<float, 8> R32; + std::array<double, 8> R64; + + // Read stuff + for (size_t t = 0; t < 3; ++t) + { + std::vector<int> gDims; + hdf5Reader.Read("i8", I8.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 2); + ASSERT_EQ(gDims[1], 4); + + hdf5Reader.Read("i16", I16.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 2); + ASSERT_EQ(gDims[1], 4); + + hdf5Reader.Read("i32", I32.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 2); + ASSERT_EQ(gDims[1], 4); + + hdf5Reader.Read("i64", I64.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 2); + ASSERT_EQ(gDims[1], 4); + + hdf5Reader.Read("u8", U8.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 2); + ASSERT_EQ(gDims[1], 4); + + hdf5Reader.Read("u16", U16.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 2); + ASSERT_EQ(gDims[1], 4); + + hdf5Reader.Read("u32", U32.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 2); + ASSERT_EQ(gDims[1], 4); + + hdf5Reader.Read("u64", U64.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 2); + ASSERT_EQ(gDims[1], 4); + + hdf5Reader.Read("r32", R32.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 2); + ASSERT_EQ(gDims[1], 4); + + hdf5Reader.Read("r64", R64.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 2); + ASSERT_EQ(gDims[1], 4); // Check if it's correct for (size_t i = 0; i < 8; ++i) @@ -427,13 +547,12 @@ TEST_F(HDF5WriteReadTest, ADIOS2HDF5WriteHDF5Read2D2x4) EXPECT_EQ(R32[i], m_TestData.R32[i + t]) << msg; EXPECT_EQ(R64[i], m_TestData.R64[i + t]) << msg; } - hdf5Reader.Advance(); + hdf5Reader.H5_Advance(); } // Cleanup file - hdf5Reader.Close(); + hdf5Reader.H5_Close(); } - } // ADIOS2 write, ADIOS2 read @@ -529,7 +648,7 @@ TEST_F(HDF5WriteReadTest, ADIOS2HDF5WriteHDF5Read2D4x2) engine->Close(); } - // Read test data using HDF5 +// Read test data using HDF5 #ifdef ADIOS2_HAVE_MPI // Read everything from rank 0 int rank; @@ -537,100 +656,75 @@ TEST_F(HDF5WriteReadTest, ADIOS2HDF5WriteHDF5Read2D4x2) if (rank == 0) #endif { - adios::ADIOS adios(adios::Verbose::WARN, true); - // call reader directly - auto method = adios.DeclareMethod("TestMethod"); - method.SetEngine("HDF5Reader"); - - adios::HDF5Reader hdf5Reader(adios, fname, "r", MPI_COMM_WORLD, method); - - ASSERT_TRUE(hdf5Reader.isValid()); - - std::array<char, 8> I8; - std::array<int16_t, 8> I16; - std::array<int32_t, 8> I32; - std::array<int64_t, 8> I64; - std::array<unsigned char, 8> U8; - std::array<uint16_t, 8> U16; - std::array<uint32_t, 8> U32; - std::array<uint64_t, 8> U64; - std::array<float, 8> R32; - std::array<double, 8> R64; - - - auto &var_i8 = adios.DefineVariable<char>("i8"); - auto &var_i16 = adios.DefineVariable<short>("i16"); - auto &var_i32 = adios.DefineVariable<int>("i32" ); - auto &var_i64 = adios.DefineVariable<long>("i64" ); - auto &var_u8 = - adios.DefineVariable<unsigned char>("u8"); - auto &var_u16 = - adios.DefineVariable<unsigned short>("u16"); - auto &var_u32 = - adios.DefineVariable<unsigned int>("u32"); - auto &var_u64 = - adios.DefineVariable<unsigned long>("u64"); - auto &var_r32 = adios.DefineVariable<float>("r32"); - auto &var_r64 = adios.DefineVariable<double>("r64"); - - // Read stuff - for (size_t t = 0; t < 3; ++t) - { - // Read the current step - hdf5Reader.ReadMe(var_i8, I8.data(), H5T_NATIVE_CHAR); - hdf5Reader.ReadMe(var_i16, I16.data(), H5T_NATIVE_SHORT); - hdf5Reader.ReadMe(var_i32, I32.data(), H5T_NATIVE_INT); - hdf5Reader.ReadMe(var_i64, I64.data(), H5T_NATIVE_LONG); - hdf5Reader.ReadMe(var_u8, U8.data(), H5T_NATIVE_UCHAR); - hdf5Reader.ReadMe(var_u16, U16.data(), H5T_NATIVE_USHORT); - hdf5Reader.ReadMe(var_u32, U32.data(), H5T_NATIVE_UINT); - hdf5Reader.ReadMe(var_u64, U64.data(), H5T_NATIVE_ULONG); - hdf5Reader.ReadMe(var_r32, R32.data(), H5T_NATIVE_FLOAT); - hdf5Reader.ReadMe(var_r64, R64.data(), H5T_NATIVE_DOUBLE); - - // Check the variables exist - ASSERT_EQ(var_i8.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_i8.m_GlobalDimensions[0], 4); - ASSERT_EQ(var_i8.m_GlobalDimensions[1], 2); - - ASSERT_EQ(var_i16.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_i16.m_GlobalDimensions[0], 4); - ASSERT_EQ(var_i16.m_GlobalDimensions[1], 2); - - ASSERT_EQ(var_i32.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_i32.m_GlobalDimensions[0], 4); - ASSERT_EQ(var_i32.m_GlobalDimensions[1], 2); - - ASSERT_EQ(var_i64.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_i64.m_GlobalDimensions[0], 4); - ASSERT_EQ(var_i64.m_GlobalDimensions[1], 2); - - ASSERT_EQ(var_u8.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_u8.m_GlobalDimensions[0], 4); - ASSERT_EQ(var_u8.m_GlobalDimensions[1], 2); - - ASSERT_EQ(var_u16.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_u16.m_GlobalDimensions[0], 4); - ASSERT_EQ(var_u16.m_GlobalDimensions[1], 2); - - ASSERT_EQ(var_u32.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_u32.m_GlobalDimensions[0], 4); - ASSERT_EQ(var_u32.m_GlobalDimensions[1], 2); - - ASSERT_EQ(var_u64.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_u64.m_GlobalDimensions[0], 4); - ASSERT_EQ(var_u64.m_GlobalDimensions[1], 2); - - ASSERT_EQ(var_r32.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_r32.m_GlobalDimensions[0], 4); - ASSERT_EQ(var_r32.m_GlobalDimensions[1], 2); - - ASSERT_EQ(var_r64.m_GlobalDimensions.size(), 2); - ASSERT_EQ(var_r64.m_GlobalDimensions[0], 4); - ASSERT_EQ(var_r64.m_GlobalDimensions[1], 2); + HDF5Direct hdf5Reader(fname, MPI_COMM_WORLD); + ASSERT_TRUE(hdf5Reader.isValid()); + + std::array<char, 8> I8; + std::array<int16_t, 8> I16; + std::array<int32_t, 8> I32; + std::array<int64_t, 8> I64; + std::array<unsigned char, 8> U8; + std::array<uint16_t, 8> U16; + std::array<uint32_t, 8> U32; + std::array<uint64_t, 8> U64; + std::array<float, 8> R32; + std::array<double, 8> R64; + + // Read stuff + for (size_t t = 0; t < 3; ++t) + { + std::vector<int> gDims; + hdf5Reader.Read("i8", I8.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 4); + ASSERT_EQ(gDims[1], 2); + + hdf5Reader.Read("i16", I16.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 4); + ASSERT_EQ(gDims[1], 2); + + hdf5Reader.Read("i32", I32.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 4); + ASSERT_EQ(gDims[1], 2); + + hdf5Reader.Read("i64", I64.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 4); + ASSERT_EQ(gDims[1], 2); + + hdf5Reader.Read("u8", U8.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 4); + ASSERT_EQ(gDims[1], 2); + + hdf5Reader.Read("u16", U16.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 4); + ASSERT_EQ(gDims[1], 2); + + hdf5Reader.Read("u32", U32.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 4); + ASSERT_EQ(gDims[1], 2); + + hdf5Reader.Read("u64", U64.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 4); + ASSERT_EQ(gDims[1], 2); + + hdf5Reader.Read("r32", R32.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 4); + ASSERT_EQ(gDims[1], 2); + + hdf5Reader.Read("r64", R64.data(), gDims); + ASSERT_EQ(gDims.size(), 2); + ASSERT_EQ(gDims[0], 4); + ASSERT_EQ(gDims[1], 2); - // Check if it's correct for (size_t i = 0; i < 8; ++i) { std::stringstream ss; @@ -648,11 +742,11 @@ TEST_F(HDF5WriteReadTest, ADIOS2HDF5WriteHDF5Read2D4x2) EXPECT_EQ(R32[i], m_TestData.R32[i + t]) << msg; EXPECT_EQ(R64[i], m_TestData.R64[i + t]) << msg; } - hdf5Reader.Advance(); + hdf5Reader.H5_Advance(); } // Cleanup file - hdf5Reader.Close(); + hdf5Reader.H5_Close(); } }