[Rcpp-devel] Struggling with cppFunction() and clusterExport()

Matteo Fasiolo matteo.fasiolo at gmail.com
Thu Sep 26 18:57:28 CEST 2013


Dear Rcpp developers,

 I'm trying to parallelize some of my algorithms but I have encountered
the following problem:

# I have a cppFunction
cppFunction(' double inner_Cpp(double a){ return 1;  } ')

# And an R wrapper around it
wrapper_R<- function(input)
{
  inner_Cpp(input)
}

# And I want to call the wrappen in parallel within algorithm
algo <- function(input)
{
  cl <- makeCluster(2)
  clusterExport(cl, "inner_Cpp")
  a <- clusterApply(cl, 1:2, wrapper_R)
  stopCluster(cl)

  a
}

algo(2)

Error in checkForRemoteErrors(val) :
  2 nodes produced errors; first error: NULL value passed as symbol address

It seems that I'm unable to find the address of inner_Cpp.
If the inner function is an R function there is no problem:

inner_R <- function(input) 1

wrapper_R<- function(input)
{
  inner_R(input)
}

algo <- function(input)
{
  cl <- makeCluster(2)
  clusterExport(cl, "inner_R")

  a <- clusterApply(cl, 1:2, wrapper_R)

  stopCluster(cl)

  a
}

algo(2)

[[1]]
[1] 1

[[2]]
[1] 1

Do you have any idea about why this is happening?
Given that I have just started parallelizing my algorithms in this
way, any suggestion/criticism about the overall approach is
more then welcome!

Matteo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130926/903b42ae/attachment.html>


More information about the Rcpp-devel mailing list