[R] Parallel code runs slower!

Mike Marchywka marchywka at hotmail.com
Wed Nov 10 15:30:23 CET 2010










----------------------------------------
> From: santosh.srinivas at gmail.com
> To: r-help at r-project.org
> Date: Wed, 10 Nov 2010 19:37:29 +0530
[[elided Hotmail spam]]
>
> My parallel code is running slower than my non-parallel code! Can someone
> pls advise what am I doing wrong here?

I cited an IEEE blurb here that has nothing to do with R
but you get the idea,

http://lists.boost.org/boost-users/2008/11/42263.php

I don't know enough R or for that matter openMP to
comment on details but often the cores just compete with
rather than help each other. You may be doing nothing "wrong"
other than hopping on the wrong bandwagon. There is nothing
wrong with dividing tasks, but you need to do it in 
a way that avoid contention for the rate limiting resources. 

In gross cases such as you suggest, look at task manager
as you may simply be pushing some of these threads into 
VM and that is basically the end of the world.


>
> t and tTA are simple matrices of equal dimensions.
>
> #NON PARALLEL CODE
>
> nCols=ncol(t)
> nRows=nrow(t)
> tTA = matrix(nrow=nRows,ncol=nCols)
>
> require(TTR)
> system.time(
> for (i in 1:nCols) {
> x = t[,i]
> xROC = ROC(x)
> tTA[,i]=xROC
>
> }
> )
>
> user system elapsed
> 123.24 0.07 123.47
>
>
> # PARALLEL CODE
>
> nCols=ncol(t)
> nRows=nrow(t)
> tTA = matrix(nrow=nRows,ncol=nCols)
>
> require(doSMP)
> workers <- startWorkers(4) # My computer has 4 cores
> registerDoSMP(workers)
> system.time(
> foreach (i=1:nCols) %dopar%{
> x = t[,i]
> xROC = ROC(x)
> tTA[,i]=xROC
>
> }
> )
>
> # stop workers
> stopWorkers(workers)
>
> It is taking ages!
>
> Thanks,
> S
>
> ______________________________________________
> R-help at 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.
 		 	   		  


More information about the R-help mailing list