Run multiple R-scripts simultaneously

前端 未结 5 1351
名媛妹妹
名媛妹妹 2020-12-07 23:22

In my thesis I need to perform a lot of simulation studies, which all takes quite a while. My computer has 4 cores, so I have been wondering if it is possible to run for exa

5条回答
  •  一向
    一向 (楼主)
    2020-12-07 23:52

    You can achieve multicore parallelism (as explained here https://cran.r-project.org/web/packages/doMC/vignettes/gettingstartedMC.pdf) in the same session with the following code

    if(Sys.info()["sysname"]=="Windows"){
      library(doParallel)
      cl<-makeCluster(numberOfCores)
      registerDoParallel(cl)
    }else{
      library(doMC)
      registerDoMC(numberOfCores)
    }
    library(foreach)
    
    someList<-list("file1","file2")
    returnComputation <-
      foreach(x=someList) %dopar%{
        source(x)
      }
    
    
    if(Sys.info()["sysname"]=="Windows") stopCluster(cl)
    

    You will need still adapt your output.

提交回复
热议问题