Hi Mollyy,
On 24 June 2013 at 14:53, Molly Davies wrote:
| Hello,
| This might belong in the R-devel category, but I am not a C / C++
| programmer, so I thought I'd start here. I have just written my first R
The convention is that package-specific question go to the package specific
forums. In this case, you should really subscribe to rcpp-devel and post there.
| extension using Rcpp, and it is SO much faster than my best R efforts,
| thank you for such a wonderful package!
On behalf of the team: You are very welcome.
| Instead of writing a separate text | file, 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)
|
| I've been trying to get this to work for about a week now, but no luck.
| (The original Rmpi simulation code that included the old, slow R version of
| the function above worked without error). Until recently, I've been
getting
| a steady stream of informative error messages that I've forwarded to our
| sys admin - problems with g++, etc. Now I'm not getting any error
messages,
| I'm just not getting any results. There may still be a problem with our
| cluster, but I'm wondering if perhaps I'm doing something wrong, too.
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?
In a nutshell, you need the Rcpp-using code on each node -- that means object
code and all the object code needs. But let's discuss on rcpp-devel.
Cheers, Dirk
| Thanks very much for your time,
| Molly Davies
| Biostatistics Graduate Student
| UC Berkeley
|
| [[alternative HTML version deleted]]
|
| ______________________________________________
| R-help at r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-help
| PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
| and provide commented, minimal, self-contained, reproducible code.
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com