I am trying to run code on several cores (I tried both the snow and parallel packages). I have
cl <- makeCluster(2)
y <- 1:10
sapply(1:5, function(x) x + y) # Works
parSapply(cl, 1:5, function(x) x + y)
The last line returns the error:
Error in checkForRemoteErrors(val) :
2 nodes produced errors; first error: object 'y' not found
Clearly parSapply isn’t finding y in the global environment. Any ways to get around this? Thanks.
The nodes don’t know about the
yin the global environment on the master. You need to tell them somehow.