From ffc2037a07942abd19cffe51c239deccb49ade05 Mon Sep 17 00:00:00 2001 From: dutta-alankar Date: Thu, 19 Nov 2026 00:31:19 +0100 Subject: [PATCH 1/5] Fix restarts so that they reproduce uninterrupted runs bit-for-bit - TimeIntegrator: store the cycle count in restart dumps (as a double, exact up to 2^53) and resume it on restart. The parity of ncycles sets the order of the RKL and hydro steps (Strang splitting); restarting at ncycles=0 from a dump written after an odd cycle flipped that order and made the restarted run diverge from the uninterrupted one. -maxcycles, the final performance figure and the cycle count reported at the end still refer to the cycles performed in the current run, and the log header is now also printed after a restart. - Dump: zero-pad strings (header, field names) up to their fixed size. Uninitialised bytes after the terminating null made otherwise identical dumps differ. - Xdmf: store xdmfFileNumber in restart dumps, as done for vtk, so that xdmf outputs do not start again from 0 after a restart. --- src/main.cpp | 8 ++++---- src/output/dump.cpp | 10 ++++++++-- src/output/xdmf.cpp | 4 ++++ src/timeIntegrator.cpp | 18 +++++++++++++++++- src/timeIntegrator.hpp | 9 +++++++++ 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b46c8a43..488d7aed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -229,7 +229,7 @@ int main( int argc, char* argv[] ) { break; } if(input.maxCycles>=0) { - if(Tint.GetNCycles() >= input.maxCycles) { + if(Tint.GetNCyclesThisRun() >= input.maxCycles) { idfx::cout << "Main: Reached maximum number of integration cycles." << std::endl; break; } @@ -247,7 +247,7 @@ int main( int argc, char* argv[] ) { n_seconds = divres.rem; double perfs = timer.seconds() / grid.np_int[IDIR] / grid.np_int[JDIR] - / grid.np_int[KDIR] / Tint.GetNCycles() * idfx::psize; + / grid.np_int[KDIR] / Tint.GetNCyclesThisRun() * idfx::psize; idfx::cout << "Main: Reached t=" << data.t << std::endl; idfx::cout << "Main: Completed in "; @@ -277,8 +277,8 @@ int main( int argc, char* argv[] ) { idfx::cout << "s"; } idfx::cout << " "; - idfx::cout << "and " << Tint.GetNCycles() << " cycle"; - if (Tint.GetNCycles() != 1) { + idfx::cout << "and " << Tint.GetNCyclesThisRun() << " cycle"; + if (Tint.GetNCyclesThisRun() != 1) { idfx::cout << "s"; } idfx::cout << std::endl; diff --git a/src/output/dump.cpp b/src/output/dump.cpp index 4d0a6371..9e888eca 100644 --- a/src/output/dump.cpp +++ b/src/output/dump.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include "dump.hpp" #include "dataBlockHost.hpp" #include "gridHost.hpp" @@ -251,16 +253,20 @@ Dump::~Dump() { } void Dump::WriteString(IdfxFileHandler fileHdl, char *str, int size) { + /* Pad with zeros after the terminating null: the callers' buffers are not initialised + beyond it, and writing them as they are would make identical dumps differ. */ + std::vector padded(size, 0); + std::strncpy(padded.data(), str, size); #ifdef WITH_MPI MPI_Status status; MPI_SAFE_CALL(MPI_File_set_view(fileHdl, this->offset, MPI_BYTE, MPI_CHAR, "native", MPI_INFO_NULL )); if(idfx::prank==0) { - MPI_SAFE_CALL(MPI_File_write(fileHdl, str, size, MPI_CHAR, &status)); + MPI_SAFE_CALL(MPI_File_write(fileHdl, padded.data(), size, MPI_CHAR, &status)); } offset=offset+size; #else - if(fwrite (str, sizeof(char), size, fileHdl) != size) { + if(fwrite (padded.data(), sizeof(char), size, fileHdl) != size) { IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); } #endif diff --git a/src/output/xdmf.cpp b/src/output/xdmf.cpp index aceda037..d0154a6f 100644 --- a/src/output/xdmf.cpp +++ b/src/output/xdmf.cpp @@ -289,6 +289,10 @@ Xdmf::Xdmf(Input &input, DataBlock *datain) { } #endif #endif + + // Register variables that are required in restart dumps + if(data->dump.get() != nullptr) + data->dump->RegisterVariable(&xdmfFileNumber, "xdmfFileNumber"); } int Xdmf::Write() { diff --git a/src/timeIntegrator.cpp b/src/timeIntegrator.cpp index e5183df9..c5365206 100644 --- a/src/timeIntegrator.cpp +++ b/src/timeIntegrator.cpp @@ -70,6 +70,9 @@ TimeIntegrator::TimeIntegrator(Input & input, DataBlock & data) { data.t=0.0; ncycles=0; + ncyclesDump=0.0; + // dumps without this field (older code) leave it at 0, i.e. the old behaviour + data.dump->RegisterVariable(&ncyclesDump, "ncycles"); if(nstages==2) { wc[0] = 0.5; @@ -119,7 +122,8 @@ void TimeIntegrator::ShowLog(DataBlock &data) { int col_width{16}; - if (ncycles == 0) { + if (!logHeaderDone) { + logHeaderDone = true; idfx::cout << "TimeIntegrator: "; idfx::cout << std::setw(col_width) << "time"; idfx::cout << " | " << std::setw(col_width) << "cycle"; @@ -267,6 +271,13 @@ void TimeIntegrator::Cycle(DataBlock &data) { idfx::pushRegion("TimeIntegrator::Cycle"); + if(firstCycle) { + // fresh run: 0; restart: the cycle count stored in the dump + ncycles = static_cast(ncyclesDump); + ncyclesStart = ncycles; + firstCycle = false; + } + if(ncycles%cyclePeriod==0) ShowLog(data); // Launch user step before everything @@ -427,6 +438,7 @@ void TimeIntegrator::Cycle(DataBlock &data) { ncycles++; + ncyclesDump = static_cast(ncycles); idfx::popRegion(); } @@ -435,6 +447,10 @@ int64_t TimeIntegrator::GetNCycles() { return(ncycles); } +int64_t TimeIntegrator::GetNCyclesThisRun() { + return(ncycles-ncyclesStart); +} + // Check whether our maximumruntime has been reached. Reduce the results on all of the cores // to make sure they stop simultaneously even if running time are not perfectly in sync bool TimeIntegrator::CheckForMaxRuntime() { diff --git a/src/timeIntegrator.hpp b/src/timeIntegrator.hpp index fc828889..44bafaa6 100644 --- a/src/timeIntegrator.hpp +++ b/src/timeIntegrator.hpp @@ -27,6 +27,7 @@ class TimeIntegrator { public: int64_t GetNCycles(); // Get current number of cycles + int64_t GetNCyclesThisRun(); // Get number of cycles performed since (re)start // Constructor from input and given datablock TimeIntegrator(Input &, DataBlock &); @@ -62,6 +63,14 @@ class TimeIntegrator { real cflMaxVar; // Max CFL variation number real maxdivB{0}; // Maximum allowed divB int64_t ncycles; // # of cycles + // ncycles is an int64_t, which the dumps cannot store: mirror it in a double (exact up to + // 2^53) so that a restart resumes the cycle count, and with it the parity that sets the + // order of the RKL and hydro steps in Cycle(). Without it a restart from a dump written + // after an odd cycle flips that order and departs from the uninterrupted run. + double ncyclesDump{0.0}; + bool firstCycle{true}; // ncycles has not yet been synced with ncyclesDump + int64_t ncyclesStart{0}; // value of ncycles at the start of this run + bool logHeaderDone{false}; // the log header has been printed double computeLastLog; // Timer for actual computeTime From e2cf3ddc3c709b618cc1c1fa41653d4373b92af2 Mon Sep 17 00:00:00 2001 From: dutta-alankar Date: Thu, 19 Nov 2026 00:33:59 +0100 Subject: [PATCH 2/5] Xdmf: do not record object timestamps in HDF5 files By default HDF5 stores access, modification, change and birth times in each object header, so HDF5 files holding identical data differ byte for byte, e.g. between a restart and the uninterrupted run, or between two runs of the same setup. Disable time tracking on the file (root group), group and dataset creation property lists. --- src/output/xdmf.cpp | 34 +++++++++++++++++++++++++--------- src/output/xdmf.hpp | 3 +++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/output/xdmf.cpp b/src/output/xdmf.cpp index d0154a6f..09270c1e 100644 --- a/src/output/xdmf.cpp +++ b/src/output/xdmf.cpp @@ -325,6 +325,16 @@ int Xdmf::Write() { filename = outputDirectory/ssfileName.str(); filename_xmf = outputDirectory/ssfileNameXmf.str(); + // Do not record access/modification/change/birth times in the object headers: identical + // data would otherwise produce files that differ, e.g. between a restart and the + // uninterrupted run. + fcplNoTimes = H5Pcreate(H5P_FILE_CREATE); // applies to the root group + H5Pset_obj_track_times(fcplNoTimes, false); + gcplNoTimes = H5Pcreate(H5P_GROUP_CREATE); + H5Pset_obj_track_times(gcplNoTimes, false); + dcplNoTimes = H5Pcreate(H5P_DATASET_CREATE); + H5Pset_obj_track_times(dcplNoTimes, false); + #ifdef WITH_MPI hid_t file_access = H5Pcreate(H5P_FILE_ACCESS); // #if MPI_POSIX == YES @@ -332,16 +342,17 @@ int Xdmf::Write() { // #else H5Pset_fapl_mpio(file_access, MPI_COMM_WORLD, MPI_INFO_NULL); // #endif - hid_t fileHdf = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, file_access); + hid_t fileHdf = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, fcplNoTimes, file_access); H5Pclose(file_access); #else - hid_t fileHdf = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + hid_t fileHdf = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, fcplNoTimes, H5P_DEFAULT); #endif hid_t group_fields; // = static_cast(malloc(sizeof(hid_t))); std::stringstream ssgroup_name; ssgroup_name << "/Timestep_" << xdmfFileNumber; - hid_t timestep = H5Gcreate(fileHdf, ssgroup_name.str().c_str(), 0); + hid_t timestep = H5Gcreate2(fileHdf, ssgroup_name.str().c_str(), H5P_DEFAULT, + gcplNoTimes, H5P_DEFAULT); WriteHeader(fileHdf, ssfileName.str(), filename_xmf, data->t, timestep, group_fields); @@ -431,6 +442,9 @@ int Xdmf::Write() { H5Gclose(group_fields); // Close group "vars" H5Gclose(timestep); H5Fclose(fileHdf); + H5Pclose(dcplNoTimes); + H5Pclose(gcplNoTimes); + H5Pclose(fcplNoTimes); xdmfFileNumber++; // Make file number @@ -582,7 +596,7 @@ void Xdmf::WriteHeader( H5Sclose(strspace); /* Create group_fields "vars" (cell-centered vars) */ - group_fields = H5Gcreate(timestep, "vars", 0); + group_fields = H5Gcreate2(timestep, "vars", H5P_DEFAULT, gcplNoTimes, H5P_DEFAULT); /* Define "coords" attribute of group_fields "vars" */ dimstr = 3; @@ -602,7 +616,7 @@ void Xdmf::WriteHeader( hsize_t count[DIMENSIONS]; /* Create group "cell_coords" (centered mesh) */ - group = H5Gcreate(fileHdf, "cell_coords", 0); + group = H5Gcreate2(fileHdf, "cell_coords", H5P_DEFAULT, gcplNoTimes, H5P_DEFAULT); #if (DIMENSIONS == 1) || (DIMENSIONS == 3) for (int dir = 0; dir < DIMENSIONS; dir++) { @@ -644,7 +658,8 @@ void Xdmf::WriteHeader( DUMP_DATATYPE *cell_mesh; for (int dir = 0; dir < 3; dir++) { - dataset = H5Dcreate(group, directions[dir].c_str(), H5_DUMP_DATATYPE, dataspace, H5P_DEFAULT); + dataset = H5Dcreate(group, directions[dir].c_str(), H5_DUMP_DATATYPE, dataspace, + dcplNoTimes); cell_mesh = Kokkos::subview (this->cell_coord, dir, Kokkos::ALL(), @@ -668,7 +683,7 @@ void Xdmf::WriteHeader( H5Gclose(group); /* Close group "cell_coords" */ /* Create group "node_coords" (node mesh) */ - group = H5Gcreate(fileHdf, "node_coords", 0); + group = H5Gcreate2(fileHdf, "node_coords", H5P_DEFAULT, gcplNoTimes, H5P_DEFAULT); #if (DIMENSIONS == 1) || (DIMENSIONS == 3) for (int dir = 0; dir < DIMENSIONS; dir++) { @@ -717,7 +732,8 @@ void Xdmf::WriteHeader( #endif for (int dir = 0; dir < 3; dir++) { - dataset = H5Dcreate(group, directions[dir].c_str(), H5_DUMP_DATATYPE, dataspace, H5P_DEFAULT); + dataset = H5Dcreate(group, directions[dir].c_str(), H5_DUMP_DATATYPE, dataspace, + dcplNoTimes); DUMP_DATATYPE *node_mesh = Kokkos::subview (this->node_coord, dir, @@ -832,7 +848,7 @@ void Xdmf::WriteScalar( // We define the dataset that contain the fields. dataset = H5Dcreate(group_fields, var_name.c_str(), H5_DUMP_DATATYPE, - dataspace, H5P_DEFAULT); + dataspace, dcplNoTimes); #ifdef WITH_MPI err = H5Dwrite(dataset, H5_DUMP_DATATYPE, memspace, dataspace, plist_id_mpiio, Vin); diff --git a/src/output/xdmf.hpp b/src/output/xdmf.hpp index 8af8348f..bbd856a7 100644 --- a/src/output/xdmf.hpp +++ b/src/output/xdmf.hpp @@ -100,6 +100,9 @@ class Xdmf { // output directory std::filesystem::path outputDirectory; + // HDF5 creation property lists that disable object timestamps (set in Write()) + hid_t fcplNoTimes, gcplNoTimes, dcplNoTimes; + #ifdef WITH_MPI int mpi_data_start[3]; int mpi_data_size[3]; From 213f9dbdf32d288eb4bd980d484914fa1d00538f Mon Sep 17 00:00:00 2001 From: dutta-alankar Date: Thu, 19 Nov 2026 11:32:32 +0100 Subject: [PATCH 3/5] Xdmf: keep HDF5 object timestamps, except in debug builds HDF5 object timestamps are useful metadata, and h5diff, which compares the content of the files, ignores them. Record them again by default (HDF5's own default), and only disable them when Idefix_DEBUG is on, so that debug builds still produce byte-identical .h5 files for identical data (e.g. a restart vs the uninterrupted run). Document this alongside the other effects of Idefix_DEBUG. --- doc/source/programmingguide.rst | 5 +++- doc/source/reference/makefile.rst | 3 +- src/output/xdmf.cpp | 48 +++++++++++++++++-------------- src/output/xdmf.hpp | 4 +-- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/doc/source/programmingguide.rst b/doc/source/programmingguide.rst index d8f989df..60c6da4c 100644 --- a/doc/source/programmingguide.rst +++ b/doc/source/programmingguide.rst @@ -743,7 +743,10 @@ adding ``-DIdefix_DEBUG=ON`` when calling cmake). This forces the code to log ea returned (this is achieved thanks to the ``idfx::pushRegion(std::string)`` and ``idfx::popRegion()`` which are found at the beginning and end of each function). In addition, ``Idefix_DEBUG`` will force *Idefix* to wait for each ``idefix_for`` to finish before continuing to the next instruction (otherwise, ``idefix_for`` are asynchronous when using -an accelerator). This simplifies the detection and identification of bugs in ``idefix_for`` loops. Note that all of these +an accelerator). This simplifies the detection and identification of bugs in ``idefix_for`` loops. Finally, ``Idefix_DEBUG`` +stops HDF5 (XDMF) outputs from recording the access/modification/change/birth times of their objects, so that runs producing +identical data (e.g. a restart and the uninterrupted run) produce byte-identical ``.h5`` files. Outside of debug builds, these +files differ by these timestamps only, and ``h5diff`` can be used to compare their content. Note that all of these debugging features induce a large overhead, and should therefore not be activated in production runs. If you suspect an out-of-bound access, it may be worth enabling additionaly ``Kokkos_ENABLE_BOUNDS_CHECK`` that will check diff --git a/doc/source/reference/makefile.rst b/doc/source/reference/makefile.rst index 5f86c66f..8fd6bfd7 100644 --- a/doc/source/reference/makefile.rst +++ b/doc/source/reference/makefile.rst @@ -44,7 +44,8 @@ Several options can be enabled from the command line (or are accessible with ``c ``-D Idefix_DEBUG=ON`` Enable debug options in *Idefix*. This triggers a lot of outputs, and automatic bound checks of array accesses. As a result, this - option makes the code very slow. + option makes the code very slow. It also stops HDF5 outputs from recording object timestamps, so that identical data produce + byte-identical ``.h5`` files. ``-D Idefix_RUNTIME_CHECKS=ON`` Include (potentially expensive) runtime sanity checks implemented with ``RUNTIME_CHECK_HOST`` and ``RUNTIME_CHECK_KERNEL``. diff --git a/src/output/xdmf.cpp b/src/output/xdmf.cpp index 09270c1e..1f6a195e 100644 --- a/src/output/xdmf.cpp +++ b/src/output/xdmf.cpp @@ -325,15 +325,21 @@ int Xdmf::Write() { filename = outputDirectory/ssfileName.str(); filename_xmf = outputDirectory/ssfileNameXmf.str(); - // Do not record access/modification/change/birth times in the object headers: identical - // data would otherwise produce files that differ, e.g. between a restart and the - // uninterrupted run. - fcplNoTimes = H5Pcreate(H5P_FILE_CREATE); // applies to the root group - H5Pset_obj_track_times(fcplNoTimes, false); - gcplNoTimes = H5Pcreate(H5P_GROUP_CREATE); - H5Pset_obj_track_times(gcplNoTimes, false); - dcplNoTimes = H5Pcreate(H5P_DATASET_CREATE); - H5Pset_obj_track_times(dcplNoTimes, false); + // By default HDF5 records access/modification/change/birth times in the object headers, + // so files holding identical data differ byte for byte (h5diff, which compares the + // content, still reports them as identical). Debug builds do not record these times, + // so that outputs can be compared byte for byte, e.g. a restart vs the uninterrupted run. + #ifdef DEBUG + constexpr bool trackTimes = false; + #else + constexpr bool trackTimes = true; + #endif + fcpl = H5Pcreate(H5P_FILE_CREATE); // applies to the root group + H5Pset_obj_track_times(fcpl, trackTimes); + gcpl = H5Pcreate(H5P_GROUP_CREATE); + H5Pset_obj_track_times(gcpl, trackTimes); + dcpl = H5Pcreate(H5P_DATASET_CREATE); + H5Pset_obj_track_times(dcpl, trackTimes); #ifdef WITH_MPI hid_t file_access = H5Pcreate(H5P_FILE_ACCESS); @@ -342,17 +348,17 @@ int Xdmf::Write() { // #else H5Pset_fapl_mpio(file_access, MPI_COMM_WORLD, MPI_INFO_NULL); // #endif - hid_t fileHdf = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, fcplNoTimes, file_access); + hid_t fileHdf = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, fcpl, file_access); H5Pclose(file_access); #else - hid_t fileHdf = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, fcplNoTimes, H5P_DEFAULT); + hid_t fileHdf = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, fcpl, H5P_DEFAULT); #endif hid_t group_fields; // = static_cast(malloc(sizeof(hid_t))); std::stringstream ssgroup_name; ssgroup_name << "/Timestep_" << xdmfFileNumber; hid_t timestep = H5Gcreate2(fileHdf, ssgroup_name.str().c_str(), H5P_DEFAULT, - gcplNoTimes, H5P_DEFAULT); + gcpl, H5P_DEFAULT); WriteHeader(fileHdf, ssfileName.str(), filename_xmf, data->t, timestep, group_fields); @@ -442,9 +448,9 @@ int Xdmf::Write() { H5Gclose(group_fields); // Close group "vars" H5Gclose(timestep); H5Fclose(fileHdf); - H5Pclose(dcplNoTimes); - H5Pclose(gcplNoTimes); - H5Pclose(fcplNoTimes); + H5Pclose(dcpl); + H5Pclose(gcpl); + H5Pclose(fcpl); xdmfFileNumber++; // Make file number @@ -596,7 +602,7 @@ void Xdmf::WriteHeader( H5Sclose(strspace); /* Create group_fields "vars" (cell-centered vars) */ - group_fields = H5Gcreate2(timestep, "vars", H5P_DEFAULT, gcplNoTimes, H5P_DEFAULT); + group_fields = H5Gcreate2(timestep, "vars", H5P_DEFAULT, gcpl, H5P_DEFAULT); /* Define "coords" attribute of group_fields "vars" */ dimstr = 3; @@ -616,7 +622,7 @@ void Xdmf::WriteHeader( hsize_t count[DIMENSIONS]; /* Create group "cell_coords" (centered mesh) */ - group = H5Gcreate2(fileHdf, "cell_coords", H5P_DEFAULT, gcplNoTimes, H5P_DEFAULT); + group = H5Gcreate2(fileHdf, "cell_coords", H5P_DEFAULT, gcpl, H5P_DEFAULT); #if (DIMENSIONS == 1) || (DIMENSIONS == 3) for (int dir = 0; dir < DIMENSIONS; dir++) { @@ -659,7 +665,7 @@ void Xdmf::WriteHeader( DUMP_DATATYPE *cell_mesh; for (int dir = 0; dir < 3; dir++) { dataset = H5Dcreate(group, directions[dir].c_str(), H5_DUMP_DATATYPE, dataspace, - dcplNoTimes); + dcpl); cell_mesh = Kokkos::subview (this->cell_coord, dir, Kokkos::ALL(), @@ -683,7 +689,7 @@ void Xdmf::WriteHeader( H5Gclose(group); /* Close group "cell_coords" */ /* Create group "node_coords" (node mesh) */ - group = H5Gcreate2(fileHdf, "node_coords", H5P_DEFAULT, gcplNoTimes, H5P_DEFAULT); + group = H5Gcreate2(fileHdf, "node_coords", H5P_DEFAULT, gcpl, H5P_DEFAULT); #if (DIMENSIONS == 1) || (DIMENSIONS == 3) for (int dir = 0; dir < DIMENSIONS; dir++) { @@ -733,7 +739,7 @@ void Xdmf::WriteHeader( for (int dir = 0; dir < 3; dir++) { dataset = H5Dcreate(group, directions[dir].c_str(), H5_DUMP_DATATYPE, dataspace, - dcplNoTimes); + dcpl); DUMP_DATATYPE *node_mesh = Kokkos::subview (this->node_coord, dir, @@ -848,7 +854,7 @@ void Xdmf::WriteScalar( // We define the dataset that contain the fields. dataset = H5Dcreate(group_fields, var_name.c_str(), H5_DUMP_DATATYPE, - dataspace, dcplNoTimes); + dataspace, dcpl); #ifdef WITH_MPI err = H5Dwrite(dataset, H5_DUMP_DATATYPE, memspace, dataspace, plist_id_mpiio, Vin); diff --git a/src/output/xdmf.hpp b/src/output/xdmf.hpp index bbd856a7..0ff76492 100644 --- a/src/output/xdmf.hpp +++ b/src/output/xdmf.hpp @@ -100,8 +100,8 @@ class Xdmf { // output directory std::filesystem::path outputDirectory; - // HDF5 creation property lists that disable object timestamps (set in Write()) - hid_t fcplNoTimes, gcplNoTimes, dcplNoTimes; + // HDF5 creation property lists for the file, groups and datasets (set in Write()) + hid_t fcpl, gcpl, dcpl; #ifdef WITH_MPI int mpi_data_start[3]; From 224a0e58f6b9f4c5bada837f7c0b46cbb8bfd16f Mon Sep 17 00:00:00 2001 From: Geoffroy Lesur Date: Wed, 25 Nov 2026 09:37:01 +0100 Subject: [PATCH 4/5] Use int64 for cycle count in dumps (now supported by #423) Register ncycles directly as int64_t instead of mirroring it in a double. Simplify TimeIntegrator by removing the ncyclesDump mirror and the associated static_casts. --- src/timeIntegrator.cpp | 8 +++----- src/timeIntegrator.hpp | 9 ++------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/timeIntegrator.cpp b/src/timeIntegrator.cpp index 7a4b8259..54ea6206 100644 --- a/src/timeIntegrator.cpp +++ b/src/timeIntegrator.cpp @@ -70,9 +70,8 @@ TimeIntegrator::TimeIntegrator(Input & input, DataBlock & data) { data.t=0.0; ncycles=0; - ncyclesDump=0.0; // dumps without this field (older code) leave it at 0, i.e. the old behaviour - data.dump->RegisterVariable(&ncyclesDump, "ncycles"); + data.dump->RegisterVariable(&ncycles, "ncycles"); if(nstages==2) { wc[0] = 0.5; @@ -272,8 +271,8 @@ void TimeIntegrator::Cycle(DataBlock &data) { idfx::pushRegion("TimeIntegrator::Cycle"); if(firstCycle) { - // fresh run: 0; restart: the cycle count stored in the dump - ncycles = static_cast(ncyclesDump); + // capture the cycle count at the start of this run (0 for a fresh run, + // the value stored in the dump for a restart) ncyclesStart = ncycles; firstCycle = false; } @@ -438,7 +437,6 @@ void TimeIntegrator::Cycle(DataBlock &data) { ncycles++; - ncyclesDump = static_cast(ncycles); idfx::popRegion(); } diff --git a/src/timeIntegrator.hpp b/src/timeIntegrator.hpp index 44bafaa6..f707a560 100644 --- a/src/timeIntegrator.hpp +++ b/src/timeIntegrator.hpp @@ -62,13 +62,8 @@ class TimeIntegrator { real cfl; // CFL number real cflMaxVar; // Max CFL variation number real maxdivB{0}; // Maximum allowed divB - int64_t ncycles; // # of cycles - // ncycles is an int64_t, which the dumps cannot store: mirror it in a double (exact up to - // 2^53) so that a restart resumes the cycle count, and with it the parity that sets the - // order of the RKL and hydro steps in Cycle(). Without it a restart from a dump written - // after an odd cycle flips that order and departs from the uninterrupted run. - double ncyclesDump{0.0}; - bool firstCycle{true}; // ncycles has not yet been synced with ncyclesDump + int64_t ncycles; // # of cycles (stored in dumps as int64, resumed on restart) + bool firstCycle{true}; // ncyclesStart has not yet been captured int64_t ncyclesStart{0}; // value of ncycles at the start of this run bool logHeaderDone{false}; // the log header has been printed From 3b8b227ad1613f3d869f4e047980958a67934328 Mon Sep 17 00:00:00 2001 From: Geoffroy Lesur Date: Wed, 25 Nov 2026 09:44:06 +0100 Subject: [PATCH 5/5] Fix duplicate include in dump.cpp (cpplint) --- src/output/dump.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/output/dump.cpp b/src/output/dump.cpp index 6f7dbbb0..29d43c43 100644 --- a/src/output/dump.cpp +++ b/src/output/dump.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include "dump.hpp" #include "dataBlockHost.hpp" #include "gridHost.hpp"