Wraping a MKL handle in julia

I did successfully change the value of the pointer by declaring an array of Ptr{Cvoid} and passing that

julia> using Base.Enums, MKL_jll, SparseArrays

julia> @enum sparse_index_base_t SPARSE_INDEX_BASE_ZERO=0 SPARSE_INDEX_BASE_ONE=1

julia> m = sparse(collect(1:10), [5, 2, 6, 3, 9, 1, 8, 5, 7, 10], ones(10))

julia> p = [Ptr{Cvoid}(0)]
1-element Array{Ptr{Nothing},1}:
 Ptr{Nothing} @0x0000000000000000

julia> ccall((:mkl_sparse_d_create_csc, libmkl_rt), Cint, (Ref{Ptr{Cvoid}}, sparse_index_base_t, Int64, Int64, Ptr{Int64}, Ptr{Int64}, Ptr{Int64}, Ptr{Cdouble}),
           p, SPARSE_INDEX_BASE_ONE, m.m, m.n, m.colptr, pointer(m.colptr, 2), m.rowval, m.nzval)
0

julia> p
1-element Array{Ptr{Nothing},1}:
 Ptr{Nothing} @0x000000000443f000

Creating an array of one element may be more complicated than necessary. There should be a way of using Ref and I still need to check that pointer points to a valid sparse_matrix for MKL.

1 Like