[R-sig-hpc] Using snow on a looping structure

Gang Chen gangchen6 at gmail.com
Tue Dec 2 20:38:15 CET 2008


I'm a newbie running parallel computing, so, sorry for this simple question.

My original code without parallel computing is like this:

runAna <- function(myData, Model, ...) {
      myStat <- wFun(myData, Model, ...)   # myStat: a vector with a
length of nStat
      return(myStat)
}

rStat <- array(0, dim=c(dimx, dimy, dimz, nStat))
for (i in 1:dimx)
for (j in 1:dimy)
for (k in 1:dimz)
     rStat[i, j, k,] <- runAna(rData[i, j, k,], Model, ...)   # each
analysis is on the 4th dimension, and returns nStat numbers which are
stored in the 4th dimension of rStat

I'm trying to run the above analysis using snow on a machine with two
processors, but could not figure out how to correctly set it up:

nNodes <- 2
library(snow)
cl <- makeCluster(nNodes, type = "SOCK")	

I thought I would use parApply, but how should I combine the looping
with parApply? Or no looping at all with something like parApply(cl,
rData, c(1,2,3), ...)?

Thanks in advance,
Gang



More information about the R-sig-hpc mailing list