# Wraping a MKL handle in julia

**URL:** <https://discourse.julialang.org/t/wraping-a-mkl-handle-in-julia/48241>\
**Category:** General Usage\
**Tags:** ccall, mkl\
**Created:** [October 12, 2020, 4:53pm UTC](https://discourse.julialang.org/t/wraping-a-mkl-handle-in-julia/48241 "2020-10-12T16:53:34Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![j\_tanu](https://avatars.discourse-cdn.com/v4/letter/j/b77776/32.png) [@j\_tanu](https://discourse.julialang.org/u/j_tanu)\
**Post date:** [October 16, 2020, 3:43am UTC](https://discourse.julialang.org/t/wraping-a-mkl-handle-in-julia/48241/4 "2020-10-16T03:43:05Z")

</div>

According to your prescription, I have created a pointer of type Cvoid but my call giving me an error of no method matching. I am attaching my sample code here

```julia
I = [1, 4, 4, 5]; J = [1, 1, 2, 3]; V = [2.0, 1.0, 4.0, 6.0];
b=sparse(I,J,V);
p=Ptr{Cvoid}
ccall(("mkl_sparse_d_create_csc", librt),Cint (Ptr{Cvoid},Ptr{UInt8},
Ref{Cint},Ref{Cint},Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Float64}),
p,"SPARSE_INDEX_BASE_ONE",b.m,b.n,
b.colptr,pointer(b.colptr,2),b.rowval,b.nzval)
MethodError: no method matching unsafe_convert(::Type{Ptr{Nothing}}, ::Type{Ptr{Nothing}})
Closest candidates are:
  unsafe_convert(::Type{Ptr{Nothing}}, ::Base.RefValue{T}) where T at refvalue.jl:30
  unsafe_convert(::Type{Ptr{Nothing}}, ::Base.RefArray{T,A,R} where R where A<:(AbstractArray{T,N} where N)) where T at refpointer.jl:90
  unsafe_convert(::Type{Ptr{Nothing}}, ::Base.CFunction) at c.jl:36

```

I also looked into the python wrapper [sparse\_dot\_mkl](https://github.com/flatironinstitute/sparse_dot/blob/release/sparse_dot_mkl/_mkl_interface.py). I have tried to implement their logic for creating the matrix handle for the MKL routine, `mkl_sparse_?_create_csc` gives me the error -“The input parameters contain an invalid value”. I am showing a part of my code.

```julia
mutable struct sparse_matrix_t
end
I = [1, 4, 4, 5]; J = [1, 1, 2, 3]; V = [2.0, 1.0, 4.0, 6.0];
b=sparse(I,J,V);
d=sparse_matrix_t();
p=pointer_from_objref(d)
ccall(("mkl_sparse_d_create_csc", librt),Cint (Ptr{Cvoid},Ptr{UInt8},
Ref{Cint},Ref{Cint},Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Float64}),
p,"SPARSE_INDEX_BASE_ONE",b.m,b.n,
b.colptr,pointer(b.colptr,2),b.rowval,b.nzval);

```

the value of the pointer p does not change during the operation.

---

_[View the full topic](https://discourse.julialang.org/t/wraping-a-mkl-handle-in-julia/48241)._
