# NAG Library Routine Document

## 1Purpose

x10bd_a1w_f gets the callback computational mode from a configuration data structure for the NAG AD Library as created by a prior call to x10aa_a1w_f.

## 2Specification

Fortran Interface
 Subroutine x10bd_a1w_f ( mode,
 Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: mode Type (c_ptr), Intent (In) :: ad_handle
C++ Header Interface
#include <nagad.h>
extern "C" {
 void x10bd_a1w_f_ (void *&ad_handle, Integer &mode, Integer &ifail)
}
VBA (Long integers) Header Interface
 Declare PtrSafe Sub X10BDF Lib "libname" ( _ ad_handle As LongPtr, mode As Long, ifail As Long)

## 3Description

x10bd_a1w_f gets, when the symbolic computational mode is being used, the callback computational mode from the configuration data object as created by x10aa_a1w_f and passed to a user-supplied procedure argument (callback) of a NAG AD Library routine. This mode is then used to determine the form of computation that is required to be performed by the symbolic callback for which the mode has been set and obtained. The full set of computational modes for symbolic callbacks currently supplied are: nagad_primal, nagad_dstate, nagad_dparam and nagad_dall. Within a user-supplied callback, different forms of computation are expected at different times. These are: the primal calculation of the callback (nagad_primal); the derivatives of the primal calculation with respect to real-valued input arguments (nagad_dstate); the derivatives of the primal calculation with respect to any user-supplied real-valued input data, e.g., in the argument ruser (nagad_dparam); and, in combining nagad_dstate and nagad_dparam, derivatives of the primal calculation with respect to all active input arguments (nagad_dall).
Note that in the case where the algorithmic computation mode is being used and the primal callback operation involves only standard operations and intrinsic functions then the callback computational mode is not relevant and no companion callback need be supplied. When the symbolic computational mode is being used the callback computational mode must be interrogated to determine the form of operation required, even when this is to be performed using operator overloading rather than via companion callbacks (see Section 10 in c05ay_a1w_f).

### 3.1Life Cycle of the Handle

Each handle should pass four stages in its life: initialization; mode setting; problem solution using the NAG AD Library; and, destruction.
The initialization by x10aa_a1w_f and destruction by x10ab_a1w_f mark the beginning and the end of the life of the handle. During this time the handle must only be modified by NAG AD Library routines. Working with a handle which has not been properly initialized is potentially very dangerous as it may cause unpredictable behaviour.
After the handle has been initialized, two routines are provided to set or get the callback computational mode to determine the form of computation to be performed by a supplied procedure argument. If, for example, a callback needs to know the computational mode in order to provide differentials appropriately, x10bd_a1w_f will return the current computational mode as stored in the ad_handle.
When all AD computation is completed, the handle must be destroyed by x10ab_a1w_f.

None.

## 5Arguments

1:     $\mathbf{ad_handle}$ – Type (c_ptr)Input
On entry: a handle to the AD configuration data object, as created by x10aa_a1w_f.
2:     $\mathbf{mode}$ – IntegerOutput
On exit: the callback computational mode as stored in the AD configuration data object with handle ad_handle.
${\mathbf{mode}}=\mathit{nagad_primal}$
The current callback is expected to perform the primal calculation.
${\mathbf{mode}}=\mathit{nagad_dstate}$
The current callback is expected to return the derivatives of the primal calculation with respect to real-valued input arguments.
${\mathbf{mode}}=\mathit{nagad_dparam}$
The current callback is expected to return the derivatives of the primal calculation with respect to user-supplied real-valued inputs (e.g., in ruser).
${\mathbf{mode}}=\mathit{nagad_dall}$
The current callback is expected to return derivatives of the primal calculation with respect to both active input arguments and active supplied parameters (i.e., combining nagad_dstate and nagad_dparam).
3:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, . If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value  is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value  is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry: ad_handle is not a valid handle for the AD computational data object. Either ad_handle has not been initialized or it has become corrupted.
${\mathbf{ifail}}=2$
Unexpected value of mode set on exit, ${\mathbf{mode}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{mode}}=\mathit{nagad_primal}$, $\mathit{nagad_dstate}$, $\mathit{nagad_dparam}$ or $\mathit{nagad_dall}$.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

Not applicable.

## 8Parallelism and Performance

x10bd_a1w_f is not threaded in any implementation.

None.

## 10Example

See examples for computational routines in the NAG AD Library, for example, Section 10 in c05ay_a1w_f.