0

I have an Rcpp routine that is given an R function and then does various computations. When run as such it works just fine. Now I want to run it in parallel, and then I get the error

Error in checkForRemoteErrors(lapply(cl, recvResult)): 4 nodes produced errors; first error: NULL value passed as symbol address

A toy example is here. The routine is supposed to generate 10 observations from a normal distribution with the mean passed as an argument:

The Rcpp code:

#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector tst(Function f, double m) {
   NumericVector out=f(m);
   return out;
}

and running

f=function(m) {rnorm(10, m)}
tst(f, 5)

works fine. But trying

cl <- makeCluster(4)
z=clusterCall(cl, tst, f, 5)

results in the error.

In the real routine f could be any routine that generates data, even something not part of base R.

Wolfgang

Wolfgang Rolke
  • 795
  • 4
  • 16
  • 3
    the general advice is to wrap your Rcpp code in a package :https://stackoverflow.com/questions/6074310/using-rcpp-within-parallel-code-via-snow-to-make-a-cluster ; https://stackoverflow.com/questions/38518387/using-rcpp-functions-inside-of-rs-parapply-functions-from-the-parallel-package ; https://stackoverflow.com/questions/56225145/how-to-parallelise-c-code-when-using-rcpp – user20650 Apr 05 '22 at 18:49
  • 2
    And that advice has been give here a few dozen times. Alternative, you can call `sourceCpp()` or `cppFunction()` on each node. A function you build that is _local_ to the session, however a package can be loaded everwhere. – Dirk Eddelbuettel Apr 05 '22 at 18:52

1 Answers1

0

I had read many of the discussions on the subject before, and even created a package, but kept getting error messages. I have it running now, even though I am not sure what the problem was before.

Anyway, thanks for the replies!

Wolfgang Rolke
  • 795
  • 4
  • 16
  • Glad you have it working but that sounds too non-deterministic for computers :) I had this covered in some of the old 'HPC with R' tutorials so there are stanzas should you need it. – Dirk Eddelbuettel Apr 06 '22 at 19:12