[Rcpp-devel] mpi and RInside

Dirk Eddelbuettel edd at debian.org
Mon Feb 15 22:40:26 CET 2010


Jianping,

Very cool. Thanks for posting this!

On 8 February 2010 at 17:13, Jianping Hua wrote:
| I'm quite new to R and I'd like to run some R program inside my C++
| code. So I installed Rcpp and RInside recently. Since many of my work
| involves mpi, so I'm wondering if RInside works with mpi. It looks mpi
| works, although with some glitch. So I think I might post my
| experiences here, for anyone who is interested, and possibly, further
| discussions and suggestions.
| 
| First, some background. I have a MacbookPro running Leopard. To make
| Rcpp and RInside work, I have installed it from source (Thanks Dirk
| for tipping me out!!!) The mpic++ is Mac's own g++-4.0.1. Here is an

[ For the record, and as Romain and I understand it now after more hints from
  Simon, dynamic loading from OS X requires building from source. Static
  linking is possible with the pre-built binaries. ]

| very simple example code which I modified from the example code 0 of
| RInside package:
| 
| ////////////Start of Example///////////////

[ snip ]

That worked.
 
| /////////////End of Example///////////////
| 
| The tricky part is I found I have to put mpi.h before Rinside.h and
| Rcpp.h, otherwise the compiler will report syntax error in mpi.h.
| 
| For the makefile, I just changed two lines related to CXX in the
| example makefile
| CXX      := mpic++
| CXXFLAGS := $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) -g -O2

That works. I did the following (using Open MPI on Linux)

a) define new variables

   # OpenMPI header and libraries
   MPICPPFLAGS :=	$(shell mpic++ -showme:compile)
   MPILIBS :=		$(shell mpic++ -showme:link)

b) use these variables

   CXXFLAGS := 		$(MPICPPFLAGS) $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
   LDLIBS := 		$(MPILIBS) $(RLDFLAGS) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)

[ snip ]
 
| Note that in the above example there is no data passing at all. In the
| following example I add data gathering and it also works:
| 
| ///////Start of example/////////////////

[ snip ]

This example seg faults for me on the 
   
     delete[] allvalues;

step. 

Maybe w have to make sure that node 0 is the one allocating and doing the
gathering?
 
| I hope this information is useful.

Very much so!  This brings RInside right back to the MPI part of my HPC
exercises :)

Would you permit us to include your example, with the altered Makefile, as
additional examples in the RInside tarball?

Thanks again for posting this!

Regards, Dirk

-- 
  Registration is open for the 2nd International conference R / Finance 2010
  See http://www.RinFinance.com for details, and see you in Chicago in April!


More information about the Rcpp-devel mailing list