Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software
- Software Development SDKs and Libraries
- Intel® oneAPI Math Kernel Library
- Use Intel MKL libraries with Matlab 2012b

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Jeena_J_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-19-2013
06:26 AM

186 Views

Use Intel MKL libraries with Matlab 2012b

Hi all,

I am working with a Matlab code and needs to handle large sparse systems. I have to take perform Mathematical operations like 'inverse', eigen value computation etc on these sparse systems. While using the inbuilt Matlab functions like 'inv()' and 'eig()', I ended up in getting memory issues and the program takes so much time to finish the analysis. This forces me to consider incorporating Intel MKL library functions to my code. I couldn't find a proper help to do so. I have seen certain procedures described for Matlab R2010a version http://software.intel.com/en-us/articles/using-intel-mkl-with-matlab

But I couldn't find any information for using MKL with Matlab R2012b. Can anyone help me with this regard ?

Link Copied

20 Replies

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-19-2013
07:21 AM

182 Views

Jeena_J_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-19-2013
08:28 AM

182 Views

Hi,

Thanks for the comments

The systems are atleat 5000 x 50000 matrices.... I donn't need the complete eigen vectors, but needs only few (between 6-15)....

While taking the eigen values , I have two matrices.. the first one is a full matrix and the second one is a sparse singular matrix.... both have a size more than 5000 x 5000 ... If I use the 'sparse' function in matlab, I have to use 'eigs' to compute the eigen vectors and mode shapes.... but 'eigs' function can't compute the eigen vectors when matrix is singular ..... and my second matrix may or may not be singular ....

Ying_H_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-19-2013
10:45 PM

182 Views

Hi Jeena,

As i understand, there are two questions,

1. choose suitable lapack functions to perform operation on the sparse matrix.

Not exaxt sure if you can call them in Matlab directly. Matlab should have blas and lapack function supported. So what you need to do is to choose suitable function. you may consult mathworks for the functions.

2. Regarding use MKL in Matlab.

The paper http://software.intel.com/en-us/articles/using-intel-mkl-with-matlab. mentioned, Matlab have employied MKL BLAS in itself. So you may check if it is ture by command

> > version - lapack

>> version - blas

(sorry, i haven't matlab so can't test).

If both show MKL verstion. then actually, matlab have used MKL blas and lapack.. You don't need to find a way to use MKL with matlab.

If you'd like try, then the mathworks article http://www.mathworks.com/help/matlab/matlab_external/calling-lapack-and-blas-functions-from-mex-file...

and the article http://software.intel.com/en-us/articles/intel-math-kernel-library-intel-mkl-for-windows-using-intel...

