{"id":54,"date":"2013-06-21T10:09:41","date_gmt":"2013-06-21T08:09:41","guid":{"rendered":"http:\/\/candrea.ch\/blog\/?p=54"},"modified":"2013-06-21T13:29:44","modified_gmt":"2013-06-21T11:29:44","slug":"compiling-r-with-mkl-support-on-os-x","status":"publish","type":"post","link":"https:\/\/candrea.ch\/blog\/compiling-r-with-mkl-support-on-os-x\/","title":{"rendered":"Compiling R v3.1.0 with MKL Support on OS X v10.8.4"},"content":{"rendered":"<p>Inspired by <a href=\"http:\/\/www.flaviobarros.net\/2013\/06\/19\/compiling-r-3-0-1-with-mkl-support\/\">Compiling R 3.0.1 with MKL support<\/a>\u00a0I compiled R v3.1.0 with MKL (<a href=\"http:\/\/software.intel.com\/en-us\/intel-mkl\">Intel\u00ae Math Kernel Library<\/a>) 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.<\/p>\n<p>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\u00a0<a href=\"http:\/\/software.intel.com\/en-us\/articles\/intel-composer-xe\/\">Intel\u00ae C++ Composer XE 2011 for Mac OS X<\/a> or\u00a0<a href=\"http:\/\/software.intel.com\/en-us\/articles\/intel-composer-xe\/\">Intel\u00ae Fortran Composer XE 2011 for Mac OS X<\/a>\u00a0(see also &#8220;<a href=\"http:\/\/software.intel.com\/en-us\/articles\/performance-tools-for-software-developers-how-can-i-download-the-intel-ipp-and-intel-mkl-for-mac-os-x\">How can I download the Intel\u00ae IPP and Intel\u00ae MKL for Mac OS* X?<\/a>&#8220;). Both are <strong>not<\/strong> freely available, but you can download and install the &#8220;Free 30-Day Evaluation Version&#8221;, as I did with Intel\u00ae 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.<\/p>\n<p>Then the big nightmare begann by trying to compile\/build R from source&#8230;.<\/p>\n<p>Before you start, you have to install all this developer <a href=\"http:\/\/r.research.att.com\/tools\/\">tools<\/a> such as Xcode and Fortran.<\/p>\n<p>My first attempt was to compile R v3.0.1. After a few tries I ended up with this configure parameters:<\/p>\n<pre class=\"toolbar:2 show-lang:2 striped:false marking:false ranges:false nums:false nums-toggle:false wrap:true wrap-toggle:false show-plain:3 lang:sh highlight:0 decode:true\">.\/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<\/pre>\n<p>Both variables\u00a0MKLROOT and LD_LIBRARY_PATH must be defined before, e.g., with the following command:<\/p>\n<pre class=\"toolbar:2 show-lang:2 striped:false marking:false ranges:false nums:false nums-toggle:false wrap:true wrap-toggle:false show-plain:3 lang:sh highlight:0 decode:true\">source \/opt\/intel\/mkl\/bin\/mklvars.sh intel64<\/pre>\n<p>&#8220;configure&#8221; went right, but then &#8220;make&#8221; ended up with errors, namely with:<\/p>\n<pre class=\"toolbar:2 show-lang:2 striped:false marking:false ranges:false nums:false nums-toggle:false wrap:true wrap-toggle:false show-plain:3 lang:sh highlight:0 decode:true\">** testing if installed package can be loaded\r\n*** arch - R\r\nERROR: sub-architecture 'R' is not installed\r\n*** arch - x86_64\r\nERROR: loading failed for \u2018R\u2019\r\n* removing \u2018\/Users\/phsz\/Downloads\/R-3.0.1\/library\/MASS\u2019\r\nmake[2]: *** [MASS.ts] Error 1\r\nmake[1]: *** [recommended-packages] Error 2\r\nmake: *** [stamp-recommended] Error 2<\/pre>\n<p>After googling for a wile I found the <a href=\"http:\/\/r.789695.n4.nabble.com\/R-CMD-config-for-R-gt-3-0-1-td4667399.html\">hint<\/a> to try with the R-devel from <a href=\"https:\/\/svn.r-project.org\/R\/trunk\/\">svn\/trunk<\/a>, i.e, with R v3.1.0. Here everything went right with &#8220;make&#8221;. Errors occurred on &#8220;make install&#8221;, nevertheless I found, that R was working if running with the &#8220;&#8211;arch&#8221; option, i.e., by executing<\/p>\n<pre class=\"toolbar:2 show-lang:2 striped:false marking:false ranges:false nums:false nums-toggle:false wrap:true wrap-toggle:false show-plain:3 lang:sh highlight:0 decode:true\">R --arch=x86_64<\/pre>\n<p>First, I did the <a href=\"http:\/\/r.research.att.com\/benchmarks\/R-benchmark-25.R\">R\u00a0benchmark<\/a>, which showed impressible results:<\/p>\n<p>R 3.1.0 with MKL:<\/p>\n<pre class=\"toolbar:2 show-lang:2 striped:false marking:false ranges:false nums:false nums-toggle:false wrap:true wrap-toggle:false show-plain:3 lang:sh highlight:0 decode:true\">Total time for all 15 tests_________________________ (sec):  7.47700000000002\r\nOverall mean (sum of I, II and III trimmed means\/3)_ (sec):  0.443668541312943<\/pre>\n<p>R 3.0.1 without MKL:<\/p>\n<pre class=\"toolbar:2 show-lang:2 striped:false marking:false ranges:false nums:false nums-toggle:false wrap:true wrap-toggle:false show-plain:3 lang:sh highlight:0 decode:true\">Total time for all 15 tests_________________________ (sec):  34.8980000000001\r\nOverall mean (sum of I, II and III trimmed means\/3)_ (sec):  1.34762633295107<\/pre>\n<p>My unspoken hope was to be able to increase performance in functions like <a title=\"Parallel computing unidimTest in IRT\" href=\"https:\/\/candrea.ch\/blog\/parallel-computing-unidimtest-in-irt\/\">unidimTest()<\/a>. But afterwards clearly it could not perform better, because of the chains and loops&#8230;<\/p>\n<p>Have fun and be prepared for some more happenings during compiling!<\/p>\n<p>BTW uninstalling MKL is easy:<\/p>\n<pre class=\"toolbar:2 show-lang:2 striped:false marking:false ranges:false nums:false nums-toggle:false wrap:true wrap-toggle:false show-plain:3 lang:sh highlight:0 decode:true \">sudo \/opt\/intel\/composer_xe_2013.3.171\/uninstall_ccompxe.sh<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Inspired by Compiling R 3.0.1 with MKL support\u00a0I compiled R v3.1.0 with MKL (Intel\u00ae 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 &hellip; <a href=\"https:\/\/candrea.ch\/blog\/compiling-r-with-mkl-support-on-os-x\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Compiling R v3.1.0 with MKL Support on OS X v10.8.4<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-54","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/posts\/54"}],"collection":[{"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":21,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":74,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions\/74"}],"wp:attachment":[{"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}