openmp: Control number of OpenMP threads used by a TMB model.

View source: R/TMB.R

openmpR Documentation

Control number of OpenMP threads used by a TMB model.

Description

Control number of OpenMP threads used by a TMB model.

Usage

openmp(n = NULL, max = FALSE, autopar = NULL, DLL = getUserDLL())

Arguments

n

Requested number of threads, or NULL to just read the current value.

max

Logical; Set n to OpenMP runtime value 'omp_get_max_threads()'?

autopar

Logical; use automatic parallelization - see details.

DLL

DLL of a TMB model.

Details

This function controls the number of parallel threads used by a TMB model compiled with OpenMP. The number of threads is part of the configuration list config() of the DLL. The value only affects parallelization of the DLL. It does not affect BLAS/LAPACK specific parallelization which has to be specified elsewhere.

When a DLL is loaded, the number of threads is set to 1 by default. To activate parallelization you have to explicitly call openmp(nthreads) after loading the DLL. Calling openmp(max=TRUE) should normally pick up the environment variable OMP_NUM_THREADS, but this may be platform dependent.

An experimental option autopar=TRUE can be set to parallelize models automatically. This requires the model to be compiled with framework="TMBad" and openmp=TRUE without further requirements on the C++ code. If the C++ code already has explicit parallel constructs these will be ignored if automatic parallelization is enabled.

Value

Number of threads.


TMB documentation built on Nov. 27, 2023, 5:12 p.m.

Related to openmp in TMB...