Let's look at how to call the existing MPI C code from R. What follows is an example that will help when you already have some C or C++ MPI code that you want to call from R. We will look at one simple way of doing this, but please note there are a number of ways this can be done. The definitive guide to calling code in C or other languages from R is the Writing R Extensions manual available from CRAN at http://cran.r-project.org/doc/manuals/r-release/R-exts.html.
If you are writing the MPI C code that you want to call from R from scratch, then you should consider using the Rcpp
R package (see http://cran.r-project.org/web/packages/Rcpp/index.html). This package provides C++ wrappers for R data types, thus allowing easy data transfer between C++ and R. It also manages memory for you, and provides other helper methods.