Learn R Programming

BigDataStatMeth (version 2.0.3)

get_cpu_cores: Get number of CPU cores

Description

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

Usage

get_cpu_cores()

Arguments

Value

Integer with number of CPU cores

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.

See Also

get_total_ram

Examples

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

Run the code above in your browser using DataLab