should be helpful. (but it may take time as you may run other configuration problems like the forum mentioned http://mdkey.org/?p=277 ) ,

So if your computation task is independent and have other compiler like Intel compiler + microsoft Visual C. you can write C code directly call MKL function. (save your matrix to a file, then read them to C file)

Best Regards,

Ying

Jeena_J_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-20-2013
10:14 AM

182 Views

Hi ,

Thanks for the comments.. I types the 'version' command and it displayed the version of Intel MKL being used in my Matlab version.

Now if I need to call a lapack function , say the function to create the inverse of a matrix - do I need to create a mex file / C# file to call the function ??

Thanks,

Jeena

SergeyKostrov

Valued Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-21-2013
07:00 AM

182 Views

TimP

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-21-2013
08:17 AM

182 Views

Jeena_J_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-21-2013
08:33 AM

182 Views

Hi,

Thanks for the comments...

I am working on Windows platform 32-bit OS with 2GB RAM.....and I am using the default data type in Matlab ( i didn't intentionaly change the data type) ... I can see each variable takes 8 bytes storage space ....

For large systems, if I use [C,D] = eig(A,B), it shows up 'out of memory by using eigs() ' ... even for a smaller problems, by looking through the performance profile of Matlab , I can see 'eigs()' take 99% of the total computation time ...

My main question here is how to use Intel MKL with Matlab ( as I may have even higher matrices and using 'eig()' within Matlab takes so much time for computation ) I have seen a procedure to link MKL with Matlab version R2010a...http://software.intel.com/en-us/articles/using-intel-mkl-with-matlab .... I wasn't sure if its the same procedure for linking MKL with Matlab R2012b , as I was getting some errors ...

Jeena_J_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-21-2013
09:09 AM

182 Views

@ TimP

I am not using 'inverse' anywhere in Matlab code, but I was just trying to explain the situtation why I needed to use Intel MKL routines...I just meant I might need to deal with large sparse as well as full matrices and thus using the inbuilt Matlab functions might make my program work slow and ends up in storage issues....

At some stage or other I need to use MKL library functions with Matlab and thus I was trying to call MKL library functions through my Matlab program ... http://software.intel.com/en-us/articles/using-intel-mkl-with-matlab .... This describes about making MKL use with Matlab start up...I was trying to follow the instructions described in this page... When I was trying to build the custom dll using 'nmake ia32' it started showing some syntax errors .... Not sure if I set wrong environment variables or something...I have typed the following in Intel MKL command prompt ...

*C:\Program Files\Intel\Composer XE 2013.149\mkl\bin\ia32\mklvars_ia32.bat *

*cd..*

*cd..*

*set MKLROOT="C:\Program Files\Intel\Composer XE 2013.149\mkl"*

*set INCLUDE="C:\Program Files\Intel\Composer XE 2013.149\mkl"\include*

*set LIB="C:\Program Files\Intel\Composer XE 2013.149\mkl"\lib\ia32*

*cd tools*

*cd builder*

*nmake ia32 *

I tried to follow whats explained in the above mentioned page , but after 'nmake ia32' the following error came

*makefile(92) : fatal error UI023 : syntax error in expression Stop*

http://software.intel.com/en-us/articles/intel-mkl-111-getting-started#Environment I could successfully complete the example described in this page for linking with a C code.... so I know MKL works in my computer ....

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-21-2013
09:36 AM

182 Views

Matlab already comes with MKL libraries integrated into it. The Intel article that you cited above is about replacing those libraries with a newer version of MKL, and probably does not apply to your installation. Secondly, you are not likely to see the performance of Matlab functions such as eig() improve dramatically as a result of upgrading to a more recent version of the Matlab MKL DLLs. In other words, given a calculation where 10 percent of the code consumes 90 percent of the CPU cycles, tinkering with the other 90 percent of the code and making it faster is not worthwhile unless you are a perfectionist.

In fact, I question why you must remain tied to using Matlab for a high-performance task where using a compiled language such as C or Fortran together with MKL might work out to be a better solution.

Jeena_J_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-21-2013
11:39 AM

182 Views

@ mecej4

Thanks for the clarifications .... If Matlab has lapack and blas libraries inbuilt to it, then can I call a lapack function without writing a mex file ? For example, if I need to solve a system of equations , can I directly use functions like 'DGESV' through Matlab scripts by properly giving the inputs for the function 'DGESV' .... or do I need to create the mex file to call the function always ?

So far I am creating a prototype model using Matlab scripts and test it for accuracy of results, computation speed and then on a later stage someone else will implement it in using C or Fortran (as I have a zero experience with C or Fortran )...

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-21-2013
01:00 PM

182 Views

You are complicating things far more than is reasonable by thinking of calling MKL routines through Matlab. Matlab gives you a well thought-out language and environment for performing mathematical work at a higher level than you can in C or Fortran. You express your algorithm in the Matlab language, and Matlab takes care of translating, as needed, your Matlab expressions to calls to MKL routines.

Given that you have no experience in C or Fortran, my advice is that for the time being you put aside any thoughts of using MKL from Matlab or writing .MEX files. The chances are quite high that .MEX files written without the necessary in-depth understanding would run more slowly than straightforward Matlab code, and therefore do little more than waste your time.

SergeyKostrov

Valued Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-21-2013
07:02 PM

182 Views

SergeyKostrov

Valued Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-21-2013
07:06 PM

182 Views

Jeena_J_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-22-2013
03:56 PM

182 Views

Thanks for the comments :)

I will incorporate all these modifications and see the memory requirements

SergeyKostrov

Valued Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-22-2013
04:09 PM

182 Views

Ying_H_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-23-2013
08:12 PM

182 Views

Hi Jeena,

No, you can't call lapack function direclty in matlab. As i learned, there are 3 ways to use MKL in matlab,

1. some of matlab function have called MKL function internally,

2. maybe some matlab plugin have provide such wrapper, you can call lapack funtion directly.

3. call lapack function and link mkl library yourself as the artice discrible on mathworks. ( in that paper, it use libmwlapack, you can change it into mkl libray)

So agree to Sergey and Mecej4.

As you mentioned MKL are in your matlab. the steps in the article was about using new version version instead of old mkl version. So if the mkl version is new enough, you don't need to do them again.

Second, (not 100% exact sure, but you can consult mathworks) the matlab fuction eigs() itself have accelerated by MKL lapack functions, (when mkl are already there), so there is less chance for you to call lapack function manually to improve the performance unless you have special matrix structure and use special lapack functions. on the other hand, if you have decide to call lapack, then the better solution is to call it directly in C , otherwise you will run into all kind of problems before you make all things ready。

third, your matrix is too big to 32bit platform, you may need 64bit platform and 64bt matlab.

Best Regards,

Ying

SergeyKostrov

Valued Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-23-2013
08:42 PM

182 Views

Ying_H_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-08-2013
06:44 PM

182 Views

Hi Jenna,

Any updates?

I guess, the 64bit matlab should be able to solve the out of memory problem.

As sergey mentioned, there are all kind of ways to use c function (mkl are c/fortran function in nature ) in Matlab (or call matlab in C).

There are much articles in mathwork regarding lapack in matlab. As i see, the eig() itself use lapack,

for example, http://www.mathworks.com/company/newsletters/articles/matlab-incorporates-lapack.html

There are now 16 different code paths underlying the eig function, depending on whether there are one or two arguments, whether the arguments are real or complex, whether the problem is symmetric and whether the eigenvectors are requested.

and here is another simple way to cal build-in lapack in matlab in *.m.

http://stackoverflow.com/questions/6438551/calling-matlabs-built-in-lapack-blas-routines

// dgesvd.m

X = rand(4,3);

[m,n] = size(X);

C = lapack('dgesvd', 'A', 'A', m, n, X, m, zeros(n,1), ...

zeros(m), m, zeros(n), n, zeros(5*m,1), 5*m, 0);

[s,U,VT] = C{[7,8,10]};

V = VT';

If you are working within Matlab, could you pleas try it and let us know how it works?

Best Regards,

Ying

RANGU_R_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-21-2014
04:22 AM

182 Views

hi,

Embedding Process

i am dividing high frequency coefficients into 3*3block ,if center coefficient f3(i,j) and i am finding average of minimum and maximum coefficients value..................condition 1 and 2 for inserting bit 0 and condition 3 and 4 for inserting bit 1. for retriving this condition is not working plz help me out.

if f3(i,j) >=avg(i,j) ...................1

f6(i,j)=f3(i,j);

end

if ((f3(i,j)<avg(i,j)) .....2

f6(i,j)=avg(i,j)+1;

end

if f3(i,j) <avg(i,j) ...................3

f6(i,j)=f3(i,j);

end

if ((f3(i,j)>=avg(i,j)) .....4

f6(i,j)=avg(i,j)+1;

end

for extraction

if f3(i,j) <avg(i,j) then extract bit 0

if f3(i,j) >=avg(i,j) then extract bit 1

thank u advance ........

Ying_H_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-23-2014
06:57 PM

57 Views

HI RANGU,

As i understand, your case is kind of comparison and assignment operation. You can implement them either in Matblab or in C. Is there any special reason for you to ask the question in mkl forum? do you want to implement them in C code, then call MKL function?

Best Regards,

Ying

Or if you'd like use some functions to do this, if your data type is 32floating number, you may use IPP function .

ippiThreshold_LTValGTVal_32f_C1R( pSrc, int srcStep, pDst, int dstStep, roiSize, thresholdLT, valueLT, thresholdGT, valueGT);

for example, if f3(i,j)<2, then f6(i,j)=1, if f3(i, j)>6, then f6(i, j)=7.

IppStatus threshold( void ) {

Ipp8u x[5*4];

IppiSize roi = {5,4};

int i;

for( i=0; i<5*4; ++i ) x* = (Ipp8u)i;*

// the x in the function as input and out. you can call _C1R which support x as input, y as output

return ippiThreshold_LTValGTVal_8u_C1IR( x, 5, roi, 2,1,6,7 );

}

The destination image x contains:

01 01 02 03 04

05 06 07 07 07

07 07 07 07 07

07 07 07 07 07

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

For more complete information about compiler optimizations, see our Optimization Notice.