[R] For->lapply->parallel apply
Alaios
alaios at yahoo.com
Sat Apr 9 11:03:14 CEST 2011
Dear all,
I would like to ask your help understand the subsequent steps for making my program faster.
The following code:
Gauslist<-array(data=NA,dim=c(dimx,dimy,dimz))
for (i in c(1:dimz)){
print(sprintf('Creating the %d map',i));
Gauslist[,,i]<-f <- GaussRF(x=x, y=y, model=model, grid=TRUE,param=c(mean,variance,nugget,scale,Whit.alpha))
}
creates 100 GaussMaps (each map is of 256*256 dim) and stores them in a matrix called Gauslist.
This process takes too long, so I was thinking if you can help me understand what should I do to make it run in parallel (in work there is a system with 16 cores).
There is mclapply (parralel version of lapply) . If I make run my code run with lapply then I will be able to run it with mclapply also (they have same syntax).
If I understand it correct the sequence for doing that is to understand the following:
for..loop->lapply->mcapply
Can you please help me understand if my for loop can be converted to lapply or not?
Regards
Alex
More information about the R-help
mailing list