I wrote a script to test a call to Intel MKL a external library but it doesn’t work.
The concept: Solve a linear system using MKL “dgetrs” (Documentation Library)
# Test MKL solve linear systems
N = 10;
A = rand(N,N);
AA = copy(A);
b = rand(N,1);
c = copy(b);
function juliaSol(A,b)
\(A,b);
end
sol = sol = juliaSol(A,b); #Solution of the linear system
# Test MKL
const global librt = Libdl.find_library(["libmkl_rt"], ["/opt/intel/mkl/lib"])
# Open librt
Libdl.dlopen(librt)
# 101 = LAPACK_ROW_MAJOR
# 102 = LAPACK_COL_MAJOR
function linSOLVE(A::StridedMatrix{Float64}, b::StridedMatrix{Float64})
m, n = size(A)
lda = max(1,stride(A, 2))
ipiv = similar(A, Int64, min(m,n))
#lapack_int LAPACKE_dgetrs (int matrix_layout , char trans , lapack_int n ,
# lapack_int nrhs , const double * a , lapack_int lda ,
# const lapack_int * ipiv , double * b , lapack_int ldb );
dd = ccall(("LAPACKE_dgetrs", librt),
Cint, # Return type
(Int64, Cuchar, Int64,
Int64, Ptr{Float64}, Int64,
Ptr{Int64}, Ptr{Float64}, Int64),
102, 'N', m,
1, A, lda,
ipiv, b, m
)
dd, b, ipiv # dd = 0 if calculation is done, b = output
end
dd, sol2, piv = linSOLVE(AA,c)
The script run with an error: Intel MKL ERROR: Parameter 6 was incorrect on entry to DLASWP
and the solution of the linear system is completely wrong.
An example of ccal of a BLAS can be seen here: https://github.com/JuliaLang/julia/blob/master/base/linalg/lapack.jl#L528
There is any expert (or developer) that can help me to use correctly the MKL ccall ?