Computational Mathematics

Adventures in Computing, Statistics, and R

Installing Rmpi with OpenMPI on Mac OS X Lion


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/

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.


9 Responses

  1. Can’t understand why anyone would choose MacPorts over Homebrew (

    • Hmm.. Homebrew looks pretty awesome! I’ll have to check it out, thanks for the comment.

      • +1 Ryan, especially when there’s the open-mpi recipe in Homebrew as well.

        Installing it should be as simple as:
        brew install open-mpi

        • Well essentially homebrew and MacPorts do the same thing except homebrew seems to be faster and use less disk space as it uses existing libraries instead of compiling the latest ones from scratch. That being said, either should be just as easy to use if it weren’t for the bug in the current openmpi port on MacPorts.

  2. I’ve been struggling to install open mpi using the ports instructions, but Homebrew worked like a charm. Thanks guys!

  3. Hi Jon, thanks for posting this!

    I’m hitting a wall here with the developer version 0.6 of Rmpi. The mac compiled version seems to work, but 0.5-7 from the OSX section works fine (but it is too old for my current version of R: Error: package ‘Rmpi’ was built before R 2.10.0: please re-install it). When I update packages, I get 0.5-9 from CRAN, and library(Rmpi) fails to complete.

    Here is the error for installing 0.6:

    Bioinfomacs-Mac-Pro:ompl bioinfomac4$ R CMD INSTALL –configure-args=”–with-Rmpi-include=/opt/local/include/openmpi –with-Rmpi-libpath=/opt/local/lib –with-Rmpi-type=OPENMPI” /Users/bioinfomac4/Downloads/Rmpi_0.6-0.tar
    * installing to library ‘/Library/Frameworks/R.framework/Versions/2.13/Resources/library’
    * installing *source* package ‘Rmpi’ …
    checking for openpty in -lutil… no
    checking for main in -lpthread… no
    configure: creating ./config.status
    config.status: creating src/Makevars
    ** libs
    *** arch – x86_64

    [Omitted a bunch of text]

    Error in dyn.load(file, DLLpath = DLLpath, …) :
    unable to load shared object ‘/Library/Frameworks/R.framework/Versions/2.13/Resources/library/Rmpi/libs/x86_64/’:
    dlopen(/Library/Frameworks/R.framework/Versions/2.13/Resources/library/Rmpi/libs/x86_64/, 6): Symbol not found: _ompi_mpi_2int
    Referenced from: /Library/Frameworks/R.framework/Versions/2.13/Resources/library/Rmpi/libs/x86_64/
    Expected in: flat namespace
    in /Library/Frameworks/R.framework/Versions/2.13/Resources/library/Rmpi/libs/x86_64/
    Error: loading failed
    In addition: Warning message:
    .Last.lib failed in detach() for ‘Rmpi’, details:
    call: dyn.unload(file.path(libpath, “libs”, paste(“Rmpi”, .Platform$dynlib.ext,
    error: shared object ‘/Library/Frameworks/R.framework/Versions/2.13/Resources/library/Rmpi/libs/’ was not loaded
    Execution halted
    ERROR: loading failed
    * removing ‘/Library/Frameworks/R.framework/Versions/2.13/Resources/library/Rmpi’
    * restoring previous ‘/Library/Frameworks/R.framework/Versions/2.13/Resources/library/Rmpi’

    • @Nate – I ran into this problem and I used R64 CMD INSTALL and it worked.

    • I have got the same problem. I have followed all the instructions, everything worked fine until I ran the R (or R64) CMD INSTALL command.

      Here is the error message

      Error in dyn.load(file, DLLpath = DLLpath, …) :
      unable to load shared object ‘/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rmpi/libs/x86_64/’:
      dlopen(/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rmpi/libs/x86_64/, 6): Symbol not found: _ompi_mpi_2int
      Referenced from: /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rmpi/libs/x86_64/
      Expected in: flat namespace
      in /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rmpi/libs/x86_64/
      Error: loading failed
      Execution halted
      ERROR: loading failed
      * removing /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rmpi
      * restoring previous /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rmpi

      And of course, if I tried to load the library in R I get:

      Error in get(“.First.lib”, envir = env, inherits = FALSE) :
      internal error -3 in R_decompress1
      Erreur : le chargement du package / espace de noms a chou pour Rmpi

      Any solution?

      • Hi Franck,

        I ran into a similar problem installing some other software. Can you try running ldd on to see what libraries are linking to it?


Leave a Reply