Skip to content
This repository

AD computation with Template Model Builder (TMB)

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 TMB
Octocat-spinner-32 admb_examples
Octocat-spinner-32 compare
Octocat-spinner-32 dox
Octocat-spinner-32 slides
Octocat-spinner-32 tmb_examples
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Makefile
Octocat-spinner-32 install_windows.R

Template Model Builder (TMB)

TMB is an R package with functionality similar to ADMB. It requires R at least version 3.0.0 and development tools needed to install R packages from source. The package is installed from the command line by entering the adcomb folder and typing

  • make install

To build the manual type

  • make pdf

Once the package is successfully installed it can be tested by starting R and running


Alternative platforms


Tested to work on 64 bit R with latest Rtools. Currently not working with 32 bit R.

Install instructions

  1. Start 64 bit R and change working directory to the (cloned or unzipped) adcomp folder.

  2. From R run: source("install_windows.R")

The required Rtools will be downloaded and installed. Note that the PATH variable need not be changed by the installer or otherwise edited. The PATH will be automatically set for each TMB session.


  • Parallel user templates work, including changing the number of threads from R.
  • Filenames and folders with spaces should be ok.
  • -Wall flag disabled by default.

Mac OS X

Tested to work with both llvm-gcc-4.2 and clang. Fortran compiler libraries must be installed. According to R admin manual "the OpenMP support in this version of gcc is problematic, and the alternative, clang, has no OpenMP support". So, parallel templates with OS X will require a different compiler installed.

Linux specific notes

Metis orderings

For large 3D random field models the ordering algorithms shipping with R's Matrix package are far from optimal. To get better orderings available run the following in the terminal:

  • sudo apt-get install libsuitesparse-metis-3.1.0

This will install a more complete version of CHOLMOD with more orderings available. Then install TMB like this:

  • make install-metis

For a quick example of how to use it start R, load TMB and run

  • runExample("ar1xar1")

Issues with library unloading

On recent versions of gcc the following problem may be encountered: When the user cpp file is changed, re-compiled and re-loaded, the changes does not take place. To see if you are affected by this issue, assuming your compiled DLL is called "", try running:

  • readelf -s | grep UNIQUE

If this gives a lot of output it is not possible to unload the library, and R will have to be restarted every time the model is re-compiled. A workaround is to use clang++ instead of gcc.

Something went wrong with that request. Please try again.