I made several wrappers to LAPACK, so I am basically familiar with the mechanism of calling Fortran based LAPACK programs from Julia. I would like to call now subroutines from another Fortran library (called SLICOT), which heavily relies on LAPACK and BLAS calls. I wonder if this is possible, relying on the already compiled LAPACK and BLAS codes used inside Julia. I would like to avoid compiling LAPACK and BLAS as separate libraries (which I guess would be possible).
I thank in advance for any hint on how to approach this problem. And sorry if such a question has been already answered.
You will need to build a library of the “slicot” package anyway. At least in linux, the inclusion of lapack or blas libraries in that process reduces to adding a flag to the compilation (-llapack and -lblas, if I remember well) because these libraries can be installed, already compiled, with standard package managers. With that in place, I do not think there is any more practical alternative than that.
Is there any specific scenario in which this does not seem a good alternative?
If you’d like to find the path for linking:
julia> using LinearAlgebra, Libdl
julia> filter(lib->occursin(BLAS.libblas, lib), Libdl.dllist())
julia> filter(lib->occursin(BLAS.liblapack, lib), Libdl.dllist())
Thanks for your reply.
In Julia, you need to call a library routine using
ccall, for example,
ccall((function_name, library), ...
is the name of my library, say SLICOT, and function_name
is the name of the routine. But, I wonder how the internal calls to LAPACK are resolved and where the information on the Julia library "libopenblas64_" (which contains the LAPACK library routines in the directoryjulia\bin` on my Windows computer) can be provided.
A minimal example here:
The Fortran code, which calls dsyev from Lapack:
double precision :: M(4,4), A(4)
! For dsyev
double precision :: work(12)
integer :: info
! Computing the eigenvalues 'A' and eigenvectors 'M' of the M matrix
end subroutine uselapack
Compile it with:
gfortran uselapack.f90 -llapack -shared -o uselapack.so
Then, in Julia:
julia> M = [ i == j ? Float64(i+j) : 0. for i in 1:4, j in 1:4 ]
2.0 0.0 0.0 0.0
0.0 4.0 0.0 0.0
0.0 0.0 6.0 0.0
0.0 0.0 0.0 8.0
julia> A = zeros(4)
1.0 -0.0 -0.0 0.0
0.0 1.0 -0.0 0.0
0.0 0.0 1.0 0.0
0.0 0.0 0.0 1.0
In the long run it would be nice to have a Yggdrasil build script for SLICOT, which could automatically build a
SLICOT_jll package with precompiled binaries for every Julia platform. Given this, it would be much easier to build Julia packages on top of SLICOT, maybe starting with a SLICOT.jl package to provide some higher-level interfaces.
Here is a simple example of a Yggdrasil build script for a Fortran program; you can look at build scripts for things like SCALAPACK or COSMA that link BLAS/LAPACK.
(There was an early Slicot.jl package from 6 years ago that started putting together SLICOT wrappers, but Julia has changed so much since 2014 that one would probably be better off mostly starting over.)
This is a very interesting information. Incidentaly, today, the NICONET association, who cares for SLICOT, decided to follow my proposal and make the last version of SLICOT, an open software under a MIT licence (similar to LAPACK) in GITHUB. Until now, only version 4.5 was in GITHUB under a GPL license.
I am also interested in exactly the same library (namly SLICOT). But i just started to play around with wrapping of c/fortran libraries in julia. Can you please provide an Link to the information NICONET wants tp make the last version of SLICOT an open software under a MIT licence? Thanks in advance. Thanks also for the information already posted here.
I am the 2nd chairman of NICONET, the organization who developed and maintains SLICOT. So, you have this information directly from me.
Wow fine. Thanks very much for the fast reply. And i appreciate this move. Thanks very much.