My parallel code is running slower than my non-parallel code! Can someone pls advise what am I doing wrong here? 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
Can you provide a little more information. What operating system are you using? Have you monitored the CPU and memory utilizations of the processes? Do you have enough physical memory; e.g., are you paging? How big are the matrices that you are processing; e.g., str(tTA) and object.size(tTA). This is the type of information that would be required to make an informed guess at what is happening. On Wed, Nov 10, 2010 at 9:07 AM, Santosh Srinivas <santosh.srinivas at gmail.com> wrote:> My parallel code is running slower than my non-parallel code! Can someone > pls advise what am I doing wrong here? > > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
----------------------------------------> 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.