get_cpu_cores

get_cpu_cores

SYSTEM_UTILS

1 Description

Returns the number of logical CPU cores (processors) available.

2 Usage

get_cpu_cores()

3 Value

Integer with number of CPU cores

4 Details

This function returns the number of logical processors, which includes cores from hyperthreading/SMT. Useful for configuring parallel processing.

Typical values: - 4-core CPU without hyperthreading: 4 - 4-core CPU with hyperthreading: 8 - 8-core CPU with hyperthreading: 16

Usage for parallelization: Don’t blindly use all cores. A common practice is to use 80-90 percent of available cores to leave room for the OS and other processes.

5 Examples

\donttest{
# Get CPU cores
cores <- get_cpu_cores()
cat("System has", cores, "CPU cores\n")

# Configure parallel processing (use 80 percent of cores)
threads <- max(1, floor(cores * 0.8))
options(BigDataStatMeth.threads = threads)
}

6 See Also