[R] parallel SNOW slower than single core?

2012-08-02 Thread Jie
Dear All,

I am learning parallel in R and start with the package snow. I did a test
about running time and the parallel version is much slower than the regulat
code. My laptop is X200s with dual core intel L9400 cpu.
Should I make more clusters than 2? Or how to improve the performance?

# install.packages(snow)
library(snow)
cl - makeCluster(2)
t1 - proc.time()
a - c()
for (i in 1:1000)
{
a[i] - sum(parSapply(cl, 1:15, get(+), 2))
}
proc.time()-t1
t2 - proc.time()
a - c()
for (i in 1:1000)
{
a[i] - sum(sapply(1:15, +, 2))
}
proc.time()-t2

[[alternative HTML version deleted]]

__
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.


Re: [R] parallel SNOW slower than single core?

2012-08-02 Thread R. Michael Weylandt
I'm not surprised -- you're doing a fairly trivial calculation so the
overhead of setting up the parallelization is likely more than the
benefit from halving the computation time. Do it on a larger
calculation and I imagine the performance will be better -- I might
just be pulling this out of thin air, but I think I remember reading
slides from Luke Tierney saying one had to be adding vectors of size
= 30k or so for parallelization to have a meaningful benefit.
Obviously sizes will be lower for operations more expensive than
addition.

Michael

On Thu, Aug 2, 2012 at 1:13 PM, Jie jimmycl...@gmail.com wrote:
 Dear All,

 I am learning parallel in R and start with the package snow. I did a test
 about running time and the parallel version is much slower than the regulat
 code. My laptop is X200s with dual core intel L9400 cpu.
 Should I make more clusters than 2? Or how to improve the performance?

 # install.packages(snow)
 library(snow)
 cl - makeCluster(2)
 t1 - proc.time()
 a - c()
 for (i in 1:1000)
 {
 a[i] - sum(parSapply(cl, 1:15, get(+), 2))
 }
 proc.time()-t1
 t2 - proc.time()
 a - c()
 for (i in 1:1000)
 {
 a[i] - sum(sapply(1:15, +, 2))
 }
 proc.time()-t2

 [[alternative HTML version deleted]]

 __
 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.

__
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.


Re: [R] parallel SNOW slower than single core?

2012-08-02 Thread Prof Brian Ripley

On 02/08/2012 19:13, Jie wrote:

Dear All,

I am learning parallel in R and start with the package snow. I did a test
about running time and the parallel version is much slower than the regulat
code. My laptop is X200s with dual core intel L9400 cpu.


The OS matters far more.  Overheads on Windows are much higher than on 
Linux for example.



Should I make more clusters than 2? Or how to improve the performance?


Not use such small tasks.  This is discussed in the 'parallel' vignette 
(and we do suggest you start with 'parallel' these days).



# install.packages(snow)
library(snow)
cl - makeCluster(2)
t1 - proc.time()
a - c()
for (i in 1:1000)
{
a[i] - sum(parSapply(cl, 1:15, get(+), 2))
}
proc.time()-t1
t2 - proc.time()


See ?system.time


a - c()
for (i in 1:1000)
{
a[i] - sum(sapply(1:15, +, 2))
}
proc.time()-t2




--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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.