Installing Rmpi with OpenMPI on Mac OS X Lion

August 8, 2011
By

(This article was first published on Computational Mathematics » R, and kindly contributed to R-bloggers)

For whatever reason, Apple decided not to include OpenMPI in Mac OS X Lion (it was supported in Leopard and Snow Leopard). I found this out the hard way after doing a clean install of Lion.

Here are steps to install OpenMPI and get it working with the Rmpi package in R. One benefit of doing it this way is that you get the latest version of OpenMPI.

Step 1 – Install MacPorts
MacPorts is a great tool to compile and install many packages with ease, including OpenMPI. Install MacPorts by following the instructions on this page. Note that you will need to install Xcode off the App Store first.

Step 2 – Install OpenMPI on MacPorts
At the time of this posting, according to this ticket there is a problem compiling OpenMPI on Lion. To get around this, append the following block of code to: /opt/local/var/macports/sources/rsync.macports.org/release/ports/science/openmpi/Portfile

if {${configure.compiler} == "llvm-gcc-4.2"} {
configure.compiler clang
}

Update: This issue has been fixed.
then in Terminal, run:

sudo port install openmpi

Note that gcc44 and openmpi will take a while to build (several hours on my Macbook Air).

Step 3 – Compile and Install Rmpi
It’s best to compile the latest version from source. Download the .tar.gz file from the Rmpi site (at the time of this post, the latest version is 0.6-0 on the developer branch). Then in Terminal, install the package pointing to the proper OpenMPI directory paths with:

R CMD INSTALL --configure-args="--with-Rmpi-include=/opt/local/include/openmpi --with-Rmpi-libpath=/opt/local/lib --with-Rmpi-type=OPENMPI" Rmpi_0.6-0.tar.gz

You can try to load the library in R and run a few test lines to make sure everything is configured properly.

library(Rmpi)
mpi.spawn.Rslaves(nslaves=2)
mpi.remote.exec(runif(5))
mpi.close.Rslaves()

To leave a comment for the author, please follow the link and comment on his blog: Computational Mathematics » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.