[R-sig-hpc] Choosing Intel MKL BLAS when compiling R

Simon Urbanek simon.urbanek at r-project.org
Wed Nov 2 16:18:49 CET 2011


On Nov 2, 2011, at 10:57 AM, Michael Braun wrote:

> Interesting.  Incidentally, I mis-typed my link link below.  Usually I link to MKL using -lmkl_rt -liomp5 (without the -lpthread).  I'm still learning the vagaries of C++ and system libraries, but does this mean that I have been bypassing the Apple implementation?  If Intel's libiomp5 does not have this problem, would that explain why my code seems to be working?  Or is this an unrelated issue?
> 

I think you may be misunderstanding - what Dirk said is that MKL and OMP in R don't mix well and I said that we don't use OMP in R on OS X so it is irrelevant for OS X.

Cheers,
Simon




> 
> On Nov 2, 2011, at 8:39 AM, Simon Urbanek wrote:
> 
>> 
>> On Nov 1, 2011, at 11:19 PM, Michael Braun wrote:
>> 
>>> Simon:
>>> 
>>> Can you clarify your statement about OpenMP on OSX?  Is this an issue with OpenMP in general, or just R's use of it?  Or just Intel's use of it? 
>>> 
>> 
>> It seems to be an issue in Apple's posix threads implementation that OpenMP relies on - it seems that the cost of thread synchronization is several orders of magnitude higher than on Linux which mean you can't use it for "short" tasks. It's deep enough the I don't think we can do anything about it. Luke Tierney has a good test case that shows the problem, I'll see if I can forward it here.
>> 
>> Cheers,
>> Simon
>> 
>> 
>>> Michael
>>> 
>>> 
>>> On Nov 1, 2011, at 9:09 PM, Simon Urbanek wrote:
>>> 
>>>> 
>>>> On Nov 1, 2011, at 8:23 PM, Michael Braun wrote:
>>>> 
>>>>> Jonathan:
>>>>> 
>>>>> Compiling R, and linking to Intel MKL, is quite simple, as long as you are using a recent version of MKL.  Intel has a MKL Link Advisor at
>>>>> 
>>>>> http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor/
>>>>> 
>>>>> Choose the linking model you want, and then use the --with-blas option on configure.  For example, on my Mac, to link dynamically with the parallel version (which can be controlled with environment variables), I use the following:
>>>>> 
>>>>> '--with-blas=-L$(MKLROOT)/lib -lmkl_rt -lpthread -liomp5'
>>>>> 
>>>>> I compiled R 2.14.0 this morning with this option, and it seems to work fine.  I'm not sure what Dirk was referencing about how MKL is no longer compatible with R.  If there is an issue, it would be good to know about it.  Perhaps he can point us to the page in the documentation where this is mentioned.
>>>>> 
>>>> 
>>>> The issue is not relevant on OS X because OpenMP performance on OS X for vector parallelization is very bad, so it is typically disabled.
>>>> 
>>>> One comment to the earlier discussion - it's not always as simple as replacing the BLAS back-end due to ABI difference in the different implementations. You'll notice, for example, when complex BLAS calls start crashing (because R can work around such issues at configure time but not if you switch BLAS). On Debian I'm usually compiling ATLAS by hand which yields the best performance so I don't run into that problem.
>>>> 
>>>> Cheers,
>>>> Simon
>>>> 
>>>> 
>>>> 
>>>>> I hope this helps.
>>>>> 
>>>>> Michael
>>>>> 
>>>>> 
>>>>> On Nov 1, 2011, at 7:59 PM, <r-sig-hpc-request at r-project.org> <r-sig-hpc-request at r-project.org> wrote:
>>>>>> 
>>>>>> 
>>>>>> Message: 1
>>>>>> Date: Tue, 1 Nov 2011 14:36:50 -0700
>>>>>> From: Jonathan Greenberg <jgrn at illinois.edu>
>>>>>> To: r-sig-hpc at r-project.org
>>>>>> Subject: [R-sig-hpc] Choosing Intel MKL BLAS when compiling R
>>>>>> Message-ID:
>>>>>>      <CABG0rfvnoswR+Hi7peaTAPczT_4j6FTV-H0rDLwqJOw05HrLuw at mail.gmail.com>
>>>>>> Content-Type: text/plain; charset=ISO-8859-1
>>>>>> 
>>>>>> r-sig-hpc'ers:
>>>>>> 
>>>>>> I am compiling R 2.14 from scratch on a cluster computer (I can't use
>>>>>> any package managers for the install, unfortunately), and they have
>>>>>> the Intel MKL libraries available for BLAS/LAPACK.  I have not
>>>>>> successfully gotten a configure/make/make install combo yet that uses
>>>>>> multiple CPUs to do, say:
>>>>>> 
>>>>>> a = matrix(rnorm(5000*5000), 5000, 5000)
>>>>>> b = matrix(rnorm(5000*5000), 5000, 5000)
>>>>>> # This following line, minimally, should be getting distributed.
>>>>>> c = a%*%b
>>>>>> 
>>>>>> First off, I've tried compiling it with the configure flags:
>>>>>> ./configure --prefix=/myprefix/ --enable-BLAS-shlib
>>>>>> 
>>>>>> How do I then select the Intel MKL libraries to be used as the BLAS?
>>>>>> They are located in /usr/local/intel-11.1/mkl/lib/em64t
>>>>>> 
>>>>>> Thanks!
>>>>>> 
>>>>>> --j
>>>>>> 
>>>>>> 
>>>>>> --
>>>>>> Jonathan A. Greenberg, PhD
>>>>>> Assistant Professor
>>>>>> Department of Geography
>>>>>> University of Illinois at Urbana-Champaign
>>>>>> 607 South Mathews Avenue, MC 150
>>>>>> Urbana, IL 61801
>>>>>> Phone: 415-763-5476
>>>>>> AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
>>>>>> http://www.geog.illinois.edu/people/JonathanGreenberg.html
>>>>>> 
>>>>>> 
>>>>> 
>>>>> -------------------------------------------
>>>>> Michael Braun
>>>>> Associate Professor of Management Science (Marketing Group)
>>>>> MIT Sloan School of Management
>>>>> 100 Main St.., E62-535
>>>>> Cambridge, MA 02139
>>>>> braunm at mit.edu
>>>>> 617-253-3436
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> _______________________________________________
>>>>> R-sig-hpc mailing list
>>>>> R-sig-hpc at r-project.org
>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-hpc
>>>> 
>>> 
>>> -------------------------------------------
>>> Michael Braun
>>> Associate Professor of Management Science (Marketing Group)
>>> MIT Sloan School of Management
>>> 100 Main St.., E62-535
>>> Cambridge, MA 02139
>>> braunm at mit.edu
>>> 617-253-3436
>>> 
>>> 
>>> 
>>> 
>> 
> 
> Michael Braun 
> MIT Sloan School of Management
> braunm at mit.edu
> -------------------------------------------------- 
> View my research at
> http://braunm.scripts.mit.edu/
> 



More information about the R-sig-hpc mailing list