<div dir="ltr"><div><div><div><div><div>Hello,<br></div>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:<br>
<br></div>### begin R ###<br>require(Rcpp)<br>cppFunction('<br>double s2nICm(NumericVector ICvec, int m, double In, double sampleSize) {<br> int n = ICvec.size();<br> double covSum = 0.0;<br> double s2n = 0.0;<br>
double ss = sampleSize*sampleSize; <br>
for(int i=0; i<=m-1; i++){<br> for(int k=0; k<=i+m; k++){<br> covSum += ICvec[i]*ICvec[k];<br> } <br> }<br> for(int i=m; i<=n-m-1; i++){<br> for(int k=i-m; k<=i+m; k++){<br> covSum += ICvec[i]*ICvec[k];<br>
}<br> }<br> for(int i=n-m; i<=n; i++){<br> for(int k=i-m; k<=n; k++){<br> covSum += ICvec[i]*ICvec[k];<br> }<br> }<br> s2n = (In/ss) * covSum;<br> return s2n;<br>}<br>')<br></div>### end R ###<br>
<br></div>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<br>
<br>mpi.bcast.Robj2slave(s2nICm)<br><br></div><div>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?<br>
</div><div>Thanks very much for your time,<br></div><div>Molly Davies<br></div><div>Biostatistics Graduate Student<br></div>UC Berkeley</div>