[R] Parallel code runs slower!
Santosh Srinivas
santosh.srinivas at gmail.com
Wed Nov 10 15:07:29 CET 2010
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
More information about the R-help
mailing list