Community
cancel
Showing results for 
Search instead for 
Did you mean: 
141 Views

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

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
Black Belt
141 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.

141 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!

 

141 Views

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

Ying_H_Intel
Employee
141 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-i...

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

Best Regards,

Ying

Gennady_F_Intel
Moderator
141 Views

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

Reply