Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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, ...)

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.

Value

The new value of the environment variable RCPP_PARALLEL_NUM_THREADS.

Note

The mechanism for setting the number of threads changed between versions 4.1.0 and 4.2.0. The default number of cores is now capped at 2 to meet CRAN requirements. Setting ncores = NULL previously specified one less than the number of available cores.

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

Examples

# determine current number of threads

setNumThreads()

# set new number of threads

setNumThreads(2)

## Not run: 

# 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()


## End(Not run)

secr

Spatially Explicit Capture-Recapture

v4.4.1
GPL (>= 2)
Authors
Murray Efford
Initial release
2021-05-01

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.