Learn R Programming

secr (version 4.6.10)

setNumThreads: Number of Threads

Description

Set or report the number of cores to be used for multi-threaded operations. A wrapper for the RcppParallel function setThreadOptions (Allaire et al. 2019).

Usage

setNumThreads(ncores, ...)

Value

The new value of the environment variable RCPP_PARALLEL_NUM_THREADS.

Arguments

ncores

integer number of threads to use

...

other arguments passed to RcppParallel::setThreadOptions, specifically stackSize

Details

If ncores is NULL then the current value of the environment variable RCPP_PARALLEL_NUM_THREADS is used. RCPP_PARALLEL_NUM_THREADS defaults to 2 at the start of a session (assuming at least 2 logical cores available).

Calling setNumThreads() with no arguments is a handy way to check how many threads are in use.

The value of RCPP_PARALLEL_NUM_THREADS is also reset when a multi-threaded function such as secr.fit is called with a non-NULL value of the ncores argument. This value applies in later calls of secr.fit with ncores = NULL until changed.

References

Allaire, J. J., Francois, R., Ushey, K., Vandenbrouck, G., Geelnard, M. and Intel (2019) RcppParallel: Parallel Programming Tools for 'Rcpp'. R package version 4.4.4. https://CRAN.R-project.org/package=RcppParallel.

See Also

Parallel, setThreadOptions Sys.getenv

Examples

Run this code

# determine current number of threads

setNumThreads()

if (FALSE) {

# set new number of threads
setNumThreads(7)

# a call to secr.fit that specifies 'ncores' also sets the 
# number of threads, as we see here

fit <- secr.fit(captdata, trace = FALSE, ncores = 8)
setNumThreads()

}

Run the code above in your browser using DataLab