get_recommended_threads

get_recommended_threads

SYSTEM_UTILS

1 Description

Returns a recommended number of threads for parallel operations, based on available CPU cores and system load.

2 Usage

get_recommended_threads(use_fraction = 0.8)

3 Arguments

Parameter Description
use_fraction Numeric. Fraction of available cores to use (default 0.8). Using all cores (1.0) may overload the system.

4 Value

Integer with recommended number of threads (minimum 1)

5 Details

This function uses the C++ implementation to detect CPU cores and returns a conservative estimate leaving room for the OS and other processes.

Default behavior (use_fraction = 0.8): - 4 cores → 3 threads - 8 cores → 6 threads - 16 cores → 13 threads

6 Examples

\donttest{
# Get recommended threads
threads <- get_recommended_threads()

# Use for OpenMP operations
options(BigDataStatMeth.threads = threads)

# More aggressive (use 90% of cores)
threads <- get_recommended_threads(use_fraction = 0.9)
}

7 See Also