Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Difference between C++ code with Blas/Lapack and Matlab

Tianyi__Darren__L_
681 Views

Hi All!

I am trying to implement one Linear programming algorithm in C++. For the matrix multiplication, I use Blas and Lapack. However, I find C++ code performs worse than Matlab as the size of problem is large. Indeed, the difference becomes significant as the size increases. 

I am wondering if it is caused by the optimization tricks of matlab use to call Intel MKL. Could some one help explain why Matlab sometimes outperform C++ with Blas/Lapack?  Is there any way to improve this version of C++ code, or any option to optimize compiling?

Thank you for your time!

0 Kudos
5 Replies
TimP
Honored Contributor III
681 Views

Does Matlab make affinity settings?  Even if you run on a single CPU, those may improve cache locality, particularly as you prevent C++ from fusing loops as it might do if you wrote in-line code in place of level 1 BLAS calls.

0 Kudos
Tianyi__Darren__L_
681 Views

Hi, Tim. 

Thank you for your reply! 

Would you like to tell me what affinity settings in Matlab mean? I am not familiar with this. Furthermore, could you tell me how I modify my C++ code to improve the performance?

Thank you for your time!

 

0 Kudos
Tianyi__Darren__L_
681 Views

Could anyone help solve this problem? I am still confusing about which optimization tricks Matlab apply to Intel MKL. 

0 Kudos
Ying_H_Intel
Employee
681 Views

Hi Tianyi, 

Could you provide some details, like a test code and test result, compile option, test processor, matlab version, MKL version  to explain what the problem you are seeing?  otherwise, it is hard to say something. 

Regarding MKL and Matlab, you may have known that , Matlab matrix multiply should call MKL. You may check this by enter command in matlab command windows, 

version -blas

https://software.intel.com/en-us/articles/using-intel-math-kernel-library-with-mathworks-matlab-on-intel-xeon-phi-coprocessor-system

https://software.intel.com/en-us/articles/using-intel-mkl-with-matlab

Best Regards,

Ying

0 Kudos
Gennady_F_Intel
Moderator
681 Views

two my cents just for info -- Matlab R2015b uses MKL version 11.1. 

0 Kudos
Reply