Skip to content
Prev 1495 / 2152 Next

Problems parallelizing glmnet

y<-rnorm(1000)
x<-matrix(rnorm(1000*10000),ncol=10000)
dimx<-dim(x)

library(doParallel)
library(foreach)
cl <- makeCluster(8, methods=FALSE)
registerDoParallel(cl)
print(system.time(
pval <- foreach (i =1:dimx[2], .combine=c) %dopar% {
mod <- lm(y ~ x[,i])
summary(mod)$coefficients[2,4]
}
))

  user  system elapsed 
 12.28    2.75  231.93 

stopCluster(cl)

library(parallel)
cl <- makeCluster(8, methods=FALSE)
print(system.time(
pval <- unlist(mclapply(1:dimx[2], function(i) summary(lm(y ~ x[,i]))$coefficients[2,4]))
))

  user  system elapsed 
 21.80    1.33   25.78 

stopCluster(cl)
On 09/06/2012 12:15 PM, Patrik Waldmann wrote:
A search of the list archives doesn't provide any backup that you have 
'showed' anything.

The only other post by you that I can see on the list shows the total 
elapsed time decreasing with the use of foreach, even though it was, 
indeed, a trivial function evaluation.