Installing Rmpi (MPI for R) on Mac and Windows

MPI is message passing interface for parallel computing I described in the previous post. MPI is usually written in C or Fortran. Fortunately, you don’t need to know these programing language to use MPI. In this post, I am going to show step-by-step how to install MPI to use in R.

Installing Rmpi on Mac

Rmpi is a package to run MPI in R. Assuming you have already installed R, this site tells you how to install Rmpi for Mac OS X. There are several steps for this.

1) Get X codes, Command line tools, and home brew. Homebrew can manually install non-apple programs. If your system doesn’t have these, you need to spend some time to install them. Make sure you see the message below before next step.

Your system is ready to brew.

If you are running OS X 10.6.8 or earlier, the system may not be compatible with most recent X code. In this case, I recommend to upgrade your system to Mavericks, which is free (right now at least). Then you can install X code followed by command line tool for Mavericks.

Screen Shot 2013-11-17 at 9.04.36 PM

Once command line tool is installed, install home brew the same way as described there (step 2 and 3).

2) install gfortran and open-mpi

This part is pretty simple. Open command line window, then type the command to install gfortran and openMPI.

>brew install gfortran
>brew install open-mpi

3) install rmpi package in R
First download rmpi. Then install it on R64 (use local package directory for installation).

> install.packages("Rmpi",type="source")
Installing package(s) into ‘/Library/Frameworks

If you have trouble compiling….. your compiler may be obsolete. When I installed Maverics on my old macbook, my compiler couldn’t compile from Rmpi source package. I needed to install macports for Mavericks, and then re-install open mpi.

If still doesn’t work, try earlier version of Rmpi  (e.g. 0.6-3) from here. Place the tgz file on your desktop, then in command line type “R”. Then type

>install.packages(file.choose(), repos = NULL, 
type = "source")

4) load rmpi in R


Installing Rmpi on Windows

Installation of Rmpi for Windows is once all requirements are met. It is necessary to install MPICH2 program to host parallel computing.

1) Install MPICH2 from here (select unofficial binary package for windows)
2) Change the PATH
3) Start hosting MPI
4) Download Rmpi and install on R
5) Start using Rmpi

What I am showing here is very similar to this website, but I am adding a little more information for each step.
If installation of MPICH2 is successful, you should see MPICH2 folder in the program files.


2) To change PATH for MPICH2, right click “my computer” then select “property”. Click “Advanced system setting” on the left. Click “Environmental Variable”, then highlight “PATH”, click edit. In the small window, you will add “;C:\Program Files\MPICH2\bin” at the end of character string which is already there. Hit OK.

environmental varialble change3) To start hosting, you need to run the following command in administrator, to do in Windows 7 or Vista, go to Run on the menu and type cmd, then press CTL + SHIFT + ENTER. You will see a little window like this.


Then type the following command.

>smpd -install
>mpiexec -remove

It will remove existing MPICH2 (if any) and install the program. -remove option will remove existing accounts and passwords.
Now, you are going to register an account with a password with -register option

>mpiexec -register

It will ask you to type account name and password.You need a valid user name and password for the windows. Otherwise it will fail.
Then using -validate option to test if this process is successful. You should see SUCCESS.

4) Download Rmpi package here.  Select the most recent version at the bottom. Then go to R, and install package from package archive (using the downloaded zip file). Click brows and select the file you downloaded.

install rmpi on R

5) Load Rmpi package. Now it is ready to run MPI.


Testing If Rmpi Is Running Successfully

Let’s see you set up Rmpi correctly. Try typing the following:

> mpi.spawn.Rslaves()

It may take a few moments before it returns, however if it takes too long there is something wrong with the installation process. For desktop/laptop computer, the number of slaves spawn is the number of threads you have in your machine.

In the next post, I will discuss more about how to use the MPI installed on R.

Disclaimer: Installation process described here was tested on several computers both windows and macs, however, I cannot guarantee that the processes described above works for all computers. I am not responsible for anything that happens to your computer, please backup all your data before you try.

About bioinfomagician

Bioinformatic Scientist @ UCLA

2 responses to “Installing Rmpi (MPI for R) on Mac and Windows”

  1. Briti says :

    Hello …Many Many thnx for the post .. I am trying to install “Rmpi” for the windows 8 system ..I did all the steps mentioned above, it installs the package also but when i try to use the library I get a strange error


    Error in get(hookname, envir = env, inherits = FALSE) :
    lazy-load database ‘P’ is corrupt
    In addition: Warning message:
    In get(hookname, envir = env, inherits = FALSE) :
    internal error -3 in R_decompress1
    Error: package or namespace load failed for ‘Rmpi’


    It would be great help if u can provide me some ides on this !!!!

    • bioinfomagician says :

      I have never installed on w8, so I don’t know the answer. Perhaps, you can try clean all variables and source and reinstall the package again. If you can find the package from somewhere else, I would give a shot too.Good luck.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: