Using MKL-Linked R in Eclipse

[This article was first published on Computing in Psychological Research, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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/libjri.so: libmkl_gf_lp64.so: cannot open shared object file: No such file or directory

java.lang.UnsatisfiedLinkError: /usr/local/lib64/R/library/rJava/jri/libjri.so: libR.so: 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/10.2.4.032/lib/em64t;/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!

To leave a comment for the author, please follow the link and comment on their blog: Computing in Psychological Research.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)