Skip to content

Instantly share code, notes, and snippets.

@aaronpuchert
Last active December 21, 2015 23:09
Show Gist options
  • Save aaronpuchert/6380536 to your computer and use it in GitHub Desktop.
Save aaronpuchert/6380536 to your computer and use it in GitHub Desktop.
Initialize "parallel" cluster on R startup
require("utils")
require("parallel")
# do not start in RStudio
if (Sys.getenv("RSTUDIO_USER_IDENTITY") == "" && !file.exists(".cluster")) {
cat(Sys.getpid(), file=".cluster")
Cluster <- makeCluster(detectCores())
}
.First <- function() source("src/main.r") # should load all other sources
.Last <- function() {
if (exists("Cluster")) {
stopCluster(Cluster)
file.remove(".cluster")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment