0

I have to find and work out some useful examples of parallel computing in R. What I've actually done, is installing the package and trying out some basic function using 2 or 4 cores of my CPU. I wasn't surprised that e.g. computing sqrt on 5-elements list will not be done faster using parallel, but I thought that things like sorting or just repeating the foreach loop 1000000 times will be the case when parallel can help... But this is what I get:

using 1 core (default)

    > c<-sample(1:1000000)
    > system.time(sort(c))
    user  system elapsed 
    0.21    0.00    0.20 

using doParallel package, 1 core (should be the same?!)

    > cl<-makeCluster(1)
    > registerDoParallel(cl)
    > system.time(clusterCall(cl, sort, c))
    user  system elapsed 
    0.01    0.06    0.39 

using 2 cores

    > cl<-makeCluster(2)
    > registerDoParallel(cl)
    > system.time(clusterCall(cl, sort, c))
    user  system elapsed 
    0.03    0.11    0.45 

Using 4 cores is even worse. What am I doing wrong? I've searched through internet and it says it should be better, especially because the default sort algorithm is quicksort, which take advantage of parallel computing. Any help?

katta
  • 87
  • 1
  • 7
  • 1
    See this [post on SO](http://stackoverflow.com/questions/14614306/why-is-the-parallel-package-slower-than-just-using-apply), [this post on the R help list](https://stat.ethz.ch/pipermail/r-help/2012-August/320431.html), and [this chapter](http://adv-r.had.co.nz/Profiling.html#parallelise) in Hadley's book – Richard Erickson May 06 '15 at 20:08
  • @RichardErickson, thanks for help! this book especially seems to be valuable for me, cause I am going to analyze some exercises. Although, there's still no answer to my question, is it? – katta May 07 '15 at 17:30

0 Answers0