LinearAlgebra.inv matrix inversion slower than MATLAB?

Hmm, as a reference, this is my performance numbers on a Ryzen 3700X:

MATLAB R2021b
>> A = rand(4000); f = @() inv(A); timeit(f)
ans =

    0.5925
>> version -blas                   
ans =

    'Intel(R) Math Kernel Library Version 2019.0.3 Product Build 20190125 for Intel(R) 64 architecture applications, CNR branch auto'

Julia with OpenBLAS

julia> VERSION
v"1.7.0-rc1"
julia> using LinearAlgebra, BenchmarkTools
julia> A = rand(4000,4000);
julia> @btime inv($A);
  753.273 ms (6 allocations: 124.05 MiB)
julia> LinearAlgebra.versioninfo()
BLAS: libblastrampoline (f2c_capable)
 --> /home/trostaft/Documents/AcademicFiles/Software/julia-1.7.0-rc1/bin/../lib/julia/libopenblas64_.so (ILP64)

Julia with MKL

julia> VERSION
v"1.7.0-rc1"
julia> using LinearAlgebra, BenchmarkTools
julia> using MKL
julia> A = rand(4000,4000);
julia> @btime inv($A);
  688.735 ms (6 allocations: 124.05 MiB)
julia> LinearAlgebra.versioninfo()
BLAS: libblastrampoline (f2c_capable)
 --> /home/trostaft/.julia/artifacts/72d4adc3ef9236a92f4fefeb0291cb6e8aaae2d7/lib/libmkl_rt.so (ILP64)

So, despite the fact that I’m on an AMD CPU, MKL still results in a performance improvement for inv over OpenBLAS. Upping the size of the matrix, the performance gain from OpenBLAS and MKL is still around 13%.

I think MathWorks hasn’t updated the MKL version in MATLAB in order to keep using the hack to run optimized code paths on AMD CPU’s.

Yet, on the latest versions of MKL Intel has created a dedicated code path to AMD Ryzen.
Though not as optimized as using the Haswell / Skylake code path but still better than OpenBLAS.
The issue with latest MKL is the hack was disabled (Hence MATLAB uses old version).

2 Likes