set.mcOption(value)
get.mcOption()
set.coresOption(value)
get.coresOption()
set.ClusterOption(cl)
get.ClusterOption()
makeCluster
in mc
option is set by default to FALSE on Windows systems, as they cannot fork the R session; by default it is TRUE on other systems, but may be set FALSE. If mc
is FALSE, the Cluster
option is used: if mc
is FALSE and the Cluster
option is NULL no parallel computing is done, or the Cluster
option is passed a cores
option is set to NULL by default, and can be used to store the number of cores to use as an integer. If cores
is NULL, facilities from the parallel package will not be used.ls(envir=spdep:::.spdepOptions)
library(parallel)
nc <- detectCores(logical=FALSE)
nc
nc <- ifelse(nc > 2L, 2L, nc)
coresOpt <- get.coresOption()
coresOpt
if (!is.na(nc)) {
invisible(set.coresOption(nc))
print(exists("aple.mc"))
if(.Platform$OS.type == "windows") {
# forking not permitted on Windows - start cluster
print(get.mcOption())
cl <- makeCluster(get.coresOption())
print(clusterEvalQ(cl, exists("aple.mc")))
set.ClusterOption(cl)
clusterEvalQ(get.ClusterOption(), library(spdep))
print(clusterEvalQ(cl, exists("aple.mc")))
clusterEvalQ(get.ClusterOption(), detach(package:spdep))
set.ClusterOption(NULL)
print(clusterEvalQ(cl, exists("aple.mc")))
stopCluster(cl)
} else {
mcOpt <- get.mcOption()
print(mcOpt)
print(mclapply(1:get.coresOption(), function(i) exists("aple.mc"),
mc.cores=get.coresOption()))
invisible(set.mcOption(FALSE))
cl <- makeCluster(nc)
print(clusterEvalQ(cl, exists("aple.mc")))
set.ClusterOption(cl)
clusterEvalQ(get.ClusterOption(), library(spdep))
print(clusterEvalQ(cl, exists("aple.mc")))
clusterEvalQ(get.ClusterOption(), detach(package:spdep))
set.ClusterOption(NULL)
print(clusterEvalQ(cl, exists("aple.mc")))
stopCluster(cl)
invisible(set.mcOption(mcOpt))
}
invisible(set.coresOption(coresOpt))
}
Run the code above in your browser using DataLab