Thanks for Stephen and Roman.

Indeed, there are many options on windows. Just for the record, I put here
the computation times for the sinc problem with 1000x1000 grid.


          t_R_lapply t_parallel_mclapply t_parallel_parLapply
t_doSMP_foreachdo t_doSMP_foreachdopar t_snowfall_sfSapply
user.self     15.040              14.923                0.595
14.543                0.478               0.830
sys.self       0.053               0.034                0.228
0.035                0.043               0.404
elapsed       15.101              14.957                9.435
14.577               10.105               9.755

Basically, if the gain in time when using 2 cores vs 1 core is about 33%
from 15sec to 10sec, irrespective of the package used (parallel, doSMP or
snowfall).

Regards

Christophe

PS: my code below
_____________________________________________

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=1000)
g <- expand.grid(x=x, y=x)

fonx <- function(x, sinc) apply(x, 1, sinc)
foni <- function(i, sinc, glist) apply(glist[[i]], 1, sinc)

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

n <- 10

#sequential lapply

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


#parallel's lapply
library(parallel)

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



   cl <- parallel::makeCluster(2)
t_parallel_parLapply <- system.time( replicate(n, parallel::parLapply(cl,
glist, fonx, sinc=sinc)), gcFirst=TRUE) / n
   parallel::stopCluster(cl)



library(doSMP)
w <- startWorkers()

registerDoSMP(w)

#sequential foreach

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

#parallel foreach

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

#n=10 -> 0.2027
t_doSMP_foreachdopar <- t_doSMP_foreachdopar/n



#snowfall

library(snowfall)


sfInit(parallel = TRUE, cpus = 2, type = "SOCK")
t_snowfall_sfSapply <- system.time( replicate(n, snowfall::sfSapply(x =
1:2, fun = foni , sinc=sinc, glist=glist) ), gcFirst=TRUE) / n
sfStop()

cbind(t_R_lapply, t_parallel_mclapply, t_parallel_parLapply,
t_doSMP_foreachdo, t_doSMP_foreachdopar, t_snowfall_sfSapply)[1:3, ]





2011/12/5 Stephen Weston <stephen.b.weston@gmail.com>

> 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@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@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-hpc
>



-- 
Christophe DUTANG
Ph. D. student at ISFA, Lyon, France

	[[alternative HTML version deleted]]

