dust_openmp_threads: Select number of threads

View source: R/openmp.R

dust_openmp_threadsR Documentation

Select number of threads

Description

Politely select a number of threads to use. See Details for the algorithm

Usage

dust_openmp_threads(n = NULL, action = "error")

Arguments

n

Either NULL (select automatically) or an integer as your proposed number of threads.

action

An action to perform if n exceeds the maximum number of threads you can use. Options are "error" (the default, throw an error), "fix" (print a message and reduce n down to the limit) or "message" (print a message and continue anyway)

Details

There are two limits and we will take the smaller of the two.

The first limit comes from piggy-backing off of R's normal parallel configuration; we will use the MC_CORES environment variable and mc.cores option as a guide to how many cores you are happy to use. We take mc.cores first, then MC_CORES, which is the same behaviour as parallel::mclapply and friends.

The second limit comes from openmp. If you do not have OpenMP support, then we use one thread (higher numbers have no effect at all in this case). If you do have OpenMP support, we take the smallest of the number of "processors" (reported by omp_get_num_procs()) the "max threads" (reported by omp_get_max_threads() and "thread_limit" (reported by omp_get_thread_limit().

See dust_openmp_support() for the values of all the values that go into this calculation.

Value

An integer, indicating the number of threads that you can use

Examples

# Default number of threads; tries to pick something friendly,
# erring on the conservative side.
dust::dust_openmp_threads(NULL)

# Try to pick something silly and it will be reduced for you
dust::dust_openmp_threads(1000, action = "fix")

mrc-ide/dust documentation built on Oct. 14, 2024, 12:57 a.m.