[R-sig-hpc] multicores, benchmark and windows

Christophe Dutang dutangc at gmail.com
Sun Dec 4 22:22:25 CET 2011


Dear list,

I'm trying to find the easiest way to use the multiple cores of my core i7 running windows 7 pro 64bit. 

With the new R 2.14.0 version, we have the parallel package. Unfortunately mclapply function is not available with multiple cores on windows according to the documentation "It relies on forking and hence is not available on Windows unless mc.cores = 1.".

An option on windows seems to be doSMP. Before testing on windows, I did a small test on my macbook (only 2 cores) between parallel and doSMP.

With the code below, I observe both packages have similar computation times. So doSMP seems to be a good alternative.

Does anyone know other packages supporting multicore on windows?

Thanks in advance

Christophe

--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr

______________________________________________________________________

options(cores = 2)
getOption('cores')

#true parallel example
sinc <- function(x)
{
	r <- sqrt(x[1]^2+x[2]^2)
	10*sin(r)/r
}

x <- seq(-10, 10, length.out=100)
g <- expand.grid(x=x, y=x)

glist <- split(g, g[,'y'] > 0)

n <- 10

#sequential lapply

#n=10 -> 0.2795
system.time( replicate(n, lapply(glist, apply, 1, sinc) ), gcFirst=TRUE) / n


#parallel's lapply
library(parallel)

#n=10 -> 0.2158
system.time( replicate(n, mclapply(glist, apply, 1, sinc) ), gcFirst=TRUE) / n


library(doSMP)
w <- startWorkers()

registerDoSMP(w)

#sequential foreach

#n=10 -> 0.2883
system.time( replicate(n, foreach(i = 1:2) %do% apply(glist[[i]], 1, sinc) ), gcFirst=TRUE)[3] / n

#parallel foreach

#n=10 -> doesn't work!!
system.time( replicate(n, foreach(i = 1:2) %dopar% apply(glist[[i]], 1, FUN= sinc) ), gcFirst=TRUE)[3] / n


t1 <- c(0, 0, 0, 0, 0)
for(j in 1:10)
	t1 <- t1 + system.time(foreach(i = 1:2) %dopar% apply(glist[[i]], 1, FUN= sinc) )

#n=10 -> 0.2027
t1/n



More information about the R-sig-hpc mailing list