0

I've a function fA in R calling three times the same function fB like :

fA <- function(x){
 r1 <- fB(param1)
 r2 <- fB(param2)
 r3 <- fB(param3)
 return(c(r1,r2,r3))
}

the parameter of fBs function are computed in fA function. But to go faster how can I launch every fB function in background and wait for the results ( so the thre fB function are executed in parallel )

Thanks

Nicolas Rosewick
  • 1,938
  • 4
  • 24
  • 42

1 Answers1

1

Not too long ago, the parallel package was added to the R core. Have a look at functions like mclapply and parLapply for functions that mimic the behavior of lapply but execute in parallel. mclapply uses process forking, and parLapply uses clusters (e.g. a SOCK cluster). I would study the documentation of the parallel package to see what your specific situation requires.

Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149