Learn R Programming

BigDataStatMeth (version 2.0.3)

get_recommended_threads: Get recommended number of threads for parallel operations

Description

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

Usage

get_recommended_threads(use_fraction = 0.8)

Value

Integer with recommended number of threads (minimum 1)

Arguments

use_fraction

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

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

See Also

get_cpu_cores

Examples

Run this code
# \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)
# }

Run the code above in your browser using DataLab