esio  0.1.9
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 */
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 */
15  esio_handle h = esio_handle_initialize(MPI_COMM_WORLD);
16  esio_file_create(h, "template.h5", 1 /* overwrite */);
17  esio_string_set(h, "/", "program", argv[0]);
18  esio_file_close(h);
19 
20  /* Establish the parallel decomposition */
21  esio_line_establish(h, 2*world_size, 2*world_rank, 2);
22 
23  /* Main simulation loop */
24  double example[2];
25  for (int i = 0; i < 10; ++i) {
26 
27  /* Update simulation state */
28  example[0] = i * world_rank;
29  example[1] = i * world_rank + 1;
30 
31  /* Create an uncommitted restart file based on the template */
32  esio_file_clone(h, "template.h5", "uncommitted.h5", 1 /*overwrite*/);
33 
34  /* Save the current simulation state in the uncommitted restart */
35  esio_line_write_double(h, "example", example, 1, NULL);
36 
37  /* Commit the restart file. Up to 5 older restarts are retained. */
38  esio_file_close_restart(h, "committed#.h5", 5 /*retain_count*/);
39  }
40 
42 
43  return 0;
44 }

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.


Generated on Thu Jan 16 2014 10:16:33 for esio by  doxygen 1.8.2