Optimal program execution reversal

Andreas Griewank, Andrea WaltherANZIAM 2000

Abstract: For adjoint calculations, debugging, and similar purposes one may need to reverse the execution of a computer program. The simplest option of recording a complete execution log and then reading it backwards requires massive amounts of storage. Instead one may generate the execution log piecewise by restarting the "forward" calculation repeatedly from suitably placed checkpoints. Our goal is to minimize the temporal and spatial complexity as measured by the number of evaluation repeats and the number of checkpoints, respectively. We present optimal checkpointing schedules for one-step and multi-step evolutions. These might arise for example as discretizations of ODEs by Euler's methods or multi-step schemes, respectively. Furthermore, we present parallel extensions, where auxiliary processors perform the repeated forward evaluations such that one processor can run backward without any interruption. For either case the length of the evolution that can be reversed is shown to grow exponentially with the number of checkpoints and either the number of repetitions or the number of processors.

Introduction

In fields such as meteorology, engineering design, and machine learning, researchers frequently need to calculate the "gradient" or sensitivity of complex simulations. The most efficient method for this is the reverse mode of Algorithmic Differentiation (AD). While computationally efficient, the reverse mode requires the program to run backward, which traditionally necessitates storing every intermediate state. For simulations involving millions of time steps, this storage requirement can reach terabytes, making it practically impossible.

This paper establishes a mathematical foundation for "checkpointing" — storing only a few select states and re-running the forward simulation from those points when needed. The authors focus on finding the optimal schedule: determining which states to save and when to re-calculate to minimize total time within a fixed memory budget.

Serial Reversal and the Persistence Principle

The authors model program execution as a sequence of transformations ($z_i = F_i(z_{i-1})$). For a single processor, they utilize Dynamic Programming (DP) to identify the optimal schedule. A key insight is the "Checkpoint Persistence" principle: in an optimal schedule, once a checkpoint is created, it remains fixed until the reversal process "reaches" it from the right. This allows the problem to be broken down into smaller, recursive sub-problems.

For a fixed number of checkpoints $c$, the temporal overhead grows as $\sqrt[c]{l}$, where $l$ is the number of steps. This represents a highly favorable trade-off, where a minor increase in computation time enables a massive reduction in memory usage. The authors prove that these optimal serial schedules can be computed efficiently in $O(cl^2)$ operations.

Parallel Reversal and Resource Interchangeability

When multiple processors are available, the authors introduce a "just-in-time" delivery system. While one processor performs the backward sweep without interruption, auxiliary processors perform forward "recording" steps in parallel.

A central concept in the parallel approach is the "resource number" ($\rho = p + c$), where $p$ is the number of processors and $c$ is the number of checkpoints. The authors treat these as somewhat interchangeable assets for extending the reversible length of the program. In the parallel case where the cost of a return step equals a forward step, the maximum reversible length follows a Fibonacci-like recurrence: $l_\rho = l_{\rho-1} + l_{\rho-2}$.

Key Insights and Scalability

  • Exponential Growth: The most striking finding is that the maximum number of steps ($l$) that can be reversed grows exponentially with the number of checkpoints ($c$). Adding just a few more units of memory allows for a massive increase in the size of the problem that can be solved.
  • Mega-steps for Multi-step Methods: While complex ODE solvers (multi-step methods) require more data per checkpoint, the authors show that treating groups of steps as "mega-steps" yields results that are nearly as optimal as more complex, specialized schedules.
  • Concrete Scalability: The theory shows that just 8 processors and 8 checkpoints are sufficient to reverse over 32,000 time steps (assuming the return step is twice as expensive as the forward step).

These strategies have been implemented in practical software tools, including the Revolve library and the ADOL-C package for C/C++ differentiation.

Limitations and Future Directions

The current framework relies on several simplifying assumptions. First, it assumes a constant state size, meaning every checkpoint occupies the same amount of memory. This may not hold for programs using adaptive grids or dynamic data structures. Second, the parallel theory assumes integer cost ratios for backward-to-forward steps, whereas real-world applications may exhibit more variability. Finally, the parallel approach is designed for a shared memory model; extending this to distributed systems with high communication latency remains an area for future research.

Summary updated

BibTeX
@inproceedings{griewank2000optimal,
  author = {Andreas Griewank and Andrea Walther},
  title = {{Optimal program execution reversal}},
  booktitle = {ANZIAM},
  year = {2000},
  doi = {10.21914/anziamj.v42i0.616},
}
Figure