From d13d6731cea0fb7a2fb7568bdab220e6d2d5e380 Mon Sep 17 00:00:00 2001 From: guj <jgu@lbl.gov> Date: Fri, 14 Apr 2017 13:42:34 -0700 Subject: [PATCH] minor changes --- examples/hello/hdf5Writer/CMakeLists.txt | 8 +- examples/hello/hdf5Writer/helloHDF5Writer.cpp | 157 +++---- .../hdf5Writer/helloHDF5Writer_nompi.cpp | 150 ++++--- include/engine/hdf5/HDF5ReaderP.h | 1 - include/engine/hdf5/HDF5WriterP.h | 2 - source/ADIOS.cpp | 18 +- source/CMakeLists.txt | 8 +- source/engine/hdf5/HDF5ReaderP.cpp | 3 - source/engine/hdf5/HDF5WriterP.cpp | 399 ++++++++++-------- 9 files changed, 403 insertions(+), 343 deletions(-) diff --git a/examples/hello/hdf5Writer/CMakeLists.txt b/examples/hello/hdf5Writer/CMakeLists.txt index 742560057..7f4197c0b 100644 --- a/examples/hello/hdf5Writer/CMakeLists.txt +++ b/examples/hello/hdf5Writer/CMakeLists.txt @@ -9,10 +9,10 @@ include_directories(${HDF5_INCLUDE_DIRS}) target_link_libraries(hello_hdf5Writer_nompi adios2_nompi) if(ADIOS_BUILD_TESTING) - add_test( - NAME Example::hello::hdf5Writer_nompi - COMMAND hello_hdf5Writer_nompi - ) + #add_test( + # NAME Example::hello::hdf5Writer_nompi + # COMMAND hello_hdf5Writer_nompi + #) endif() if(ADIOS_USE_MPI) diff --git a/examples/hello/hdf5Writer/helloHDF5Writer.cpp b/examples/hello/hdf5Writer/helloHDF5Writer.cpp index 8dd6260bf..85c5a910a 100644 --- a/examples/hello/hdf5Writer/helloHDF5Writer.cpp +++ b/examples/hello/hdf5Writer/helloHDF5Writer.cpp @@ -5,133 +5,140 @@ * Author: Junmin */ - - #include <vector> #include <iostream> - #include <mpi.h> - #include "ADIOS_CPP.h" - -int main( int argc, char* argv [] ) +int main(int argc, char *argv[]) { - MPI_Init( &argc, &argv ); + MPI_Init(&argc, &argv); int rank, size; - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); - MPI_Comm_size( MPI_COMM_WORLD, &size ); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); const bool adiosDebug = true; adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::INFO, adiosDebug); - - //Application variable + // Application variable const std::size_t intDim1 = 4; const std::size_t intDim2 = 3; - std::vector<int> myInts = {10,11,12,13,14,15,16,17,18,19,20,21}; + std::vector<int> myInts = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; - std::vector<double> myDoubles = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; const std::size_t Nx = myDoubles.size(); std::vector<std::complex<float>> myCFloats; const std::size_t ComplexDataSize = 3; - myCFloats.reserve( ComplexDataSize ); - myCFloats.emplace_back( 1, 3 ); - myCFloats.emplace_back( 2, 2 ); - myCFloats.emplace_back( 3, 1 ); - + myCFloats.reserve(ComplexDataSize); + myCFloats.emplace_back(1, 3); + myCFloats.emplace_back(2, 2); + myCFloats.emplace_back(3, 1); std::vector<std::complex<double>> myCDoubles; - myCDoubles.reserve( ComplexDataSize ); - myCDoubles.emplace_back( 1.1, -3.3 ); - myCDoubles.emplace_back( 2.1, -2.2 ); - myCDoubles.emplace_back( 3.1, -1.1 ); + myCDoubles.reserve(ComplexDataSize); + myCDoubles.emplace_back(1.1, -3.3); + myCDoubles.emplace_back(2.1, -2.2); + myCDoubles.emplace_back(3.1, -1.1); std::vector<std::complex<long double>> myCLongDoubles; - myCLongDoubles.reserve( ComplexDataSize ); - myCLongDoubles.emplace_back( 1.11, -3.33 ); - myCLongDoubles.emplace_back( 2.11, -2.22 ); - myCLongDoubles.emplace_back( 3.11, -1.11 ); - + myCLongDoubles.reserve(ComplexDataSize); + myCLongDoubles.emplace_back(1.11, -3.33); + myCLongDoubles.emplace_back(2.11, -2.22); + myCLongDoubles.emplace_back(3.11, -1.11); - std::size_t doubleVCount = Nx/size; - std::size_t complexCount = ComplexDataSize/size; - std::size_t intCountDim1 = intDim1/size; + std::size_t doubleVCount = Nx / size; + std::size_t complexCount = ComplexDataSize / size; + std::size_t intCountDim1 = intDim1 / size; std::size_t doubleVOffset = rank * doubleVCount; - std::size_t complexOffset = rank * complexCount; + std::size_t complexOffset = rank * complexCount; std::size_t intOffsetDim1 = rank * intCountDim1; std::size_t intOffsetDim2 = 0; - if ((size > 1) && (rank == size-1)) + if ((size > 1) && (rank == size - 1)) { - doubleVCount = Nx - rank*(Nx/size); - complexCount = ComplexDataSize - rank * (ComplexDataSize/size); - intCountDim1 = intDim1 - rank * (intDim1/size); - } - + doubleVCount = Nx - rank * (Nx / size); + complexCount = ComplexDataSize - rank * (ComplexDataSize / size); + intCountDim1 = intDim1 - rank * (intDim1 / size); + } + try { - //Define variable and local size - auto& ioMyInts = adios.DefineVariable<int>( "myInts", {intCountDim1, intDim2}, {4,3}, {intOffsetDim1, intOffsetDim2} ); - auto& ioMyDoubles = adios.DefineVariable<double>( "myDoubles", {doubleVCount}, {Nx}, {doubleVOffset} ); - auto& ioMyCFloats = adios.DefineVariable<std::complex<float>>( "myCFloats", {complexCount}, {3}, {complexOffset} ); - auto& ioMyCDoubles = adios.DefineVariable<std::complex<double>>( "myCDoubles", {complexCount}, {3}, {complexOffset} ); - auto& ioMyCLongDoubles = adios.DefineVariable<std::complex<long double>>( "myCLongDoubles", {complexCount}, {3}, {complexOffset} ); - - - //Define method for engine creation, it is basically straight-forward parameters - adios::Method& HDF5Settings = adios.DeclareMethod("w" ); - HDF5Settings.SetEngine("HDF5Writer"); - HDF5Settings.SetParameters( "chunck=yes", "collectiveIO=yes"); - //HDF5Settings.AddTransport( "Mdtm", "localIP=128.0.0.0.1", "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); - - //Create engine smart pointer to HDF5 Engine due to polymorphism, - //Open returns a smart pointer to Engine containing the Derived class HDF5 - auto HDF5Writer = adios.Open( "test.bp", "w", HDF5Settings ); - - if( HDF5Writer == nullptr ) - throw std::ios_base::failure( "ERROR: failed to create HDF5 I/O engine at Open\n" ); - - 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*rank) ); - - HDF5Writer->Write( ioMyCFloats, myCFloats.data()+complexOffset ); - HDF5Writer->Write( ioMyCDoubles, myCDoubles.data()+complexOffset ); - HDF5Writer->Write( ioMyCLongDoubles, myCLongDoubles.data()+complexOffset ); - HDF5Writer->Close( ); - - } - catch( std::invalid_argument& e ) + // Define variable and local size + auto &ioMyInts = + adios.DefineVariable<int>("myInts", {intCountDim1, intDim2}, {4, 3}, + {intOffsetDim1, intOffsetDim2}); + auto &ioMyDoubles = adios.DefineVariable<double>( + "myDoubles", {doubleVCount}, {Nx}, {doubleVOffset}); + auto &ioMyCFloats = adios.DefineVariable<std::complex<float>>( + "myCFloats", {complexCount}, {3}, {complexOffset}); + auto &ioMyCDoubles = adios.DefineVariable<std::complex<double>>( + "myCDoubles", {complexCount}, {3}, {complexOffset}); + auto &ioMyCLongDoubles = + adios.DefineVariable<std::complex<long double>>( + "myCLongDoubles", {complexCount}, {3}, {complexOffset}); + + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &HDF5Settings = adios.DeclareMethod("w"); + HDF5Settings.SetEngine("HDF5Writer"); + HDF5Settings.SetParameters("chunck=yes", "collectiveIO=yes"); + // HDF5Settings.AddTransport( "Mdtm", "localIP=128.0.0.0.1", + // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); + + // Create engine smart pointer to HDF5 Engine due to polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // HDF5 + auto HDF5Writer = adios.Open("test.h5", "w", HDF5Settings); + + if (HDF5Writer == nullptr) + throw std::ios_base::failure( + "ERROR: failed to create HDF5 I/O engine at Open\n"); + + 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 * rank)); + + HDF5Writer->Write(ioMyCFloats, myCFloats.data() + complexOffset); + HDF5Writer->Write(ioMyCDoubles, myCDoubles.data() + complexOffset); + HDF5Writer->Write(ioMyCLongDoubles, + myCLongDoubles.data() + complexOffset); + HDF5Writer->Close(); + } + catch (std::invalid_argument &e) { - if( rank == 0 ) + if (rank == 0) { std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; std::cout << e.what() << "\n"; } } - catch( std::ios_base::failure& e ) + catch (std::ios_base::failure &e) { - if( rank == 0 ) + if (rank == 0) { std::cout << "System exception, STOPPING PROGRAM\n"; std::cout << e.what() << "\n"; } } - catch( std::exception& e ) + catch (std::exception &e) { - if( rank == 0 ) + if (rank == 0) { std::cout << "Exception, STOPPING PROGRAM\n"; std::cout << e.what() << "\n"; } } - MPI_Finalize( ); + MPI_Finalize(); return 0; - } diff --git a/examples/hello/hdf5Writer/helloHDF5Writer_nompi.cpp b/examples/hello/hdf5Writer/helloHDF5Writer_nompi.cpp index e49794eae..87211cb13 100644 --- a/examples/hello/hdf5Writer/helloHDF5Writer_nompi.cpp +++ b/examples/hello/hdf5Writer/helloHDF5Writer_nompi.cpp @@ -5,130 +5,140 @@ * Author: Junmin */ - - #include <vector> #include <iostream> - //#include <mpi.h> #include "ADIOS_MPI.h" #ifndef HAVE_MPI // mpidummy has namespace adios using namespace adios; -#endif +#endif #include "ADIOS_CPP.h" - -int main( int argc, char* argv [] ) +int main(int argc, char *argv[]) { - MPI_Init( &argc, &argv ); + MPI_Init(&argc, &argv); int rank, size; - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); - MPI_Comm_size( MPI_COMM_WORLD, &size ); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); const bool adiosDebug = true; adios::ADIOS adios(MPI_COMM_WORLD, adios::Verbose::INFO, adiosDebug); - - //Application variable + // Application variable const std::size_t intDim1 = 4; const std::size_t intDim2 = 3; - std::vector<int> myInts = {10,11,12,13,14,15,16,17,18,19,20,21}; + std::vector<int> myInts = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; - std::vector<double> myDoubles = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector<double> myDoubles = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; const std::size_t Nx = myDoubles.size(); std::vector<std::complex<float>> myCFloats; const std::size_t CFloatSize = 3; - myCFloats.reserve( CFloatSize ); - myCFloats.emplace_back( 1, 3 ); - myCFloats.emplace_back( 2, 2 ); - myCFloats.emplace_back( 3, 1 ); - + myCFloats.reserve(CFloatSize); + myCFloats.emplace_back(1, 3); + myCFloats.emplace_back(2, 2); + myCFloats.emplace_back(3, 1); std::vector<std::complex<double>> myCDoubles; const std::size_t CDoubleSize = 3; - myCDoubles.reserve( CDoubleSize ); - myCDoubles.emplace_back( 1, 3 ); - myCDoubles.emplace_back( 2, 2 ); - myCDoubles.emplace_back( 3, 1 ); + myCDoubles.reserve(CDoubleSize); + myCDoubles.emplace_back(1, 3); + myCDoubles.emplace_back(2, 2); + myCDoubles.emplace_back(3, 1); - - std::size_t doubleVCount = Nx/size; - std::size_t floatCount = CFloatSize/size; - std::size_t intCountDim1 = intDim1/size; + std::size_t doubleVCount = Nx / size; + std::size_t floatCount = CFloatSize / size; + std::size_t intCountDim1 = intDim1 / size; std::size_t doubleVOffset = rank * doubleVCount; - std::size_t floatOffset = rank * floatCount; + std::size_t floatOffset = rank * floatCount; std::size_t intOffsetDim1 = rank * intCountDim1; std::size_t intOffsetDim2 = 0; - if ((size > 1) && (rank == size-1)) { - doubleVCount = Nx - rank*(Nx/size); - floatCount = CFloatSize - rank * (CFloatSize/size); - intCountDim1 = intDim1 - rank * (intDim1/size); - } - + if ((size > 1) && (rank == size - 1)) + { + doubleVCount = Nx - rank * (Nx / size); + floatCount = CFloatSize - rank * (CFloatSize / size); + intCountDim1 = intDim1 - rank * (intDim1 / size); + } + try { - //Define variable and local size - //auto& ioMyDoubles = adios.DefineVariable<double>( "myDoubles", {Nx}, {Nx} ); - //auto& ioMyCFloats = adios.DefineVariable<std::complex<float>>( "myCFloats", {3}, {3} ); - //auto& ioMyInts = adios.DefineVariable<int>( "myInts", {4,3}, {4,3} ); - - auto& ioMyDoubles = adios.DefineVariable<double>( "myDoubles", {doubleVCount}, {Nx}, {doubleVOffset} ); - auto& ioMyCFloats = adios.DefineVariable<std::complex<float>>( "myCFloats", {floatCount}, {3}, {floatOffset} ); - auto& ioMyCDoubles = adios.DefineVariable<std::complex<double>>( "myCDoubles", {floatCount}, {3}, {floatOffset} ); - auto& ioMyInts = adios.DefineVariable<int>( "myInts", {intCountDim1, intDim2}, {4,3}, {intOffsetDim1, intOffsetDim2} ); - - //Define method for engine creation, it is basically straight-forward parameters - adios::Method& HDF5Settings = adios.DeclareMethod("HDF5Writer" ); //default method type is Writer - HDF5Settings.SetParameters( "chunck=yes", "collectiveIO=yes"); - //HDF5Settings.AddTransport( "Mdtm", "localIP=128.0.0.0.1", "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); - - //Create engine smart pointer to HDF5 Engine due to polymorphism, - //Open returns a smart pointer to Engine containing the Derived class HDF5 - auto HDF5Writer = adios.Open( "test.bp", "w", HDF5Settings ); - - if( HDF5Writer == nullptr ) - throw std::ios_base::failure( "ERROR: failed to create HDF5 I/O engine at Open\n" ); - - 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*rank) ); - HDF5Writer->Write( ioMyCFloats, myCFloats.data() ); - HDF5Writer->Write( ioMyCDoubles, myCDoubles.data() ); - HDF5Writer->Close( ); - - } - catch( std::invalid_argument& e ) + // Define variable and local size + // auto& ioMyDoubles = adios.DefineVariable<double>( "myDoubles", {Nx}, + // {Nx} ); + // auto& ioMyCFloats = adios.DefineVariable<std::complex<float>>( + // "myCFloats", {3}, {3} ); + // auto& ioMyInts = adios.DefineVariable<int>( "myInts", {4,3}, {4,3} ); + + auto &ioMyDoubles = adios.DefineVariable<double>( + "myDoubles", {doubleVCount}, {Nx}, {doubleVOffset}); + auto &ioMyCFloats = adios.DefineVariable<std::complex<float>>( + "myCFloats", {floatCount}, {3}, {floatOffset}); + auto &ioMyCDoubles = adios.DefineVariable<std::complex<double>>( + "myCDoubles", {floatCount}, {3}, {floatOffset}); + auto &ioMyInts = + adios.DefineVariable<int>("myInts", {intCountDim1, intDim2}, {4, 3}, + {intOffsetDim1, intOffsetDim2}); + + // Define method for engine creation, it is basically straight-forward + // parameters + adios::Method &HDF5Settings = + adios.DeclareMethod("HDF5Writer"); // default method type is Writer + HDF5Settings.SetParameters("chunck=yes", "collectiveIO=yes"); + // HDF5Settings.AddTransport( "Mdtm", "localIP=128.0.0.0.1", + // "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); + + // Create engine smart pointer to HDF5 Engine due to polymorphism, + // Open returns a smart pointer to Engine containing the Derived class + // HDF5 + auto HDF5Writer = adios.Open("test.bp", "w", HDF5Settings); + + if (HDF5Writer == nullptr) + throw std::ios_base::failure( + "ERROR: failed to create HDF5 I/O engine at Open\n"); + + 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 * rank)); + HDF5Writer->Write(ioMyCFloats, myCFloats.data()); + HDF5Writer->Write(ioMyCDoubles, myCDoubles.data()); + HDF5Writer->Close(); + } + catch (std::invalid_argument &e) { - if( rank == 0 ) + if (rank == 0) { std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; std::cout << e.what() << "\n"; } } - catch( std::ios_base::failure& e ) + catch (std::ios_base::failure &e) { - if( rank == 0 ) + if (rank == 0) { std::cout << "System exception, STOPPING PROGRAM\n"; std::cout << e.what() << "\n"; } } - catch( std::exception& e ) + catch (std::exception &e) { - if( rank == 0 ) + if (rank == 0) { std::cout << "Exception, STOPPING PROGRAM\n"; std::cout << e.what() << "\n"; } } - MPI_Finalize( ); + MPI_Finalize(); return 0; - } diff --git a/include/engine/hdf5/HDF5ReaderP.h b/include/engine/hdf5/HDF5ReaderP.h index 959b08e91..ec5d910eb 100644 --- a/include/engine/hdf5/HDF5ReaderP.h +++ b/include/engine/hdf5/HDF5ReaderP.h @@ -8,7 +8,6 @@ * Author: Junmin */ - #ifndef HDF5_READER_P_H #define HDF5_READER_P_H diff --git a/include/engine/hdf5/HDF5WriterP.h b/include/engine/hdf5/HDF5WriterP.h index 9dc00a329..b0d703065 100644 --- a/include/engine/hdf5/HDF5WriterP.h +++ b/include/engine/hdf5/HDF5WriterP.h @@ -12,8 +12,6 @@ #ifndef HDF5_WRITER_P_H_ #define HDF5_WRITER_P_H_ -#include <unistd.h> //sleep must be removed - #include "core/Engine.h" // supported capsules diff --git a/source/ADIOS.cpp b/source/ADIOS.cpp index 47e3c333f..b3aee87e3 100644 --- a/source/ADIOS.cpp +++ b/source/ADIOS.cpp @@ -191,14 +191,16 @@ std::shared_ptr<Engine> ADIOS::Open(const std::string &name, // method, // iomode, timeout_sec, m_DebugMode, method.m_nThreads ); } - else if (type == "HDF5Writer") // -junmin - { - #if defined(ADIOS_HAVE_PHDF5) && defined(ADIOS_HAVE_MPI) - return std::make_shared<HDF5Writer>(*this, name, accessMode, mpiComm, method); - #else - throw std::invalid_argument( "ERROR: this version didn't compile with HDF5 library, can't use HDF5\n" ); - #endif - } + else if (type == "HDF5Writer") // -junmin + { +#if defined(ADIOS_HAVE_PHDF5) && defined(ADIOS_HAVE_MPI) + return std::make_shared<HDF5Writer>(*this, name, accessMode, mpiComm, + method); +#else + throw std::invalid_argument("ERROR: this version didn't compile with " + "HDF5 library, can't use HDF5\n"); +#endif + } else { diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 4c5afc475..975ae6dcc 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -88,18 +88,14 @@ if(ADIOS_USE_MPI) message(" HDF5 ROOT: ${HDF5_ROOT}") message(" HDF5 include: ${HDF5_INCLUDE_DIRS} is paralle? ${HDF5_IS_PARALLEL}") - get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) - foreach(dir ${dirs}) - message(STATUS "dir='${dir}'") - endforeach() - include_directories(${HDF5_INCLUDE_DIRS}) + target_include_directories(adios2 PRIVATE ${HDF5_INCLUDE_DIRS}) target_sources(adios2 PRIVATE engine/hdf5/HDF5ReaderP.cpp engine/hdf5/HDF5WriterP.cpp ) target_compile_definitions(adios2 PRIVATE ADIOS_HAVE_PHDF5) - target_link_libraries(adios2 PRIVATE hdf5) + target_link_libraries(adios2 PRIVATE ${HDF5_C_LIBRARIES}) endif() endif() diff --git a/source/engine/hdf5/HDF5ReaderP.cpp b/source/engine/hdf5/HDF5ReaderP.cpp index 3716bfea5..00ec0a8fb 100644 --- a/source/engine/hdf5/HDF5ReaderP.cpp +++ b/source/engine/hdf5/HDF5ReaderP.cpp @@ -8,9 +8,6 @@ * Author: Junmin */ - - #include <iostream> //needs to go away, this is just for demo purposes #include "engine/hdf5/HDF5ReaderP.h" - diff --git a/source/engine/hdf5/HDF5WriterP.cpp b/source/engine/hdf5/HDF5WriterP.cpp index 196744ac2..0ce36bf57 100644 --- a/source/engine/hdf5/HDF5WriterP.cpp +++ b/source/engine/hdf5/HDF5WriterP.cpp @@ -8,309 +8,360 @@ * Author: Junmin */ - #include <iostream> //needs to go away, this is just for demo purposes -#ifdef ADIOS_HAVE_MPI #include "engine/hdf5/HDF5WriterP.h" #include "core/Support.h" #include "functions/adiosFunctions.h" //CSVToVector -namespace adios { +namespace adios +{ HDF5Writer::HDF5Writer(ADIOS &adios, const std::string name, const std::string accessMode, MPI_Comm mpiComm, const Method &method) - : Engine(adios, "HDF5Writer", name, accessMode, mpiComm, method, /*debugMode, cores,*/ - " HDF5Writer constructor (or call to ADIOS Open).\n"), - m_Buffer(accessMode, m_RankMPI, m_DebugMode) +: Engine(adios, "HDF5Writer", name, accessMode, mpiComm, + method, /*debugMode, cores,*/ + " HDF5Writer constructor (or call to ADIOS Open).\n"), + m_Buffer(accessMode, m_RankMPI, m_DebugMode) { - // - // 16, 4 vs: 8 - //std::cout<<sizeof(std::complex<double>)<<", "<<sizeof(H5T_NATIVE_DOUBLE)<<" vs: "<<H5Tget_size(H5T_NATIVE_DOUBLE)<<std::endl; - // 8, 4 vs: 4 - //std::cout<<sizeof(std::complex<float>)<<", "<<sizeof(H5T_NATIVE_FLOAT)<<" vs: "<<H5Tget_size(H5T_NATIVE_FLOAT)<<std::endl; - // 32, 4 vs: 16 - //std::cout<<sizeof(std::complex<long double>)<<", "<<sizeof(H5T_NATIVE_LDOUBLE)<<" vs: "<<H5Tget_size(H5T_NATIVE_LDOUBLE)<<std::endl; - - DefH5T_COMPLEX_FLOAT = H5Tcreate(H5T_COMPOUND, sizeof(std::complex<float>)); - H5Tinsert(DefH5T_COMPLEX_FLOAT, "freal", 0, H5T_NATIVE_FLOAT); - H5Tinsert(DefH5T_COMPLEX_FLOAT, "fimg", H5Tget_size(H5T_NATIVE_FLOAT), H5T_NATIVE_FLOAT); + // + // 16, 4 vs: 8 + // std::cout<<sizeof(std::complex<double>)<<", + // "<<sizeof(H5T_NATIVE_DOUBLE)<<" vs: + // "<<H5Tget_size(H5T_NATIVE_DOUBLE)<<std::endl; + // 8, 4 vs: 4 + // std::cout<<sizeof(std::complex<float>)<<", "<<sizeof(H5T_NATIVE_FLOAT)<<" + // vs: "<<H5Tget_size(H5T_NATIVE_FLOAT)<<std::endl; + // 32, 4 vs: 16 + // std::cout<<sizeof(std::complex<long double>)<<", + // "<<sizeof(H5T_NATIVE_LDOUBLE)<<" vs: + // "<<H5Tget_size(H5T_NATIVE_LDOUBLE)<<std::endl; + + DefH5T_COMPLEX_FLOAT = H5Tcreate(H5T_COMPOUND, sizeof(std::complex<float>)); + H5Tinsert(DefH5T_COMPLEX_FLOAT, "freal", 0, H5T_NATIVE_FLOAT); + H5Tinsert(DefH5T_COMPLEX_FLOAT, "fimg", H5Tget_size(H5T_NATIVE_FLOAT), + H5T_NATIVE_FLOAT); - DefH5T_COMPLEX_DOUBLE = H5Tcreate(H5T_COMPOUND, sizeof(std::complex<double>)); - H5Tinsert(DefH5T_COMPLEX_DOUBLE, "dreal", 0, H5T_NATIVE_DOUBLE); - H5Tinsert(DefH5T_COMPLEX_DOUBLE, "dimg", H5Tget_size(H5T_NATIVE_DOUBLE), H5T_NATIVE_DOUBLE); + DefH5T_COMPLEX_DOUBLE = + H5Tcreate(H5T_COMPOUND, sizeof(std::complex<double>)); + H5Tinsert(DefH5T_COMPLEX_DOUBLE, "dreal", 0, H5T_NATIVE_DOUBLE); + H5Tinsert(DefH5T_COMPLEX_DOUBLE, "dimg", H5Tget_size(H5T_NATIVE_DOUBLE), + H5T_NATIVE_DOUBLE); - DefH5T_COMPLEX_LongDOUBLE = 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); + DefH5T_COMPLEX_LongDOUBLE = + 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); - Init(); + Init(); } HDF5Writer::~HDF5Writer() {} -void HDF5Writer::Init() { - if (m_AccessMode != "w" && m_AccessMode != "write" && m_AccessMode != "a" && - m_AccessMode != "append") - { - throw std::invalid_argument("ERROR: HDF5Writer doesn't support access mode " + m_AccessMode + - ", in call to ADIOS Open or HDF5Writer constructor\n"); - } - //std::cout << "method: # of inputs:" << m_Method.m_Parameters.size() << std::endl; - - //std::cout << "::Init hdf5 parallel writer. File name:" << m_Name << std::endl; - - _plist_id = H5Pcreate(H5P_FILE_ACCESS); +void HDF5Writer::Init() +{ + if (m_AccessMode != "w" && m_AccessMode != "write" && m_AccessMode != "a" && + m_AccessMode != "append") + { + throw std::invalid_argument( + "ERROR: HDF5Writer doesn't support access mode " + m_AccessMode + + ", in call to ADIOS Open or HDF5Writer constructor\n"); + } + // std::cout << "method: # of inputs:" << m_Method.m_Parameters.size() << + // std::endl; + // std::cout << "::Init hdf5 parallel writer. File name:" << m_Name << + // std::endl; - H5Pset_fapl_mpio(_plist_id, m_MPIComm, MPI_INFO_NULL); + _plist_id = H5Pcreate(H5P_FILE_ACCESS); + H5Pset_fapl_mpio(_plist_id, m_MPIComm, MPI_INFO_NULL); - /* - * Create a new file collectively and release property list identifier. - */ - _file_id = H5Fcreate(m_Name.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, _plist_id); - H5Pclose(_plist_id); + /* + * Create a new file collectively and release property list identifier. + */ + _file_id = H5Fcreate(m_Name.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, _plist_id); + H5Pclose(_plist_id); } -void HDF5Writer::Write(Variable<char> &variable, const char *values) { - UseHDFWrite(variable, values, H5T_NATIVE_CHAR); +void HDF5Writer::Write(Variable<char> &variable, const char *values) +{ + UseHDFWrite(variable, values, H5T_NATIVE_CHAR); } void HDF5Writer::Write(Variable<unsigned char> &variable, - const unsigned char *values) { - UseHDFWrite(variable, values, H5T_NATIVE_UCHAR); + const unsigned char *values) +{ + UseHDFWrite(variable, values, H5T_NATIVE_UCHAR); } -void HDF5Writer::Write(Variable<short> &variable, const short *values) { - UseHDFWrite(variable, values, H5T_NATIVE_SHORT); +void HDF5Writer::Write(Variable<short> &variable, const short *values) +{ + UseHDFWrite(variable, values, H5T_NATIVE_SHORT); } void HDF5Writer::Write(Variable<unsigned short> &variable, - const unsigned short *values) { - UseHDFWrite(variable, values, H5T_NATIVE_USHORT); + const unsigned short *values) +{ + UseHDFWrite(variable, values, H5T_NATIVE_USHORT); } -void HDF5Writer::Write(Variable<int> &variable, const int *values) { - UseHDFWrite(variable, values, H5T_NATIVE_INT); +void HDF5Writer::Write(Variable<int> &variable, const int *values) +{ + UseHDFWrite(variable, values, H5T_NATIVE_INT); } void HDF5Writer::Write(Variable<unsigned int> &variable, - const unsigned int *values) { - UseHDFWrite(variable, values, H5T_NATIVE_UINT); + const unsigned int *values) +{ + UseHDFWrite(variable, values, H5T_NATIVE_UINT); } -void HDF5Writer::Write(Variable<long int> &variable, const long int *values) { - UseHDFWrite(variable, values, H5T_NATIVE_LONG); +void HDF5Writer::Write(Variable<long int> &variable, const long int *values) +{ + UseHDFWrite(variable, values, H5T_NATIVE_LONG); } void HDF5Writer::Write(Variable<unsigned long int> &variable, - const unsigned long int *values) { - UseHDFWrite(variable, values, H5T_NATIVE_ULONG); + const unsigned long int *values) +{ + UseHDFWrite(variable, values, H5T_NATIVE_ULONG); } void HDF5Writer::Write(Variable<long long int> &variable, - const long long int *values) { - UseHDFWrite(variable, values, H5T_NATIVE_LLONG); + const long long int *values) +{ + UseHDFWrite(variable, values, H5T_NATIVE_LLONG); } void HDF5Writer::Write(Variable<unsigned long long int> &variable, - const unsigned long long int *values) { - UseHDFWrite(variable, values, H5T_NATIVE_ULLONG); + const unsigned long long int *values) +{ + UseHDFWrite(variable, values, H5T_NATIVE_ULLONG); } -void HDF5Writer::Write(Variable<float> &variable, const float *values) { - UseHDFWrite(variable, values, H5T_NATIVE_FLOAT); +void HDF5Writer::Write(Variable<float> &variable, const float *values) +{ + UseHDFWrite(variable, values, H5T_NATIVE_FLOAT); } -void HDF5Writer::Write(Variable<double> &variable, const double *values) { - UseHDFWrite(variable, values, H5T_NATIVE_DOUBLE); +void HDF5Writer::Write(Variable<double> &variable, const double *values) +{ + UseHDFWrite(variable, values, H5T_NATIVE_DOUBLE); } void HDF5Writer::Write(Variable<long double> &variable, - const long double *values) { - UseHDFWrite(variable, values, H5T_NATIVE_LDOUBLE); + const long double *values) +{ + UseHDFWrite(variable, values, H5T_NATIVE_LDOUBLE); } void HDF5Writer::Write(Variable<std::complex<float>> &variable, - const std::complex<float> *values) { - UseHDFWrite(variable, values, DefH5T_COMPLEX_FLOAT); + const std::complex<float> *values) +{ + UseHDFWrite(variable, values, DefH5T_COMPLEX_FLOAT); } void HDF5Writer::Write(Variable<std::complex<double>> &variable, - const std::complex<double> *values) { - UseHDFWrite(variable, values, DefH5T_COMPLEX_DOUBLE); + const std::complex<double> *values) +{ + UseHDFWrite(variable, values, DefH5T_COMPLEX_DOUBLE); } void HDF5Writer::Write(Variable<std::complex<long double>> &variable, - const std::complex<long double> *values) { - UseHDFWrite(variable, values, DefH5T_COMPLEX_LongDOUBLE); + const std::complex<long double> *values) +{ + UseHDFWrite(variable, values, DefH5T_COMPLEX_LongDOUBLE); } // String version -void HDF5Writer::Write(const std::string variableName, const char *values) { - UseHDFWrite(m_ADIOS.GetVariable<char>(variableName), values, H5T_NATIVE_CHAR); +void HDF5Writer::Write(const std::string variableName, const char *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<char>(variableName), values, + H5T_NATIVE_CHAR); } void HDF5Writer::Write(const std::string variableName, - const unsigned char *values) { - UseHDFWrite(m_ADIOS.GetVariable<unsigned char>(variableName), values, - H5T_NATIVE_UCHAR); + const unsigned char *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<unsigned char>(variableName), values, + H5T_NATIVE_UCHAR); } -void HDF5Writer::Write(const std::string variableName, const short *values) { - UseHDFWrite(m_ADIOS.GetVariable<short>(variableName), values, - H5T_NATIVE_SHORT); +void HDF5Writer::Write(const std::string variableName, const short *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<short>(variableName), values, + H5T_NATIVE_SHORT); } void HDF5Writer::Write(const std::string variableName, - const unsigned short *values) { - UseHDFWrite(m_ADIOS.GetVariable<unsigned short>(variableName), values, - H5T_NATIVE_USHORT); + const unsigned short *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<unsigned short>(variableName), values, + H5T_NATIVE_USHORT); } -void HDF5Writer::Write(const std::string variableName, const int *values) { - UseHDFWrite(m_ADIOS.GetVariable<int>(variableName), values, H5T_NATIVE_INT); +void HDF5Writer::Write(const std::string variableName, const int *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<int>(variableName), values, H5T_NATIVE_INT); } void HDF5Writer::Write(const std::string variableName, - const unsigned int *values) { - UseHDFWrite(m_ADIOS.GetVariable<unsigned int>(variableName), values, - H5T_NATIVE_UINT); + const unsigned int *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<unsigned int>(variableName), values, + H5T_NATIVE_UINT); } -void HDF5Writer::Write(const std::string variableName, const long int *values) { - UseHDFWrite(m_ADIOS.GetVariable<long int>(variableName), values, - H5T_NATIVE_LONG); +void HDF5Writer::Write(const std::string variableName, const long int *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<long int>(variableName), values, + H5T_NATIVE_LONG); } void HDF5Writer::Write(const std::string variableName, - const unsigned long int *values) { - UseHDFWrite(m_ADIOS.GetVariable<unsigned long int>(variableName), values, - H5T_NATIVE_ULONG); + const unsigned long int *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<unsigned long int>(variableName), values, + H5T_NATIVE_ULONG); } void HDF5Writer::Write(const std::string variableName, - const long long int *values) { - UseHDFWrite(m_ADIOS.GetVariable<long long int>(variableName), values, - H5T_NATIVE_LLONG); + const long long int *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<long long int>(variableName), values, + H5T_NATIVE_LLONG); } void HDF5Writer::Write(const std::string variableName, - const unsigned long long int *values) { - UseHDFWrite(m_ADIOS.GetVariable<unsigned long long int>(variableName), values, - H5T_NATIVE_ULLONG); + const unsigned long long int *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<unsigned long long int>(variableName), + values, H5T_NATIVE_ULLONG); } -void HDF5Writer::Write(const std::string variableName, const float *values) { - UseHDFWrite(m_ADIOS.GetVariable<float>(variableName), values, - H5T_NATIVE_FLOAT); +void HDF5Writer::Write(const std::string variableName, const float *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<float>(variableName), values, + H5T_NATIVE_FLOAT); } -void HDF5Writer::Write(const std::string variableName, const double *values) { - UseHDFWrite(m_ADIOS.GetVariable<double>(variableName), values, - H5T_NATIVE_DOUBLE); +void HDF5Writer::Write(const std::string variableName, const double *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<double>(variableName), values, + H5T_NATIVE_DOUBLE); } void HDF5Writer::Write(const std::string variableName, - const long double *values) { - UseHDFWrite(m_ADIOS.GetVariable<long double>(variableName), values, - H5T_NATIVE_LDOUBLE); + const long double *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<long double>(variableName), values, + H5T_NATIVE_LDOUBLE); } void HDF5Writer::Write(const std::string variableName, - const std::complex<float> *values) { - UseHDFWrite(m_ADIOS.GetVariable<std::complex<float>>(variableName), values, - DefH5T_COMPLEX_FLOAT); + const std::complex<float> *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<std::complex<float>>(variableName), values, + DefH5T_COMPLEX_FLOAT); } void HDF5Writer::Write(const std::string variableName, - const std::complex<double> *values) { - UseHDFWrite(m_ADIOS.GetVariable<std::complex<double>>(variableName), values, - DefH5T_COMPLEX_DOUBLE); + const std::complex<double> *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<std::complex<double>>(variableName), values, + DefH5T_COMPLEX_DOUBLE); } void HDF5Writer::Write(const std::string variableName, - const std::complex<long double> *values) { - UseHDFWrite(m_ADIOS.GetVariable<std::complex<long double>>(variableName), - values, DefH5T_COMPLEX_LongDOUBLE); + const std::complex<long double> *values) +{ + UseHDFWrite(m_ADIOS.GetVariable<std::complex<long double>>(variableName), + values, DefH5T_COMPLEX_LongDOUBLE); } -void HDF5Writer::Close(const int transportIndex) { - //std::cout << " ===> CLOSING HDF5 <===== " << std::endl; - // H5Dclose(_dset_id); - // H5Sclose(_filespace); - // H5Sclose(_memspace); - // H5Pclose(_plist_id); - H5Fclose(_file_id); +void HDF5Writer::Close(const int transportIndex) +{ + // std::cout << " ===> CLOSING HDF5 <===== " << std::endl; + // H5Dclose(_dset_id); + // H5Sclose(_filespace); + // H5Sclose(_memspace); + // H5Pclose(_plist_id); + H5Fclose(_file_id); } template <class T> void HDF5Writer::UseHDFWrite(Variable<T> &variable, const T *values, - hid_t h5type) { - // here comes your magic at Writing now variable.m_UserValues has the data - // passed by the user - // set variable - variable.m_AppValues = values; - m_WrittenVariables.insert(variable.m_Name); + hid_t h5type) +{ + // here comes your magic at Writing now variable.m_UserValues has the data + // passed by the user + // set variable + variable.m_AppValues = values; + m_WrittenVariables.insert(variable.m_Name); - int dimSize = variable.m_GlobalDimensions.size(); - /* - std::cout << "writting : " << variable.m_Name - << " dim size:" << variable.m_GlobalDimensions.size() << std::endl; + int dimSize = variable.m_GlobalDimensions.size(); + /* + std::cout << "writting : " << variable.m_Name + << " dim size:" << variable.m_GlobalDimensions.size() << + std::endl; - for (int i = 0; i < dimSize; i++) { - std::cout << " dim: " << i << ", size:" << variable.m_GlobalDimensions[i] - << " offset=" << variable.m_Offsets[i] - << " count=" << variable.m_LocalDimensions[i] << std::endl; - } - */ - std::vector<hsize_t> dimsf, count, offset; + for (int i = 0; i < dimSize; i++) { + std::cout << " dim: " << i << ", size:" << variable.m_GlobalDimensions[i] + << " offset=" << variable.m_Offsets[i] + << " count=" << variable.m_LocalDimensions[i] << std::endl; + } + */ + std::vector<hsize_t> dimsf, count, offset; - for (int i = 0; i < dimSize; i++) { - dimsf.push_back(variable.m_GlobalDimensions[i]); - count.push_back(variable.m_LocalDimensions[i]); - offset.push_back(variable.m_Offsets[i]); - } + for (int i = 0; i < dimSize; i++) + { + dimsf.push_back(variable.m_GlobalDimensions[i]); + count.push_back(variable.m_LocalDimensions[i]); + offset.push_back(variable.m_Offsets[i]); + } - _filespace = H5Screate_simple(dimSize, dimsf.data(), NULL); + _filespace = H5Screate_simple(dimSize, dimsf.data(), NULL); - _dset_id = H5Dcreate(_file_id, variable.m_Name.c_str(), h5type, _filespace, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - // H5Sclose(_filespace); + _dset_id = H5Dcreate(_file_id, variable.m_Name.c_str(), h5type, _filespace, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + // H5Sclose(_filespace); - _memspace = H5Screate_simple(dimSize, count.data(), NULL); + _memspace = H5Screate_simple(dimSize, count.data(), NULL); - // Select hyperslab - _filespace = H5Dget_space(_dset_id); - H5Sselect_hyperslab(_filespace, H5S_SELECT_SET, offset.data(), NULL, - count.data(), NULL); + // Select hyperslab + _filespace = H5Dget_space(_dset_id); + H5Sselect_hyperslab(_filespace, H5S_SELECT_SET, offset.data(), NULL, + count.data(), NULL); - // Create property list for collective dataset write. + // Create property list for collective dataset write. - _plist_id = H5Pcreate(H5P_DATASET_XFER); - H5Pset_dxpl_mpio(_plist_id, H5FD_MPIO_COLLECTIVE); + _plist_id = H5Pcreate(H5P_DATASET_XFER); + H5Pset_dxpl_mpio(_plist_id, H5FD_MPIO_COLLECTIVE); - herr_t status; + herr_t status; - status = - H5Dwrite(_dset_id, h5type, _memspace, _filespace, _plist_id, values); + status = + H5Dwrite(_dset_id, h5type, _memspace, _filespace, _plist_id, values); - if (status < 0) { - // error - std::cerr << " Write failed. " << std::endl; - } + if (status < 0) + { + // error + std::cerr << " Write failed. " << std::endl; + } - //std::cout << " ==> User is responsible for freeing the data " << std::endl; + // std::cout << " ==> User is responsible for freeing the data " << + // std::endl; - H5Dclose(_dset_id); - H5Sclose(_filespace); - H5Sclose(_memspace); - H5Pclose(_plist_id); + H5Dclose(_dset_id); + H5Sclose(_filespace); + H5Sclose(_memspace); + H5Pclose(_plist_id); } } // end namespace adios -#endif //ADIOS_HAVE_MPI + -- GitLab