[R] Parallel computing on Windows (foreach)
Sergey Goriatchev
sergeyg at gmail.com
Tue Jun 15 17:07:11 CEST 2010
Hello,
I am reading "Using The foreach Package" document and I have tried the
following:
---------------------------------------------------------------------
> sessionInfo()
R version 2.10.1 (2009-12-14)
i386-pc-mingw32
locale:
[1] LC_COLLATE=German_Switzerland.1252
LC_CTYPE=German_Switzerland.1252
LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C
LC_TIME=German_Switzerland.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] foreach_1.3.0 codetools_0.2-2 iterators_1.0.3
> x <- numeric(10000)
> system.time(for(i in 1:10000) x[i] <- sqrt(i))
user system elapsed
0.03 0.00 0.03
>
> system.time(system.time(x <- foreach(i=1:10000, .combine="c") %do% sqrt(i)))
user system elapsed
7.14 0.00 7.14
>
> system.time(system.time(x <- foreach(i=1:10000, .combine="c") %dopar% sqrt(i)))
user system elapsed
7.19 0.00 7.19
Warning message:
executing %dopar% sequentially: no parallel backend registered
------------------------------------------------------------------------
Not only is the sequential foreach much slower than the simple
for-loop (as least in this particular instance), but I am not quite
sure how to make foreach run parallel. Where would I get this parallel
backend? I looked at doMC and doRedis, but these do not run on
Windows, as far as I understand. And doSNOW is something to use when
you have a cluster, while I have a simple dual-core PC.
It is not really clear for how to make parallel computing work. Please, help.
Regards,
Sergey
More information about the R-help
mailing list