On this page

Set the number of cores that a fit uses to compute standard errors and the automatic-differentiation library that TMB uses. Standard errors computed in parallel are identical to those of the sequential calculation.

Usage

alscl_speed(
  sd_cores = getOption("ALSCL.sd_cores", "auto"),
  framework = getOption("ALSCL.framework", "CppAD")
)

Arguments

ArgumentDefaultDescription
sd_coresgetOption("ALSCL.sd_cores", "auto")

"auto" or a positive integer. Cores used within one fit to compute standard errors; results are identical to the sequential calculation. Also limits refinement Hessian workers when forked processes and a checked TMB version are used. "auto" uses up to four cores and keeps one free. It counts physical cores where R can tell them from logical cores (macOS and Windows) and does not exceed the number of cores given to the job by Slurm (SLURM_CPUS_PER_TASK) or by options(mc.cores = ); forked processes compute the Hessian and the delta method on macOS and Linux, and socket workers compute the delta method on Windows, in GUI front-ends and with Apple's Accelerate BLAS. Forking is also avoided with a BLAS library that may use OpenMP threads (OpenBLAS built with OpenMP, BLIS, FlexiBLAS, Intel MKL), unless the number of threads is limited to one, for example with the environment variable OMP_NUM_THREADS=1. Fits that run on parallel socket workers (for example retro_model(), sim_acl() or fit_scenarios() with ncores greater than 1) use one core each. The same functions with ncores = 1 fit in the main process and use this setting. Set sd_cores = 1 when you run fits in your own parallel loop. Letter case does not matter.

frameworkgetOption("ALSCL.framework", "CppAD")

Character. Automatic-differentiation library that TMB compiles the model with. "CppAD" is the default; "TMBad" is faster, but its estimates differ slightly from those of "CppAD". A change takes effect at the next fit. Letter case does not matter.

Value

The previous ALSCL.sd_cores and ALSCL.framework options, returned invisibly; options(old) restores them.

Details

sd_cores computes standard errors on several cores; the results are identical to the sequential calculation. On macOS and Linux outside GUI front-ends, forked processes compute the Hessian of the scalar parameters and the delta method. On Windows, in GUI front-ends such as RStudio and with Apple's Accelerate BLAS, socket workers compute the delta method when it would take more than about 3 seconds, and the Hessian is computed in the main process. Fits that run on parallel socket workers, as in retro_model(), sim_acl() or fit_scenarios() with ncores greater than 1, use one core each; the same functions with ncores = 1 fit in the main process and use this setting. "auto" does not exceed the number of cores given to the job by Slurm (SLURM_CPUS_PER_TASK) or by options(mc.cores = ). framework = "TMBad" speeds up each evaluation of the Laplace approximation, but results differ slightly from CppAD. Use alscl_speed_info() to see what the settings mean on your computer; the speed article explains every setting.

When the refinement of a fit (polish = TRUE) needs a Hessian, it shares the sd_cores limit, with at most one process per free scalar parameter. It runs in parallel only with forked processes and a checked TMB version; fits with one free parameter, socket sessions and unchecked TMB versions compute it sequentially. If forking fails, a warning is given and the Hessian is computed sequentially. fit$refinement$hessian_calculations records the method, the cores and any fallback for each Hessian computed. An empty table means that no Hessian was returned; fit$refinement$status tells whether refinement was skipped or an evaluation failed.

Examples

Run the setup before the example. Fitting examples require an R-compatible C++ toolchain; simulation and export examples may write files.

Example setup
library(ALSCL)
# Use objects defined above
old <- alscl_speed(sd_cores = 1)
alscl_speed(framework = "TMBad")
options(old)

See also

Search documentation