Created
July 7, 2015 22:24
-
-
Save akiatoji/eaafffd6929f1cc13395 to your computer and use it in GitHub Desktop.
Benchmark parallel R backends
This file contains 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
# Quick and dirty comparison of parallelism in R | |
#import packages | |
library(doMC) | |
library(doMPI) | |
library(foreach) | |
library(doParallel) | |
#number of iterations and procs | |
iters<-1e4 | |
procs <- 2 | |
################################################### | |
# Run with stock doParallel | |
cl<-makeCluster(procs) | |
registerDoParallel(cl) | |
strt<-Sys.time() | |
ls<-foreach(icount(iters)) %dopar% { | |
to.ls<-rnorm(1e6) | |
to.ls<-summary(to.ls) | |
to.ls | |
} | |
print("Parallel Procs") | |
print(Sys.time()-strt) | |
stopCluster(cl) | |
################################################### | |
# Run with doMC (supposingly subsumed into stock R) | |
registerDoMC(procs) | |
strt<-Sys.time() | |
ls<-foreach(icount(iters)) %dopar% { | |
to.ls<-rnorm(1e6) | |
to.ls<-summary(to.ls) | |
to.ls | |
} | |
print("Parallel Core") | |
print(Sys.time()-strt) | |
################################################### | |
# Run with doMPI | |
cl <- startMPIcluster(procs) | |
registerDoMPI(cl) | |
strt<-Sys.time() | |
ls<-foreach(icount(iters)) %dopar% { | |
to.ls<-rnorm(1e6) | |
to.ls<-summary(to.ls) | |
to.ls | |
} | |
print("Parallel MPI") | |
print(Sys.time()-strt) | |
closeCluster(cl) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment