Compiling R v3.1.0 with MKL Support on OS X v10.8.4

Inspired by Compiling R 3.0.1 with MKL support I compiled R v3.1.0 with MKL (Intel® Math Kernel Library) Support on OS X v10.8.4 and I was wondering if I could see any increase in performance without the need to use parallelism.

First of all you have to download and install MKL for OS X. Unfortunately there is no single package including only the library, instead you have to download either Intel® C++ Composer XE 2011 for Mac OS X or Intel® Fortran Composer XE 2011 for Mac OS X (see also “How can I download the Intel® IPP and Intel® MKL for Mac OS* X?“). Both are not freely available, but you can download and install the “Free 30-Day Evaluation Version”, as I did with Intel® C++ Composer XE 2011. Installation procedure works fine and I trusted the final screen of the installation process who told me, that the installation was successful done.

Then the big nightmare begann by trying to compile/build R from source….

Before you start, you have to install all this developer tools such as Xcode and Fortran.

My first attempt was to compile R v3.0.1. After a few tries I ended up with this configure parameters:

./configure --enable-R-shlib --enable-threads=posix --with-lapack --with-blas="-fopenmp -m64 -I$MKLROOT/include -L$MKLROOT/lib/intel64 -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lpthread -lm" r_arch=x86_64 SHELL="/bin/bash" CC="gcc -arch x86_64 -std=gnu99" CXX="g++ -arch x86_64" OBJC="gcc -arch x86_64" F77="gfortran -arch x86_64" FC="gfortran -arch x86_64" --with-system-zlib

Both variables MKLROOT and LD_LIBRARY_PATH must be defined before, e.g., with the following command:

source /opt/intel/mkl/bin/mklvars.sh intel64

“configure” went right, but then “make” ended up with errors, namely with:

** testing if installed package can be loaded
*** arch - R
ERROR: sub-architecture 'R' is not installed
*** arch - x86_64
ERROR: loading failed for ‘R’
* removing ‘/Users/phsz/Downloads/R-3.0.1/library/MASS’
make[2]: *** [MASS.ts] Error 1
make[1]: *** [recommended-packages] Error 2
make: *** [stamp-recommended] Error 2

After googling for a wile I found the hint to try with the R-devel from svn/trunk, i.e, with R v3.1.0. Here everything went right with “make”. Errors occurred on “make install”, nevertheless I found, that R was working if running with the “–arch” option, i.e., by executing

R --arch=x86_64

First, I did the R benchmark, which showed impressible results:

R 3.1.0 with MKL:

Total time for all 15 tests_________________________ (sec):  7.47700000000002
Overall mean (sum of I, II and III trimmed means/3)_ (sec):  0.443668541312943

R 3.0.1 without MKL:

Total time for all 15 tests_________________________ (sec):  34.8980000000001
Overall mean (sum of I, II and III trimmed means/3)_ (sec):  1.34762633295107

My unspoken hope was to be able to increase performance in functions like unidimTest(). But afterwards clearly it could not perform better, because of the chains and loops…

Have fun and be prepared for some more happenings during compiling!

BTW uninstalling MKL is easy:

sudo /opt/intel/composer_xe_2013.3.171/uninstall_ccompxe.sh

 

Leave a Reply

Your email address will not be published. Required fields are marked *