Tuesday, January 17, 2012

Install Rmpi with MPICH2 environment

While installing Rmpi package on my Ubuntu system, I encountered the following problem:
******* some outputs ommitted here******
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/usr/local/lib/R/site-library/Rmpi/libs/Rmpi.so':
/usr/lib/libmpich.so.3: undefined symbol: MPL_trid
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 '/usr/local/lib/R/site-library/Rmpi/libs/Rmpi.so' was not loaded
******** some outputs ommitted here ******

After searching quite a lot by google, I found that this problem could be solved by setting mpicc compiler/linker instead of gcc (by default, R uses gcc on Linux system) to compile package sources while installing Rmpi. (A relevant discussion can be found here http://r.789695.n4.nabble.com/Re-R-CMD-INSTALL-configure-args-and-CC-customization-td3802485.html)

Here is the solution:
(1) Edit /etc/R/Makeconf (administrator priviledge required) or ~/.R/Makevars (if installing Rmpi as user specific package) by modifying/setting the following two entries:
CC=mpicc
SHLIB_LD=mpicc

(2) Run the following code (in R) to install Rmpi:
install.packages('Rmpi',configure.args="--with-Rmpi-type=MPICH2 --with-Rmpi-include=/usr/lib/mpich2/include --with-Rmpi-libpath=/usr/lib/mpich2/lib/ --with-mpi=/usr/include/mpich2/")
or install from shell:
R CMD INSTALL Rmpi_***.tar.gz --configure-args="--with-Rmpi-type=MPICH2 --with-Rmpi-include=/usr/lib/mpich2/include --with-Rmpi-libpath=/usr/lib/mpich2/lib/ --with-mpi=/usr/include/mpich2/"
Note: please make appropriate changes in the above code if MPICH2 installation path is different.

Update on 3 October 2013
Here is a simpler solution. Instead of modifying Makeconf, we can specify compiler options with configure.vars argument  (or --configure-vars in command line):
install.packages('Rmpi',configure.args="--with-Rmpi-type=MPICH2 --with-Rmpi-include=/usr/lib/mpich2/include --with-Rmpi-libpath=/usr/lib/mpich2/lib/ --with-mpi=/usr/include/mpich2/",configure.vars="CC=mpicc")