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.
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 /R.framework/Versions/2.15/Resources/library’ ……………………
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.
3) 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
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.
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:
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.