Recently I implemented a julia wrapper for a subroutine of the SLICOT library (specifically SB03MD
to solve Lyapunov matrix equations). I used the generated binary wrappers in conjunction with Intel’s MKL, which is used also in MATLAB. I tested just the time required by the ccall
:
# SUBROUTINE SB03MD( DICO, JOB, FACT, TRANA,
# N, A, LDA, U, LDU, C, LDC,
# SCALE, SEP, FERR, WR, WI, IWORK, DWORK,
# LDWORK, INFO )
@time ccall((:sb03md_, libslicot), Cvoid, (Ref{UInt8}, Ref{UInt8}, Ref{UInt8}, Ref{UInt8},
Ref{BlasInt}, Ptr{Float64}, Ref{BlasInt}, Ptr{Float64}, Ref{BlasInt}, Ptr{Float64}, Ref{BlasInt},
Ptr{Float64}, Ptr{Float64}, Ptr{Float64}, Ptr{Float64}, Ptr{Float64},
Ptr{BlasInt}, Ptr{Float64}, Ref{BlasInt}, Ref{BlasInt}, Clong, Clong, Clong, Clong),
dico, job, fact, trana, n, A, lda, U, ldu, C, ldc,
scale, sep, ferr, wr, wi,
iwork, dwork, ldwork, info, 1, 1, 1, 1)
to eliminate the times required by all previous allocations.
For comparison, I used the function sllyap.m, a mex-file based implementation of the same function available in the SLICOT-BasicControl toolbox.
For a Lyapunov equation with randomly generated matrices, in MATLAB, I obtained:
>> n = 1000; a = rand(n,n); u = rand(n,n); c = rand(n,n); c = c'*c;
>> tic; x1 = sllyap(a',-c); toc
Elapsed time is 0.548520 seconds.
while for the Julia wrapper I got about 1.485512 seconds
(several times, trust me!). This is almost 3 times slower than the MATLAB interface!
I wonder, what is the cause of this difference. Any opinion is most welcome.
The MATLAB tests have been performed with MATLAB R2024b and the Julia tests with Julia Version 1.11.2, both on Windows.
Note: The MATLAB official function lyap is even faster, requiring 0.439914 seconds, but apparently another LAPACK-based Sylvester equation solver is employed (although it is claimed that SB03MD is used!)