[Rcpp-devel] Help using rcpp and Rmpi

Molly Davies mollymdavies at gmail.com
Tue Jun 25 00:33:20 CEST 2013


Hello,
I have just written my first R extension using Rcpp, and it is SO much
faster than my best R efforts, thank you for such a wonderful package! I
used the following:

### begin R ###
require(Rcpp)
cppFunction('
double s2nICm(NumericVector ICvec, int m, double In, double sampleSize) {
  int n = ICvec.size();
  double covSum = 0.0;
  double s2n = 0.0;
  double ss = sampleSize*sampleSize;
  for(int i=0; i<=m-1; i++){
    for(int k=0; k<=i+m; k++){
      covSum += ICvec[i]*ICvec[k];
    }
  }
  for(int i=m; i<=n-m-1; i++){
    for(int k=i-m; k<=i+m; k++){
      covSum += ICvec[i]*ICvec[k];
    }
  }
  for(int i=n-m; i<=n; i++){
    for(int k=i-m; k<=n; k++){
      covSum += ICvec[i]*ICvec[k];
    }
  }
  s2n = (In/ss) * covSum;
  return s2n;
}
')
### end R ###

This works perfectly on my laptop (Macbook air). Now I need to use this
function as a part of a large simulation on my school's cluster (running
Sun Grid Engine) using Rmpi. I included the above function in a text file,
sourced that file in the master and sent the function above to my slaves
using

mpi.bcast.Robj2slave(s2nICm)

This doesn't work, but there are no error messages - just endless silence
from the slaves. (The original Rmpi simulation code that included the old,
slow R version of the function above worked without error). I'm pretty sure
I'm doing something wrong, but I'm not sure how to fix it. I'd really like
to understand how Rcpp and Rmpi interact. Is it OK to call
cppFunction('...') in the master and then send the resulting R function to
slaves using mpi.bcast.Robj2slave()? Or do I need to send a text version of
the cppFunction('...') to each slave and evaluate the text within each
slave? What's the proper way to use Rcpp within the context of Rmpi? Does
anyone know of any good resources out there that can help me understand
what's going on under the hood?
Thanks very much for your time,
Molly Davies
Biostatistics Graduate Student
UC Berkeley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130624/0cf6fccb/attachment.html>


More information about the Rcpp-devel mailing list