سؤال

Does anybody know what is MATLAB using for performing BLAS1-type operations, e.g., dscal or daxpy?

>> a=ones(1,1e6,'double');
>> b=ones(1,1e6,'double');
>> a=2*a;  % dscal
>> a=2*a+1;
>> b=2*b+a; % daxpy

I have substituted MATLABs BLAS library using the BLAS_VERSION environment variable. I used a custom compiled (and modified) OpenBLAS, and inserted some printfs here and there to see if MATLAB is calling the library. I do get a printf for matrix-matrix multiplication, but I do not get anything for the simple BLAS1 operations. Which is a shame, because I really need this for performance reasons.

Which makes me wonder - does MATLAB re-implement this basic functionality? What would be a reason for doing so? And finally - where is it implemented and can I pre-load/substitute it?

هل كانت مفيدة؟

المحلول

After more investigation I am now certain that MATLAB does not use BLAS for all vector operations (it does use it for some operations - see Edit note below). You can verify this under Linux in the following way. Start MATLAB, then

>> feature getpid
ans =
   13608

From linux terminal check, what dynamic libraries are loaded by MATLAB, or to be precise, check if MKL has been loaded (I am testing on an Intel CPU):

$ cat /proc/13608/numa_maps | grep mkl

The above returns an empty output, hence mkl is not yet linked. Now, perform a simple operation on vectors:

>> a=zeros(1, 1e6, 'double');
>> a=2*a; % dscal

and check the libraries again:

$ cat /proc/13608/numa_maps | grep mkl

Again, the output is empty, so no MKL. You can check that it is the same for other BLAS1 operations. Now, do a BLAS3 operation:

>> A=zeros(100);
>> B=A*A';

and check the linked libraries for mkl

$ cat /proc/13608/numa_maps | grep mkl

7f4b687ec000 prefer:0 file=/home/matlab/R2013a/bin/glnxa64/mklcompat.so
7f4b6afb4000 prefer:0 file=/home/matlab/R2013a/bin/glnxa64/mkl.so
[...]

So yes, MATLAB does use BLAS libraries for BLAS3, and no, it does not use it for BLAS1. I have not found any way in which I can substitute MATLABs internal functions for operations on vectors. And I believe there is none. They seem to be implemented in one of the core MATLAB libraries (libmwmcr).

Edit It turns out that BLAS1 libraries are used for calculation of the dot product:

>> a=zeros(1, 1e6, 'double');
>> b=zeros(1, 1e6, 'double');
>> c=a*b';
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top