Automatic differentiation applied to unsaturated flow - ADOL-C case study

George F. Corliss, Andreas Griewank, Stephen J. Wright, T.h. Robey1992

TL;DR

This paper explores using ADOL-C, an automatic differentiation tool, to speed up derivative calculations in a complex unsaturated flow simulation. While ADOL-C provided more accurate derivatives, it didn't offer a speedup over existing finite difference methods for this specific problem. However, the study highlights significant potential for optimization in the linear equation solver, a crucial bottleneck in such simulations.

What Problem Does This Paper Address?

Simulating unsaturated flow in porous media, especially in fractured tuff with highly variable conductivity, is computationally intensive. These simulations often rely on Newton's method to solve the resulting nonlinear equations, which requires calculating the Jacobian matrix. The original code used finite differences to approximate these derivatives, a process that can be slow and prone to accuracy issues due to the problem's high nonlinearity. The authors aimed to investigate if ADOL-C, a C++ tool for automatic differentiation, could provide a more accurate and faster way to compute the Jacobian, thereby accelerating the overall simulation.

Methods

The core of the paper involves adapting an existing C code (dual.c) for unsaturated flow to utilize ADOL-C. This conversion involved several steps:

  • C++ Conversion: The original C code was first converted to C++ to be compatible with ADOL-C.
  • ADOL-C Integration: The function responsible for computing the Jacobian was modified to use ADOL-C's adouble type for variables requiring derivative calculations.
  • Forward and Reverse Mode AD: The authors experimented with both the forward and reverse modes of automatic differentiation.
  • Forward Mode: This involved recording the computation on a "tape" and then performing forward passes to compute derivatives. They explored different strategies, including using "colors" to exploit the sparsity of the Jacobian, which led to significant speedups in the finite difference approach.
  • Reverse Mode: This mode was also investigated, with variations like "eight-vector reverse" and "eight-vector short reverse" to optimize derivative computation.
  • Exploitation of Structure: The paper emphasizes the importance of understanding and exploiting the sparse structure of the Jacobian matrix. They identified block diagonal structures and used coloring techniques to reduce the number of computations.
  • Linear Equation Solver Optimization: Beyond derivative computation, the authors also analyzed the performance of the linear equation solver, which was a major bottleneck. They explored strategies for transforming the Jacobian into a banded form for more efficient solving.

Datasets

Not discussed in the paper. The paper focuses on applying ADOL-C to an existing code for a specific scientific problem (unsaturated flow in porous media) rather than on training or evaluating on a dataset in the machine learning sense.

Key Insights and Ideas

  • ADOL-C Accuracy vs. Speed: While ADOL-C produced more accurate derivatives than finite differences, it did not lead to a speedup in this particular application. This is a crucial finding, as it suggests that the overhead of ADOL-C can outweigh its benefits in certain scenarios.
  • The Bottleneck is Not Always Where You Expect: The study revealed that the Jacobian computation, while significant, was not the primary performance bottleneck. The linear equation solver consumed a much larger portion of the computation time. This highlights the importance of profiling and identifying the true performance bottlenecks in complex simulations.
  • Structure is King: The paper strongly emphasizes the power of exploiting the inherent structure of the Jacobian matrix. Techniques like coloring for finite differences and transforming the matrix into a banded form for solvers yielded substantial performance gains.
  • Finite Differences Can Be Fast (with Structure): By cleverly using a three-color scheme to exploit the Jacobian's sparsity, the authors achieved a significant speedup (factor of two) in the finite difference Jacobian computation, outperforming their initial ADOL-C implementations.
  • Reverse Mode Nuances: The reverse mode of ADOL-C, while generally efficient for problems with more independent than dependent variables, required more passes (sweeps) than the forward mode in this case, leading to slower execution.

Key Results

  • Jacobian Computation Speed:
    • Original 6-color finite differences: 5.78 seconds
    • Optimized 3-color finite differences: 2.87 seconds
    • Fastest ADOL-C (forward mode): 5.53 seconds (twice as long as optimized finite differences)
    • ADOL-C reverse modes: 18.78 seconds (8 sweeps), 11.15 seconds (8-vector), 11.12 seconds (8-vector short)
  • Derivative Accuracy: ADOL-C provided more accurate derivative values compared to finite differences.
  • Linear Equation Solver: This part of the code took up to 430 seconds, significantly more than the Jacobian computation. Transforming the Jacobian into a banded form was identified as a promising strategy for speeding this up.

Limitations and Future Work

  • ADOL-C Speedup Not Achieved: The primary limitation is that ADOL-C did not provide a speedup for the Jacobian computation in this specific case. The authors acknowledge that the fastest ADOL-C code was twice as slow as their optimized finite difference approach.
  • Generalizability of ADOL-C: While ADOL-C can be applied to existing C/C++ codes, its performance benefits are problem-dependent.
  • Future Work:
    • Linear Equation Solver Optimization: The authors strongly recommend focusing on optimizing the linear equation solver, suggesting the use of direct banded solvers after transforming the Jacobian into a banded form.
  • Further ADOL-C Exploration: While not yielding speedups here, the accuracy benefits of ADOL-C could still be valuable in applications where convergence of Newton's method is sensitive to derivative accuracy.
  • Higher-Dimensional Problems: The strategies explored in this 1-D case study are intended to generalize to higher-dimensional problems of practical interest.
  • Rank Deficiency: The paper touches upon rank deficiency in the Jacobian due to flux boundary conditions, suggesting that further work might involve handling such cases more robustly.

Summary updated

BibTeX
@misc{corliss1992automatic,
  author = {George F. Corliss and Andreas Griewank and Stephen J. Wright and T.H. Robey},
  title = {{Automatic differentiation applied to unsaturated flow - ADOL-C case study}},
  year = {1992},
  doi = {10.2172/10148286},
}

Loading related content...

Figure