I have this reproducible R snippet
rm(list=ls())
library(doSNOW)
f <- function(a, b) a+b
g <- function(c) f(c*c, c+c)
v <- c(1, 2, 3, 4, 5, 6)
cl <- makeMPIcluster(1)
cat( clusterApply(cl, v, g) )
stopCluster(cl)
and I get the following error message:
Error in checkForRemoteErrors(val) :
6 nodes produced errors; first error: could not find function "f"
I am using R 2.14.1 under Ubuntu. MPI is installed and working.
I know that there is a similar issue for the foreach construct, but it allows to reference functions manually through the .export parameter. I could not find anything similar for clusterApply. Is there a workaround for this?
Thanks!
Your function wasn’t sent to the workers. Perhaps the best way to do this is to export the function directly: