Dear all,
In my 'simple' computer I was running some experiments to help me understand how faster a multicore lapply will be. I thought it might be interesting for some people to look at the results.
Even though are not accurate, still might be a good indicator how much improvement there can be.
A.Case. The classic: for 1:100
for (i in c(1:dimz)){
print(sprintf('Creating the %d map',i));
Shadowlist[,,i]<- GaussRF(x=x, y=y, model=model, grid=TRUE,param=c(mean,variance,nugget,scale,Whit.alpha))
}
user system elapsed
1825.699 303.100 1063.352
--------------------------------------------------------------------------
B.Case. Same as above but with lapply instead of for
Shadowlist<-lapply(1:dimz, function(i) {
print(sprintf('Creating the %d map',i));
GaussRF(x=x, y=y, model=model, grid=TRUE,param=c(mean,variance,nugget,scale,Whit.alpha))
}
) )
user system elapsed
1816.784 296.745 1062.142
-------------------------------------------
C.Case. Foreach is considered to be easier to be applied to manycores.
foreach (i=1:dimz) %do% {
print(sprintf('Creating the %d map',i));
Shadowlist[,,i]<-f <- GaussRF(x=x, y=y, model=model, grid=TRUE,param=c(mean,variance,nugget,scale,Whit.alpha))
}
user system elapsed
1027.058 13.243 1031.849
-----------------------------------
D. Case. The really multicore lapply. Great difference
system.time(Shadowlist<-mclapply(1:dimz, function(i) {
+ #print(sprintf('Creating the %d map',i));
+ GaussRF(x=x, y=y, model=model, grid=TRUE,param=c(mean,variance,nugget,scale,Whit.alpha))
+ }
+ )
+ )
user system elapsed
263.134 99.639 549.366
-----------------------------------
My computer is a normal four core pc.
Great improvement with mlcapply.
Comparing execution times
2 messages · Alaios, Steve Lianoglou
Just a comment about your use of foreach:
On Mon, Apr 11, 2011 at 6:29 AM, Alaios <alaios at yahoo.com> wrote:
[snip]
C.Case. Foreach is considered to be easier to be applied to manycores.
foreach (i=1:dimz) %do% {
? ?print(sprintf('Creating the %d map',i));
? ?Shadowlist[,,i]<-f <- GaussRF(x=x, y=y, model=model, grid=TRUE,param=c(mean,variance,nugget,scale,Whit.alpha))
}
You are still running this sequentially.
To run in parallel, you need load the appropriate parallel backend,
and use %dopar%:
library(doMC)
foreach(i=1:dimz) %dopar% { ... }
Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact