简体   繁体   中英

Parallelize R code using snowfall package

I am trying to run my R code in parallel. Following is the toy example in which myfunc function returns a number.

library(snowfall); 
sfInit(parallel=TRUE,cpus=5)
a <- 1 : 10000
sfExport("a")
parwrapper <- function(i){
        mysimulation <- myfunc(b=30,c=a[i])
        return(mysimulation)}
sfapply(1:10000,parwrapper)

This is the error that I get. Error in checkForRemoteErrors(val): 5 nodes produced errors; first error: could not find function "myfunc"

Welcome to SO.

The error clearly states the problem. parwrapper calls a function myfunc . This function is not defined. In addition you might have to export the object sfExport('myfunc', 'parwrapper') .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM