[Rcpp-devel] Cannot access parameters in C++ code in parallel code called from Snow
Henric Zazzi
hzazzi at kth.se
Thu Jun 19 22:35:35 CEST 2014
I am developing a parallel R code using the Snow package, but when
calling C++ code using the Rcpp package the program just hangs and is
unresponsive.
as an example... I have the following code in R that is using snow to
split into certain number of processes
| MyRFunction<-function(i) {
n=i
.Call("CppFunction",n,PACKAGE="MyPackage")
}
if (mpi) {
cl<-getMPIcluster()
clusterExport(cl, list("set.user.Random.seed"))
clusterEvalQ(cl, {library(Rcpp); NULL})
out<-clusterApply(cl,1:mc.cores,MyRFunction)
stopCluster(cl)
}
else
out<- parallel::mclapply(1:mc.cores,MyRFunction)|
Whereas my C++ function looks like...
| RcppExport SEXP CppFunction(SEXP n) {
int n=as<int>(n);
}|
If I run it with mpi=false and mc.cores=[some number of threads] the
program runs beautifully BUT if i run it with mpi=true, therefore using
snow, the program just hangs at int=as<int>(n) ????? On the other hand
if I define the C++ function as...
| RcppExport SEXP CppFunction(SEXP n) {
CharacterVector nn(n);
int n=boost::lexical_cast<int>(nn[0]);
}|
The program runs perfectly on each mpi thread?? The problem is that it
works for integers doubles etc, but not matrices Also, I must use
lexical_cast from the boost package to make it works since as<> does not.
Does anybody know why this is, and what I am missing here, so I can load
my matrices as well?
Cheers
Henric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140619/3138492e/attachment-0001.html>
More information about the Rcpp-devel
mailing list