Why is MATLAB so fast in matrix multiplication?

前端 未结 12 1114
無奈伤痛
無奈伤痛 2020-11-22 00:29

I am making some benchmarks with CUDA, C++, C#, Java, and using MATLAB for verification and matrix generation. When I perform matrix multiplication with MATLAB, 2048x

12条回答
  •  长情又很酷
    2020-11-22 01:07

    The answer is LAPACK and BLAS libraries make MATLAB blindingly fast at matrix operations, not any proprietary code by the folks at MATLAB.

    Use the LAPACK and/or BLAS libraries in your C++ code for matrix operations and you should get similar performance as MATLAB. These libraries should be freely available on any modern system and parts were developed over decades in academia. Note that there are multiple implementations, including some closed source such as Intel MKL.

    A discussion of how BLAS gets high performance is available here.


    BTW, it's a serious pain in my experience to call LAPACK libraries directly from c (but worth it). You need to read the documentation VERY precisely.

提交回复
热议问题