Monday, April 12, 2010

Using MKL-Linked R in Eclipse

Setting up Eclipse to use MKL-Linked R

In my previous post, I showed how to compile R 2.10.1 using Intel's Math Kernel Library for the BLAS/LAPACK interface. Even though it takes a bit of time to setup, I think the noticeably improved calculation speed justifies the effort. Although I'm happy to use R from the command line for basic stuff, I prefer to develop my code in Eclipse and there is one configuration step needed for Eclipse to talk properly to MKL-linked R (assuming you followed the instructions in the last post).

If you haven't used Eclipse before, I would strongly recommend it as an Integrated Development Environment (IDE) for R. It's free, has a large user base, and is regularly updated. The editor is very flexible and allows for multiple tabs and easy arrangement of several windows. The StatET plugin links R with Eclipse through the rJava package, thereby allowing the user to browse objects in the R environment using the object browser. You can also get auto-completion suggestions for functions in the current environment by pressing Ctrl+Space. See Jeremy Anglim's post for some useful links about StatET and Eclipse. Before proceeding, if you haven't done so already, install the rJava package in R using install.packages("rJava").

Because I compiled R as a shared library linked against Intel's MKL, Eclipse struggles to locate libraries for MKL (and the shared R library). To fix this problem, one needs to set the LD_LIBRARY_PATH environment variable to include the MKL library directory, as well as the R shared library directory. By default, Java will not look for libraries in these directories, leading to errors such as this one (assuming you've enabled debugging as described on the StatET site:

java.lang.UnsatisfiedLinkError: /usr/local/lib64/R/library/rJava/jri/ cannot open shared object file: No such file or directory

java.lang.UnsatisfiedLinkError: /usr/local/lib64/R/library/rJava/jri/ cannot open shared object file: No such file or directory

Although some documentation suggested that I set the
java.library.path variable in the VM arguments in the JRE tab of the Eclipse run configuration, this is problematic because this setting only helps to load libraries directly requested by the application, not those libraries that reference other libraries (as is the case for MKL). Anyhow, the trick is to set the LD_LIBRARY_PATH environment variable in the Environment tab of the Eclipse run configuration, as seen here:

If you've installed things to the same place as me, in the Environment tab, you'll want to click "New" to add a new environment variable, call it LD_LIBRARY_PATH, and give it a value of /opt/intel/mkl/;/usr/local/lib64/R/lib.

The only other thing to be done is to verify that you've setup an R environment that points to the MKL-based installation. R environments are setup within the StatET preferences: Windows > Preferences > StatET > Run/Debug > R Environments. In my case, I installed R to /usr/local/lib64/R, so I specified that as the target and named the R installation R 2.10.1 x64 MKL. Then, under the R Config tab in your R run configuration (the same one as above), make sure you select the environment you just created. If you haven't setup StatET for Eclipse before, I would strongly encourage you to read Longhow Lam's guide, which provides more details (see especially the Configuring R section).

That's basically it! The major tweak is to tell Java where to find linked libraries using the LD_LIBRARY_PATH environment variable. Happy coding!


  1. Thanks Michael!
    I noticed on your screenshot above that you have Revo 32 and Revo 64 version 3.1 linked to your statET too. Any tips on getting rJava installed and loaded in Revo 64? I get error messages when I try to load this package, which then prevents statET from calling Revo. Any advice would be most appreciated,

  2. Michael,
    Thanks for the hint regarding linking the shared librari via LD_LIBRARY_PATH. For folks who run StatET remotely. To start rjserver, you need to modify ~/.RJServer/
    or ensure that import your system LD_LIBRARY_PATH variable


  3. I was wrong. I doesn't work. I can launch R console, but it crashes on MKL calls:

    > Sys.getenv("LD_LIBRARY_PATH")
    > crossprod(1:4)

    [INFO] Aug 25, 2010 2:54:24 PM - R stopped.

    *** *** failed with error : /opt/intel/mkl/ undefined symbol: mkl_dft_commit_descriptor_s_c2c_md_omp
    *** *** failed with error : /opt/intel/mkl/ undefined symbol: mkl_dft_commit_descriptor_s_c2c_md_omp
    MKL FATAL ERROR: Cannot load neither nor

    Any hints?

  4. Thanks for the idea that how to link the share library via library path.

    bioinformatics training india