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

Reply via email to