R/parallelsetting.r

Defines functions ataIsClusterEnabled ataClusterClearObj ataStopCluster ataStartCluster

Documented in ataIsClusterEnabled ataStartCluster ataStopCluster

## atakriging
## Author: Maogui Hu.

ataStartCluster <- function(spec = min(parallel::detectCores(), 8), ...) {
  cl <- getOption("ataKrigCluster")
  if(!is.null(cl)) try(snow::stopCluster(cl), silent = TRUE)

  cl <- snow::makeCluster(spec = spec, ...)
  doSNOW::registerDoSNOW(cl)
  options(ataKrigCluster = cl)
  cl
}


ataStopCluster <- function() {
  cl <- getOption("ataKrigCluster")
  if(!is.null(cl)) try(stopCluster(cl), silent = TRUE)
  options(ataKrigCluster = NULL)
}


ataClusterClearObj <- function() {
  cl <- getOption("ataKrigCluster")
  if(!is.null(cl)) try(clusterEvalQ(cl, "rm(list=ls())"), silent = TRUE)
}


ataIsClusterEnabled <- function() {
  return(!is.null(getOption("ataKrigCluster")))
}

Try the atakrig package in your browser

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

atakrig documentation built on Oct. 9, 2023, 5:10 p.m.