lines 6-68 of file: example/general/mul_level_adolc.cpp {xrst_begin mul_level_adolc.cpp} {xrst_spell adouble dx } Using Adolc with Multiple Levels of Taping: Example and Test ############################################################ Purpose ******* In this example, we use ``AD< adouble> >`` (level two taping), the compute values of the function :math:`f : \B{R}^n \rightarrow \B{R}` where .. math:: f(x) = \frac{1}{2} \left( x_0^2 + \cdots + x_{n-1}^2 \right) We then use Adolc's ``adouble`` (level one taping) to compute the directional derivative .. math:: f^{(1)} (x) * v = x_0 v_0 + \cdots + x_{n-1} v_{n-1} where :math:`v \in \B{R}^n`. We then use ``double`` (no taping) to compute .. math:: \frac{d}{dx} \left[ f^{(1)} (x) * v \right] = v This is only meant as an example of multiple levels of taping. The example :ref:`hes_times_dir.cpp-name` computes the same value more efficiently by using the identity: .. math:: \frac{d}{dx} \left[ f^{(1)} (x) * v \right] = f^{(2)} (x) * v The example :ref:`mul_level.cpp-name` computes the same values using ``AD< AD >`` and ``AD`` . Memory Management ***************** Adolc uses raw memory arrays that depend on the number of dependent and independent variables. The memory management utility :ref:`thread_alloc-name` is used to manage this memory allocation. Configuration Requirement ************************* This example will be compiled and tested provided :ref:`cmake@include_adolc` is true on the cmake command line. Source ****** {xrst_literal // BEGIN C++ // END C++ } {xrst_end mul_level_adolc.cpp}