setNumThreads: Number of Threads

setNumThreadsR Documentation

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

Parallel, setThreadOptions Sys.getenv

Examples


# determine current number of threads

setNumThreads()

## Not run: 

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


## End(Not run)


secr documentation built on Nov. 4, 2024, 9:06 a.m.