R/concurrency.R

Defines functions realCores

Documented in realCores

#' Detect physical cores.
#' 
#' Simple wrapper to \link{detectCores} which yields the number of
#' physical cores in Linux as well.
#' 
#' @export
realCores <- function(){
  if (Sys.info()[1] != 'Linux') {
    return(parallel::detectCores())
  }

  # Assuming the number of core ids represents the number of
  # physical cores:
  cpuinfo <- readLines('/proc/cpuinfo')
  cores <- cpuinfo[grepl('core id', cpuinfo)]
  length(unique(cores))
}
gmega/megautils documentation built on Sept. 14, 2020, 8:06 p.m.