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 may not be available on 'Windows'.
#'
#' @param fork If TRUE uses forking to create the cluster
#' @keywords wave
#' @import parallel
#' @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(1, detectCores() - 1)
  if (fork) {
    cluster <- makeForkCluster(cores)
  } else {
    cluster <- makeCluster(cores)
  }
  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 2, 2021, 5:06 p.m.