From dd7e5883dc928f4101cf4a10fac4b1bb9daeaf6c Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Thu, 7 Dec 2023 17:11:46 +0100 Subject: [PATCH 1/3] Replace hard coded value for MMPLD_DEFAULT_VERSION by existing macro Signed-off-by: Christoph Niethammer --- src/io/MmpldWriter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io/MmpldWriter.cpp b/src/io/MmpldWriter.cpp index 6c3019b468..790b8f7166 100644 --- a/src/io/MmpldWriter.cpp +++ b/src/io/MmpldWriter.cpp @@ -80,7 +80,7 @@ void MmpldWriter::readXML(XMLfileUnits& xmlconfig) Log::global_log->info() << "[MMPLD Writer] Split files every " << _numFramesPerFile << "th frame."<< std::endl; Log::global_log->info() << "[MMPLD Writer] Write buffer size: " << _writeBufferSize << " Byte" << std::endl; - int mmpldversion = 100; + int mmpldversion = MMPLD_DEFAULT_VERSION; xmlconfig.getNodeValue("mmpldversion", mmpldversion); _mmpldversion = mmpldversion; switch(_mmpldversion) { From cab91308db08bbfd5012f236e6de441bccddaafb Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Thu, 7 Dec 2023 17:17:19 +0100 Subject: [PATCH 2/3] Fix inconsistent last seek table entry in MmpldWriter output The MMPLD file format includes a seek table for the data frames. The last entry of this table should point at the end of the last frame. However, this is not identical to the file size in some cases. Correct seek table entries are already inserted by the write_frame() method. Therefore, removing the erroneous code in the finish() method. Signed-off-by: Christoph Niethammer Co-authored-by: HomesGH --- src/io/MmpldWriter.cpp | 28 ---------------------------- src/io/MmpldWriter.h | 3 +-- 2 files changed, 1 insertion(+), 30 deletions(-) diff --git a/src/io/MmpldWriter.cpp b/src/io/MmpldWriter.cpp index 790b8f7166..c48c7ab17a 100644 --- a/src/io/MmpldWriter.cpp +++ b/src/io/MmpldWriter.cpp @@ -317,34 +317,6 @@ void MmpldWriter::endStep(ParticleContainer *particleContainer, write_frame(particleContainer, domainDecomp); } -void MmpldWriter::finish(ParticleContainer * /*particleContainer*/, DomainDecompBase *domainDecomp, Domain * /*domain*/) -{ - std::string filename = getOutputFilename(); - -#ifdef ENABLE_MPI - int rank = domainDecomp->getRank(); - if (rank == 0){ - MPI_File_open(MPI_COMM_WORLD, const_cast(filename.c_str()), MPI_MODE_WRONLY, MPI_INFO_NULL, &_mpifh); - MPI_File_seek(_mpifh, 0, MPI_SEEK_END); - MPI_Offset endPosition; - MPI_File_get_position(_mpifh, &endPosition); - - uint64_t seektablePos = MMPLD_HEADER_DATA_SIZE + (_frameCount * sizeof(uint64_t)); - uint64_t seekPosition = htole64(endPosition); /** @todo end of frame offset may not be identical to file end! */ - MPI_Status status; - MPI_File_write_at(_mpifh, seektablePos, &seekPosition, sizeof(seekPosition), MPI_BYTE, &status); - uint32_t frameCount = htole32(_frameCount); // set final number of frames - // 8: frame count position in file header - MPI_File_write_at(_mpifh, 8, &frameCount, sizeof(frameCount), MPI_BYTE, &status); - MPI_File_close(&_mpifh); - }else{ - MPI_File_open(MPI_COMM_WORLD, const_cast(filename.c_str()), MPI_MODE_WRONLY, MPI_INFO_NULL, &_mpifh); - MPI_File_close(&_mpifh); - } - _seekTable.clear(); -#endif -} - void MmpldWriter::InitSphereData() { if(_bInitSphereData == ISD_READ_FROM_XML) diff --git a/src/io/MmpldWriter.h b/src/io/MmpldWriter.h index fdf0abcfcc..f17933a219 100644 --- a/src/io/MmpldWriter.h +++ b/src/io/MmpldWriter.h @@ -73,8 +73,7 @@ class MmpldWriter : public PluginBase DomainDecompBase *domainDecomp, Domain *domain, unsigned long simstep ); - void finish(ParticleContainer *particleContainer, - DomainDecompBase *domainDecomp, Domain *domain); + void finish(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) {} std::string getPluginName() { return std::string("MmpldWriter"); From 88516aa014246a614917393393d60b612e8742f0 Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Fri, 8 Dec 2023 09:47:51 +0100 Subject: [PATCH 3/3] Add sanity check in MMPLD writer for running on little endian system The MMPLD file format (version 1.2) is little endian only. The MMPLD writer uses simple byte writes without conversions so we have to make sure that we are running on a little endian system. Signed-off-by: Christoph Niethammer --- src/io/MmpldWriter.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/io/MmpldWriter.cpp b/src/io/MmpldWriter.cpp index c48c7ab17a..a4fa15ff69 100644 --- a/src/io/MmpldWriter.cpp +++ b/src/io/MmpldWriter.cpp @@ -13,7 +13,6 @@ #include #endif - #include #include #include @@ -27,8 +26,9 @@ #include "particleContainer/ParticleContainer.h" #include "parallel/DomainDecompBase.h" #include "Simulation.h" -#include "utils/Logger.h" #include "utils/FileUtils.h" +#include "utils/Logger.h" +#include "utils/mardyn_assert.h" // default version to use for mmpld format writing. possible values: 100 or 102 @@ -142,6 +142,11 @@ void MmpldWriter::readXML(XMLfileUnits& xmlconfig) void MmpldWriter::init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) { + if ( (htole32(1) != 1) || (htole64(1.0) != 1.0) ) { + Log::global_log->error() << "[MMPLD Writer] The MMPLD Writer currently only supports running on little endian systems." << std::endl; + mardyn_exit(1); + } + // only executed once this->PrepareWriteControl();