Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/source/programmingguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion doc/source/reference/makefile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
8 changes: 4 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 ";
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/output/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include "dump.hpp"
#include "dataBlockHost.hpp"
#include "gridHost.hpp"
Expand Down Expand Up @@ -218,16 +219,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<char> 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
Expand Down
44 changes: 35 additions & 9 deletions src/output/xdmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -321,23 +325,40 @@ int Xdmf::Write() {
filename = outputDirectory/ssfileName.str();
filename_xmf = outputDirectory/ssfileNameXmf.str();

// 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);
// #if MPI_POSIX == YES
// H5Pset_fapl_mpiposix(file_access, MPI_COMM_WORLD, 1);
// #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, fcpl, 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, fcpl, H5P_DEFAULT);
#endif

hid_t group_fields; // = static_cast<hid_t *>(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,
gcpl, H5P_DEFAULT);

WriteHeader(fileHdf, ssfileName.str(), filename_xmf, data->t, timestep, group_fields);

Expand Down Expand Up @@ -427,6 +448,9 @@ int Xdmf::Write() {
H5Gclose(group_fields); // Close group "vars"
H5Gclose(timestep);
H5Fclose(fileHdf);
H5Pclose(dcpl);
H5Pclose(gcpl);
H5Pclose(fcpl);

xdmfFileNumber++;
// Make file number
Expand Down Expand Up @@ -578,7 +602,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, gcpl, H5P_DEFAULT);

/* Define "coords" attribute of group_fields "vars" */
dimstr = 3;
Expand All @@ -598,7 +622,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, gcpl, H5P_DEFAULT);

#if (DIMENSIONS == 1) || (DIMENSIONS == 3)
for (int dir = 0; dir < DIMENSIONS; dir++) {
Expand Down Expand Up @@ -640,7 +664,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,
dcpl);
cell_mesh = Kokkos::subview (this->cell_coord,
dir,
Kokkos::ALL(),
Expand All @@ -664,7 +689,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, gcpl, H5P_DEFAULT);

#if (DIMENSIONS == 1) || (DIMENSIONS == 3)
for (int dir = 0; dir < DIMENSIONS; dir++) {
Expand Down Expand Up @@ -713,7 +738,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,
dcpl);

DUMP_DATATYPE *node_mesh = Kokkos::subview (this->node_coord,
dir,
Expand Down Expand Up @@ -828,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, H5P_DEFAULT);
dataspace, dcpl);
#ifdef WITH_MPI
err = H5Dwrite(dataset, H5_DUMP_DATATYPE, memspace, dataspace,
plist_id_mpiio, Vin);
Expand Down
3 changes: 3 additions & 0 deletions src/output/xdmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class Xdmf {
// output directory
std::filesystem::path outputDirectory;

// 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];
int mpi_data_size[3];
Expand Down
16 changes: 15 additions & 1 deletion src/timeIntegrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ TimeIntegrator::TimeIntegrator(Input & input, DataBlock & data) {

data.t=0.0;
ncycles=0;
// dumps without this field (older code) leave it at 0, i.e. the old behaviour
data.dump->RegisterVariable(&ncycles, "ncycles");

if(nstages==2) {
wc[0] = 0.5;
Expand Down Expand Up @@ -119,7 +121,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";
Expand Down Expand Up @@ -267,6 +270,13 @@ void TimeIntegrator::Cycle(DataBlock &data) {

idfx::pushRegion("TimeIntegrator::Cycle");

if(firstCycle) {
// 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;
}

if(ncycles%cyclePeriod==0) ShowLog(data);

// Launch user step before everything
Expand Down Expand Up @@ -435,6 +445,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() {
Expand Down
6 changes: 5 additions & 1 deletion src/timeIntegrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &);
Expand Down Expand Up @@ -61,7 +62,10 @@ class TimeIntegrator {
real cfl; // CFL number
real cflMaxVar; // Max CFL variation number
real maxdivB{0}; // Maximum allowed divB
int64_t ncycles; // # of cycles
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

double computeLastLog; // Timer for actual computeTime

Expand Down
Loading