Installing Rmpi with OpenMPI on Mac OS X Lion

[This article was first published on Computational Mathematics » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 their blog: Computational Mathematics » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)