R: Compile a C++ template to DLL suitable for MakeADFun.

compile {TMB} | R Documentation

## Compile a C++ template to DLL suitable for MakeADFun.

### Description

Compile a C++ template into a shared object file. OpenMP flag is set if the template is detected to be parallel.

### Usage

    compile(file, flags = "", safebounds = TRUE, safeunload = TRUE,
      openmp = isParallelTemplate(file[1]), libtmb = TRUE, libinit = TRUE,
      tracesweep = FALSE, framework = getOption("tmb.ad.framework"),
      supernodal = FALSE, longint = FALSE, eigen.disable.warnings = TRUE, ...)

### Arguments

`file` | C++ file.
`flags` | Character with compile flags.
`safebounds` | Turn on preprocessor flag for bound checking?
`safeunload` | Turn on preprocessor flag for safe DLL unloading?
`openmp` | Turn on openmp flag? Auto detected for parallel templates.
`libtmb` | Use precompiled TMB library if available (to speed up compilation)?
`libinit` | Turn on preprocessor flag to register native routines?
`tracesweep` | Turn on preprocessor flag to trace AD sweeps? (Silently disables `libtmb`)
`framework` | Which AD framework to use ('TMBad' or 'CppAD')
`supernodal` | Turn on preprocessor flag to use supernodal sparse Cholesky/Inverse from system wide suitesparse library
`longint` | Turn on preprocessor flag to use long integers for Eigen's SparseMatrix StorageIndex
`eigen.disable.warnings` | Turn on preprocessor flag to disable nuisance warnings. Note that this is not allowed for code to be compiled on CRAN.
`...` | Passed as Makeconf variables.

### Details

TMB relies on R's built in functionality to create shared libraries independent of the platform. A template is compiled by `compile("template.cpp")`, which will call R's makefile with appropriate preprocessor flags. Compiler and compiler flags can be stored in a configuration file. In order of precedence either via the file pointed at by R_MAKEVARS_USER or the file ~/.R/Makevars if it exists. Additional configuration variables can be set with the `flags` and `...` arguments, which will override any previous selections.

### Using a custom SuiteSparse installation

Sparse matrix calculations play an important role in TMB. By default TMB uses a small subset of `SuiteSparse` available through the R package `Matrix`. This is sufficient for most use cases, however for some very large models the following extra features are worth considering:

- Some large models benefit from an extended set of graph reordering algorithms (especially METIS) not part of `Matrix`. It is common that these orderings can provide quite big speedups.

- Some large models need sparse matrices with number of nonzeros exceeding the current 32 bit limitation of `Matrix`. Normally such cases will result in the cholmod error 'problem too large'. `SuiteSparse` includes 64 bit integer routines to address this problem.

Experimental support for linking to a custom `SuiteSparse` installation is available through two arguments to the `compile` function. The first argument `supernodal=TRUE` tells TMB to use the supernodal Cholesky factorization from the system wide `SuiteSparse` on the C++ side. This will affect the speed of the Laplace approximation when run internally (using arguments `intern` or `integrate` to `MakeADFun`).

The second argument `longint=TRUE` tells TMB to use 64 bit integers for sparse matrices on the C++ side. This works in combination with `supernodal=TRUE` from Eigen version 3.4.

On Windows a `SuiteSparse` installation can be obtained using the `Rtools` package manager. Start 'Rtools Bash' terminal and run:

      pacman -Sy
      pacman -S mingw-w64-{i686,x86_64}-suitesparse

On Linux one should look for the package `libsuitesparse-dev`.

### Selecting the AD framework

TMB supports two different AD libraries 'CppAD' and 'TMBad' selected via the argument `framework` which works as a switch to set one of two C++ preprocessor flags: 'CPPAD_FRAMEWORK' or 'TMBAD_FRAMEWORK'. The default value of `framework` can be set from R by `options("tmb.ad.framework")` or alternatively from the shell via the environment variable 'TMB_AD_FRAMEWORK'. Packages linking to TMB should set one of the two C++ preprocessor flags in Makevars.

### See Also

`precompile`

[Package TMB version 1.9.0 Index]