diff --git a/examples/heatTransfer/write/CMakeLists.txt b/examples/heatTransfer/write/CMakeLists.txt index 763a151aa2206afee7aa56a95e05be48744cb2fb..7144a8e7720987406c27e6bbf61c2e31f7a0b4a7 100644 --- a/examples/heatTransfer/write/CMakeLists.txt +++ b/examples/heatTransfer/write/CMakeLists.txt @@ -52,4 +52,25 @@ if(ADIOS_USE_MPI) ${MPI_C_LIBRARIES} ${HDF5_C_LIBRARIES} ) endif() + + if(ADIOS_USE_HDF5) + find_package(MPI COMPONENTS C REQUIRED) + + add_executable(heatTransfer_write_a2h5 + main.cpp + HeatTransfer.cpp + Settings.cpp + IO_ph5_adios2.cpp + ) + + target_include_directories(heatTransfer_write_a2h5 + PRIVATE ${MPI_C_INCLUDE_PATH} + ) + #target_link_libraries(heatTransfer_write_a2h5 + # ${MPI_C_LIBRARIES} + #) + target_link_libraries(heatTransfer_write_a2h5 PUBLIC adios2) + + endif() + endif() diff --git a/examples/heatTransfer/write/IO_ph5_adios2.cpp b/examples/heatTransfer/write/IO_ph5_adios2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a4b37c5dc466eba83a2d60a2f1918ecdd421adef --- /dev/null +++ b/examples/heatTransfer/write/IO_ph5_adios2.cpp @@ -0,0 +1,120 @@ +/* + * Distributed under the OSI-approved Apache License, Version 2.0. See + * accompanying file Copyright.txt for details. + * + * IO_ADIOS2.cpp + * + * Created on: Feb 2017 + * Author: Norbert Podhorszki + */ + +#include "IO.h" + +#include <string> + +#include <adios2.h> + +static int rank_saved; +adios::ADIOS *ad = nullptr; +std::shared_ptr<adios::Engine> h5writer; +adios::Variable<double> *varT = nullptr; +adios::Variable<unsigned int> *varGndx = nullptr; + +IO::IO(const Settings &s, MPI_Comm comm) +{ + rank_saved = s.rank; + m_outputfilename = s.outputfile + ".h5"; + //adios::ADIOS adios(comm, adios::Verbose::INFO, false); + ad = new adios::ADIOS(comm, adios::Verbose::INFO, false); + + // Define method for engine creation + // 1. Get method def from config file or define new one + + adios::Method &h5writerSettings = ad->DeclareMethod("output"); + if (!h5writerSettings.IsUserDefined()) + { + // if not defined by user, we can change the default settings + // BPFileWriter is the default engine + h5writerSettings.SetEngine("HDF5Writer"); + // Allow an extra thread for data processing + + const std::string aggregatorsParam("Aggregators=" + + std::to_string((s.nproc + 1) / 2)); + h5writerSettings.SetParameters("have_metadata_file=yes", + aggregatorsParam); + } + + // ad->DefineScalar<unsigned int>("gndx", true); + varGndx = &(ad->DefineVariable<unsigned int>("gndx")); + ad->DefineVariable<unsigned int>("gndy"); + + // define T as 2D global array + varT = &(ad->DefineArray<double>( + "T", + // Global dimensions + {s.gndx, s.gndy}, + // starting offset of the local array in the global space + {s.offsx, s.offsy}, + // local size, could be defined later using SetSelection() + {s.ndx, s.ndy})); + + // add transform to variable + // adios::Transform tr = adios::transform::BZIP2( ); + // varT.AddTransform( tr, "" ); + // varT.AddTransform( tr,"accuracy=0.001" ); // for ZFP + + h5writer = ad->Open(m_outputfilename, "w", comm, h5writerSettings); + + if (h5writer == nullptr) + throw std::ios_base::failure("ERROR: failed to open ADIOS h5writer\n"); +} + +IO::~IO() +{ + h5writer->Close(); + //delete ad; +} + +void IO::write(int step, const HeatTransfer &ht, const Settings &s, + MPI_Comm comm) +{ +#if 1 + + /* This selection is redundant and not required, since we defined + * the selection already in DefineVariable(). It is here just as an example. + */ + // Make a selection to describe the local dimensions of the variable we + // write and its offsets in the global spaces. This could have been done in + // adios.DefineVariable() + //adios::SelectionBoundingBox sel({s.offsx, s.offsy}, {s.ndx, s.ndy}); + //varT->SetSelection(sel); + + /* Select the area that we want to write from the data pointer we pass to + the + writer. + Think HDF5 memspace, just not hyperslabs, only a bounding box selection. + Engine will copy this bounding box from the data pointer into the output + buffer. + Size of the bounding box should match the "space" selection which was + given + above. + Default memspace is always the full selection. + */ + //adios::SelectionBoundingBox memspace = + // adios::SelectionBoundingBox({1, 1}, {s.ndx, s.ndy}); + //varT->SetMemorySelection(memspace); + + h5writer->Write<double>(*varT, ht.data_noghost().data()); + //h5writer->Write(*varT, ht.data_noghost().data()); + h5writer->Write<unsigned int>(*varGndx, s.gndx); + h5writer->Write<unsigned int>("gndy", s.gndy); + + h5writer->Advance(); + +#else + + h5writer->Write<double>(*varT, ht.data_noghost().data()); + h5writer->Advance(); + +#endif +} diff --git a/examples/hello/hdf5Writer/helloHDF5Writer.cpp b/examples/hello/hdf5Writer/helloHDF5Writer.cpp index adf524928bfcd4d68e3c20f47f77360839e26331..cc1b7bd3f7c9fe6aad29a6887179fe0d27e78117 100644 --- a/examples/hello/hdf5Writer/helloHDF5Writer.cpp +++ b/examples/hello/hdf5Writer/helloHDF5Writer.cpp @@ -73,17 +73,16 @@ int main(int argc, char *argv[]) try { // Define variable and local size - auto &ioMyInts = - adios.DefineArray<int>("myInts", {intCountDim1, intDim2}, {4, 3}, - {intOffsetDim1, intOffsetDim2}); + auto &ioMyInts = adios.DefineArray<int>("myInts", {4, 3}, + {intOffsetDim1, intOffsetDim2}, {intCountDim1, intDim2}); auto &ioMyDoubles = adios.DefineArray<double>( - "myDoubles", {doubleVCount}, {Nx}, {doubleVOffset}); + "myDoubles", {Nx}, {doubleVOffset}, {doubleVCount}); auto &ioMyCFloats = adios.DefineArray<std::complex<float>>( - "myCFloats", {complexCount}, {3}, {complexOffset}); + "myCFloats", {3}, {complexOffset}, {complexCount}); auto &ioMyCDoubles = adios.DefineArray<std::complex<double>>( - "myCDoubles", {complexCount}, {3}, {complexOffset}); + "myCDoubles", {3}, {complexOffset}, {complexCount}); auto &ioMyCLongDoubles = adios.DefineArray<std::complex<long double>>( - "myCLongDoubles", {complexCount}, {3}, {complexOffset}); + "myCLongDoubles", {3}, {complexOffset}, {complexCount}); // Define method for engine creation, it is basically straight-forward // parameters diff --git a/source/adios2/engine/hdf5/HDF5Common.cpp b/source/adios2/engine/hdf5/HDF5Common.cpp index e2a9c521ee6b08d50094910ea43e85920d395350..d628689c7d6a3b380e1b782f6ed331cd473fe2b9 100644 --- a/source/adios2/engine/hdf5/HDF5Common.cpp +++ b/source/adios2/engine/hdf5/HDF5Common.cpp @@ -162,6 +162,10 @@ void HDF5Common::Close() H5Fclose(m_FileId); m_FileId = -1; m_GroupId = -1; + + H5Tclose(m_DefH5TypeComplexFloat); + H5Tclose(m_DefH5TypeComplexDouble); + H5Tclose(m_DefH5TypeComplexLongDouble); } void HDF5Common::Advance() diff --git a/source/adios2/engine/hdf5/HDF5WriterP.cpp b/source/adios2/engine/hdf5/HDF5WriterP.cpp index d4f036a1b321c2310efb451d343382264db23c92..6969c4a40138bd44924dd75ddc206bdf50b9d0c0 100644 --- a/source/adios2/engine/hdf5/HDF5WriterP.cpp +++ b/source/adios2/engine/hdf5/HDF5WriterP.cpp @@ -22,8 +22,8 @@ HDF5Writer::HDF5Writer(ADIOS &adios, const std::string name, const Method &method) : Engine(adios, "HDF5Writer", name, accessMode, mpiComm, method, /*debugMode, cores,*/ - " HDF5Writer constructor (or call to ADIOS Open).\n"), - m_Buffer(m_DebugMode) + " HDF5Writer constructor (or call to ADIOS Open).\n") + //m_Buffer(m_DebugMode) { Init(); } @@ -256,6 +256,19 @@ void HDF5Writer::UseHDFWrite(Variable<T> &variable, const T *values, int dimSize = std::max(variable.m_Shape.size(), variable.m_Count.size()); + if (dimSize == 0) { + // scalar + hid_t filespaceID = H5Screate(H5S_SCALAR); + hid_t dsetID = H5Dcreate(m_H5File.m_GroupId, variable.m_Name.c_str(), h5Type, filespaceID, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + herr_t status = H5Dwrite(dsetID, h5Type, H5S_ALL, H5S_ALL, H5P_DEFAULT, values); + + H5Sclose (filespaceID); + H5Dclose (dsetID); + + return; + } + std::vector<hsize_t> dimsf, count, offset; for (int i = 0; i < dimSize; i++) diff --git a/source/adios2/engine/hdf5/HDF5WriterP.h b/source/adios2/engine/hdf5/HDF5WriterP.h index 21151a18ab648cab1b8d389436a13dfb3518c3ef..d4c4d217e4afd56fc392eba8d68acf481febfe7a 100644 --- a/source/adios2/engine/hdf5/HDF5WriterP.h +++ b/source/adios2/engine/hdf5/HDF5WriterP.h @@ -91,7 +91,7 @@ public: private: ///< heap capsule, contains data and metadata buffers - capsule::STLVector m_Buffer; + //capsule::STLVector m_Buffer; void Init();