R/defaultCluster.R

Defines functions defaultCluster

Documented in defaultCluster

#' Create Default Cluster for Windowing
#'
#' Creates a default cluster using one less than the total cores available on
#' the system. By default this uses forking, which is not be available on Windows.
#' Hence, the fork parameter has no effect on Windows.
#'
#' @param fork If TRUE uses forking to create the cluster (Unix like systems only)
#' @importFrom parallel detectCores makeForkCluster makeCluster
#' @export
#' @return A cluster object for parallel processing
#' @examples
#' \dontrun{
#' cl <- defaultCluster()
#' stopCluster(cl)
#' cl <- defaultCluster(FALSE)
#' stopCluster(cl)
#' }
#'
defaultCluster <- function(fork=TRUE) {
  cores <- max(1L, detectCores() - 1L)

  if (.Platform$OS.type == "windows") {
    fork <- FALSE
  }
  if (fork) {
    cluster <- makeForkCluster(cores, outfile="")
  } else {
    cluster <- makeCluster(cores, outfile="")
  }
  return(cluster)
}

Try the sonicscrewdriver package in your browser

Any scripts or data that you put into this service are public.

sonicscrewdriver documentation built on May 29, 2024, 3:39 a.m.