On 15-Jun-10 17:07, Sergey Goriatchev wrote:
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?

Use doMPI and run R through mpirun (for example run on 8 cores):

mpirun -np 8 R --slave -f your-script.r

Hope it helps
                mario



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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

--
Ing. Mario Valle
Data Analysis and Visualization Group | http://www.cscs.ch/~mvalle
Swiss National Supercomputing Centre (CSCS)      | Tel:  +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax:  +41 (91) 610.82.82

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to