Last active
          December 21, 2015 23:09 
        
      - 
      
- 
        Save aaronpuchert/6380536 to your computer and use it in GitHub Desktop. 
    Initialize "parallel" cluster on R startup
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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