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
multicores, benchmark and windows
3 messages · Christophe Dutang, Stephen Weston
You can use functions such as parLapply, clusterApply and clusterApplyLB
from the parallel package on Windows. Basically all of the snow-derived
functions in parallel will work, and they do a fine job on multicore machines.
It's almost as simple as mclapply:
library(parallel)
cl <- makeCluster(3)
parLapply(cl, 1:3, sqrt)
stopCluster(cl)
And coming pre-installed with R 2.14.0 is a very nice feature.
- Steve
On Sun, Dec 4, 2011 at 4:22 PM, Christophe Dutang <dutangc at gmail.com> wrote:
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
_______________________________________________
R-sig-hpc mailing list
R-sig-hpc at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-hpc
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-hpc/attachments/20111205/dbba522a/attachment.pl>