[R] foreach performance
Dom Pazzula
dompazz at yahoo.com
Wed Jun 13 01:35:46 CEST 2012
I'm noticing a huge performance hit when using foreach with doSNOW. Any ideas on why the parallel loop runs ~8 times slower than the same foreach run sequentially?
> require(doSNOW)
Loading required package: doSNOW
Loading required package: foreach
foreach: simple, scalable parallel programming from Revolution Analytics
Use Revolution R for scalability, fault tolerance and more.
http://www.revolutionanalytics.com
Loading required package: iterators
Loading required package: snow
> cl = makeSOCKcluster(rep("localhost",3))
> registerDoSNOW(cl)
>
> system.time((
+ x = foreach(i=seq(1,5000)) %dopar% {
+ arima.sim(n = 250, list(ar=c(0.8897, -0.4858), ma=c(-0.2279, 0.2488)),
+ rand.gen = function(n, ...) sqrt(0.1796) * rt(n, df = 5))
+ }
+ ))
user system elapsed
4.46 0.22 50.27
>
> system.time((
+ y= foreach(i=seq(1,5000)) %do% {
+ arima.sim(n = 250, list(ar=c(0.8897, -0.4858), ma=c(-0.2279, 0.2488)),
+ rand.gen = function(n, ...) sqrt(0.1796) * rt(n, df = 5))
+ }
+ ))
user system elapsed
6.25 0.01 6.27
> system.time((
+ for (i in seq(1,5000)) {
+ x = arima.sim(n = 250, list(ar=c(0.8897, -0.4858), ma=c(-0.2279, 0.2488)),
+ rand.gen = function(n, ...) sqrt(0.1796) * rt(n, df = 5))
+ }
+ ))
user system elapsed
2.76 0.00 2.76
Dominic J. Pazzula
+-+-+-+-+-+-+-+-+-+-+-
dompazz at yahoo.com
More information about the R-help
mailing list