Building an Optimized R with Intel’s MKL

This is a work in progress, general notes are below, I will clean up when I have some time.

First, download the R sourcecode tarball here.  Clock “download R,” select an appropriate mirror and download the .tar.gz file.

Set an environment variable containing the version number, for example

next, extract the tarball and switch your current directory to the R source tree

edit the config.site file with your favorite editor (vim of course!) and make the following changes

note that R_PAPERSIZE is just for us USA users that don’t have metric paper in our printers.  The “-O2” option turns on more aggressive optimizations, “-ftree-vectorize” tells the compiler to automatically use SSE vectorization where it can and “-march=native” tells the compiler to optimize for the CPU architecture on the current machine, this will enable the latest SSE instructions you have available.  Note that if you are planning to run this build on other machines you should specify the lowest common architecture instead.  For example, I use “-march=core2” when I plan to run across many machines because I don’t ever use anything older than that.

set an environment variable describing the root directory for your intel installation (usually in opt or your home directory but I use /usr/local/intel)

set a prefix for install location

set your LD_LIBRARY_PATH so that the system can find the shared libraries for your R install and for MKL.  Note that I will install into /usr/local/R-${version} but you can use whatever prefix you would like, or you are used to

configure

look for the following to be sure MKL was found correctly

build R

check shared libraries in libRblas

should see something like this

and check R executable too

should see something like this, “not found is bad”

setup your .bashrc environment so the new R will be found