ESIO  0.2.0
Writing restart files

ESIO provides several methods that greatly simplify writing a sequence of metadata-rich restart files. Each restart file might contain a simulation snapshot at a particular time along with enough information to track how the data was generated and to allow data post-processing.

A complete, C-based MPI program using ESIO to write a (trivial) sequence of restart files might look like:

1 #include <stdlib.h>
2 #include <mpi.h>
3 #include <esio/esio.h>
4 
5 int main(int argc, char *argv[])
6 {
7  // Initialize MPI and arrange for its finalization
8  MPI_Init(&argc, &argv);
9  atexit((void (*) ()) MPI_Finalize);
10  int world_size, world_rank;
11  MPI_Comm_size(MPI_COMM_WORLD, &world_size);
12  MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
13 
14  // Create restart file template filled with metadata on a subset of ranks
15  if (world_rank == 0) {
16  esio_handle s = esio_handle_initialize(MPI_COMM_SELF);
17  esio_file_create(s, "template.h5", 1 /* overwrite */);
18  esio_string_set(s, "/", "program", argv[0]);
19  esio_string_set(s, "/", "built", __DATE__ " " __TIME__);
21  }
22  MPI_Barrier(MPI_COMM_WORLD); // Prevent template create/clone race
23 
24  // Prepare a handle informed about the parallel domain decomposition
25  esio_handle w = esio_handle_initialize(MPI_COMM_WORLD);
26  esio_line_establish(w, 2*world_size, 2*world_rank, 2);
27 
28  // Main simulation loop would customarily be driven by time advancement
29  double state[2];
30  for (int i = 0; i < 10; ++i) {
31 
32  // Pretend to update simulation state for demonstration purposes
33  state[0] = i * world_rank;
34  state[1] = i * world_rank + 1;
35 
36  // Create an uncommitted restart file based on the template
37  esio_file_clone(w, "template.h5", "uncommitted.h5", 1 /*overwrite*/);
38 
39  // Save the current simulation state in the uncommitted restart
40  esio_line_write_double(w, "state", state, 1, "A comment");
41 
42  // Commit the restart file. Here, up to 5 older restarts are retained
43  esio_file_close_restart(w, "committed#.h5", 5 /*retain_count*/);
44  }
45 
47 }

This sample prepares a copy of loop-invariant data in the file "template.h5". Often this would include the program version, scenario parameters, and grid information. Then, when the code needs to write a new restart file during the simulation loop, a new uncommitted restart file called "uncommitted.h5" is cloned from "template.h5" using esio_file_clone(). After the program has successfully written all the necessary data to the restart file, the restart file is committed using esio_file_close_restart().

The documentation for the esio_file_close_restart() method contains several important details. The same functionality is also available in Fortran via the methods esio::esio_file_clone() and esio::esio_file_close_restart().

Using such an approach provides several benefits:

  1. Common metadata is written only once. In a long-running simulation, this may provide some performance benefits compared to repeatedly writing the same metadata within the simulation loop.
  2. Incomplete restart data is kept separate from complete restart data. This prevents a software or hardware failure from destroying your simulation's last known good state.
  3. A history of restart data is maintained. This is useful when simulation statistics must be gathered across multiple snapshots.

ESIO also provides a standalone, non-HDF5 utility named esio_restart which can be used to test ESIO's restart file management capabilities. See esio_rename –help for more details.

esio_handle_initialize
esio_handle esio_handle_initialize(MPI_Comm comm)
Initialize a handle against the given MPI communicator.
esio_string_set
int esio_string_set(const esio_handle h, const char *location, const char *name, const char *value)
Set a string-valued attribute.
esio.h
esio_file_create
int esio_file_create(esio_handle h, const char *file, int overwrite)
Create a new file or overwrite an existing one.
esio_file_close_restart
int esio_file_close_restart(esio_handle h, const char *restart_template, int retain_count)
Close the currently open file and rename it to match the path given in restart_template.
esio_line_establish
int esio_line_establish(esio_handle h, int aglobal, int astart, int alocal)
Establish the parallel decomposition to use for subsequent line operations.
esio_handle_finalize
int esio_handle_finalize(esio_handle h)
Finalize a handle.
esio_file_clone
int esio_file_clone(esio_handle h, const char *srcfile, const char *dstfile, int overwrite)
Create and open a new file by cloning the contents of an existing file.
esio_handle
struct esio_handle_s * esio_handle
An opaque type following ESIO's handle concept.
Definition: esio.h:44
esio::esio_line_write_double
subroutine esio_line_write_double(handle, name, line, astride, comment, ierr)
Definition: esio.F90:1182

Generated on Sat Jul 4 2026 17:52:45 for ESIO by  doxygen 1.8.17