diff --git a/src/IO/ADIOS/ADIOS1IOHandler.cpp b/src/IO/ADIOS/ADIOS1IOHandler.cpp index a1131f091c..865b28a924 100644 --- a/src/IO/ADIOS/ADIOS1IOHandler.cpp +++ b/src/IO/ADIOS/ADIOS1IOHandler.cpp @@ -37,7 +37,7 @@ namespace openPMD { #if openPMD_HAVE_ADIOS1 # if openPMD_USE_VERIFY -# define VERIFY(CONDITION, TEXT) { if(!(CONDITION)) throw std::runtime_error(std::string((TEXT))); } +# define VERIFY(CONDITION, TEXT) { if(!(CONDITION)) throw std::runtime_error((TEXT)); } # else # define VERIFY(CONDITION, TEXT) do{ (void)sizeof(CONDITION); } while( 0 ) # endif diff --git a/src/IO/ADIOS/ParallelADIOS1IOHandler.cpp b/src/IO/ADIOS/ParallelADIOS1IOHandler.cpp index 41e7a25a1a..031cc6c070 100644 --- a/src/IO/ADIOS/ParallelADIOS1IOHandler.cpp +++ b/src/IO/ADIOS/ParallelADIOS1IOHandler.cpp @@ -35,7 +35,7 @@ namespace openPMD { #if openPMD_HAVE_ADIOS1 && openPMD_HAVE_MPI # if openPMD_USE_VERIFY -# define VERIFY(CONDITION, TEXT) { if(!(CONDITION)) throw std::runtime_error(std::string((TEXT))); } +# define VERIFY(CONDITION, TEXT) { if(!(CONDITION)) throw std::runtime_error((TEXT)); } # else # define VERIFY(CONDITION, TEXT) do{ (void)sizeof(CONDITION); } while( 0 ) # endif @@ -52,32 +52,30 @@ ParallelADIOS1IOHandlerImpl::ParallelADIOS1IOHandlerImpl(AbstractIOHandler* hand ParallelADIOS1IOHandlerImpl::~ParallelADIOS1IOHandlerImpl() { - /* create all files where ADIOS file creation has been deferred, - * but execution of the deferred operation has never been triggered - * (happens when no Operation::WRITE_DATASET is performed) */ - for( auto& f : m_existsOnDisk ) - { - if( !f.second ) - { - int64_t fd; - int status; - status = adios_open(&fd, - f.first->c_str(), - f.first->c_str(), - "w", - m_mpiComm); - if( status != err_no_error ) - std::cerr << "Internal error: Failed to open_flush ADIOS file\n"; - - m_openWriteFileHandles[f.first] = fd; - } - } - for( auto& f : m_openReadFileHandles ) close(f.second); + m_openReadFileHandles.clear(); - for( auto& f : m_openWriteFileHandles ) - close(f.second); + if( this->m_handler->accessType != AccessType::READ_ONLY ) + { + for( auto& f : m_openWriteFileHandles ) + close(f.second); + m_openWriteFileHandles.clear(); + + for( auto& group : m_attributeWrites ) + for( auto& att : group.second ) + flush_attribute(group.first, att.first, att.second); + + /* create all files, even if ADIOS file creation has been deferred, + * but execution of the deferred operation has never been triggered + * (happens when no Operation::WRITE_DATASET is performed) */ + for( auto& f : m_filePaths ) + if( m_openWriteFileHandles.find(f.second) == m_openWriteFileHandles.end() ) + m_openWriteFileHandles[f.second] = open_write(f.first); + + for( auto& f : m_openWriteFileHandles ) + close(f.second); + } int status; MPI_Barrier(m_mpiComm); diff --git a/src/IO/HDF5/HDF5IOHandler.cpp b/src/IO/HDF5/HDF5IOHandler.cpp index b8b6f76cc7..1ee85cdd92 100644 --- a/src/IO/HDF5/HDF5IOHandler.cpp +++ b/src/IO/HDF5/HDF5IOHandler.cpp @@ -40,7 +40,7 @@ namespace openPMD { #if openPMD_HAVE_HDF5 # if openPMD_USE_VERIFY -# define VERIFY(CONDITION, TEXT) { if(!(CONDITION)) throw std::runtime_error(std::string((TEXT))); } +# define VERIFY(CONDITION, TEXT) { if(!(CONDITION)) throw std::runtime_error((TEXT)); } # else # define VERIFY(CONDITION, TEXT) do{ (void)sizeof(CONDITION); } while( 0 ) # endif diff --git a/src/IO/HDF5/ParallelHDF5IOHandler.cpp b/src/IO/HDF5/ParallelHDF5IOHandler.cpp index 1bd1e70298..3ea27f60b6 100644 --- a/src/IO/HDF5/ParallelHDF5IOHandler.cpp +++ b/src/IO/HDF5/ParallelHDF5IOHandler.cpp @@ -32,7 +32,7 @@ namespace openPMD { #if openPMD_HAVE_HDF5 && openPMD_HAVE_MPI # if openPMD_USE_VERIFY -# define VERIFY(CONDITION, TEXT) { if(!(CONDITION)) throw std::runtime_error(std::string((TEXT))); } +# define VERIFY(CONDITION, TEXT) { if(!(CONDITION)) throw std::runtime_error((TEXT)); } # else # define VERIFY(CONDITION, TEXT) do{ (void)sizeof(CONDITION); } while( 0 ) # endif diff --git a/test/CoreTest.cpp b/test/CoreTest.cpp index f159b6e5a6..d38f3d1069 100644 --- a/test/CoreTest.cpp +++ b/test/CoreTest.cpp @@ -607,3 +607,14 @@ TEST_CASE( "use_count_test", "[core]" ) REQUIRE(static_cast< Parameter< Operation::WRITE_DATASET >* >(pprc.m_chunks->front().parameter.get())->data.use_count() == 1); #endif } + +TEST_CASE( "empty_record_test", "[core]" ) +{ + Series o = Series("./new_openpmd_output", AccessType::CREATE); + + o.iterations[1].meshes["E"].setComment("No assumption about contained RecordComponents will be made"); + REQUIRE_THROWS_WITH(o.flush(), + Catch::Equals("A Record can not be written without any contained RecordComponents: E")); + o.iterations[1].meshes["E"][RecordComponent::SCALAR].resetDataset(Dataset(Datatype::DOUBLE, {1})); + o.flush(); +} \ No newline at end of file diff --git a/test/SerialIOTest.cpp b/test/SerialIOTest.cpp index 6c694854d0..333719c3a1 100644 --- a/test/SerialIOTest.cpp +++ b/test/SerialIOTest.cpp @@ -953,13 +953,6 @@ TEST_CASE( "hdf5_write_test", "[serial][hdf5]" ) std::generate(position_global.begin(), position_global.end(), [&pos]{ return pos++; }); std::vector< double > position_local = {0.}; e["position"]["x"].resetDataset(Dataset(determineDatatype(), {4})); - - for( uint64_t i = 0; i < 4; ++i ) - { - position_local.at(0) = position_global[i]; - e["position"]["x"].storeChunk({i}, {1}, shareRaw(position_local)); - } - std::vector< uint64_t > positionOffset_global(4); uint64_t posOff{0}; std::generate(positionOffset_global.begin(), positionOffset_global.end(), [&posOff]{ return posOff++; }); @@ -968,12 +961,13 @@ TEST_CASE( "hdf5_write_test", "[serial][hdf5]" ) for( uint64_t i = 0; i < 4; ++i ) { + position_local.at(0) = position_global[i]; + e["position"]["x"].storeChunk({i}, {1}, shareRaw(position_local)); positionOffset_local[0] = positionOffset_global[i]; e["positionOffset"]["x"].storeChunk({i}, {1}, shareRaw(positionOffset_local)); + o.flush(); } - o.flush(); - //TODO close file, read back, verify }