Skip to content

Commit

Permalink
Check CHOLMOD version at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Feb 28, 2015
1 parent 3b110e8 commit a8ca62d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
29 changes: 27 additions & 2 deletions base/sparse/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ macro cholmod_name(nm,typ) string("cholmod_", eval(typ) == SuiteSparse_long ? "l
for Ti in IndexTypes
@eval begin
function common(::Type{$Ti})
a = fill(0xff, cholmod_com_sz)
a = fill(0xff, common_size)
@isok ccall((@cholmod_name "start" $Ti
, :libcholmod), Cint, (Ptr{UInt8},), a)
set_print_level(a, 0) # no printing from CHOLMOD by default
Expand All @@ -36,16 +36,41 @@ for Ti in IndexTypes
end
end

const version_array = Array(Cint, 3)
if dlsym(dlopen("libcholmod"), :cholmod_version) != C_NULL
ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array)
else
ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), version_array)
end
const version = VersionNumber(version_array...)

### These offsets are defined in SuiteSparse_wrapper.c
const common_size = ccall((:jl_cholmod_common_size,:libsuitesparse_wrapper),Int,())

const cholmod_com_offsets = Array(Csize_t, 19)
ccall((:jl_cholmod_common_offsets, :libsuitesparse_wrapper),
Void, (Ptr{Csize_t},), cholmod_com_offsets)
Void, (Ptr{Csize_t},), cholmod_com_offsets)

const common_supernodal = (1:4) + cholmod_com_offsets[4]
const common_final_ll = (1:4) + cholmod_com_offsets[7]
const common_print = (1:4) + cholmod_com_offsets[13]
const common_itype = (1:4) + cholmod_com_offsets[18]
const common_dtype = (1:4) + cholmod_com_offsets[19]

function __init__()
println("Hej")
if dlsym(dlopen("libcholmod"), :cholmod_version) == C_NULL
throw(CHOLMODException("your version of CHOLMOD is old. It might not work correctly with Julia. Please upgrade to a more recent version."))
else
tmp = Array(Cint, 3)
ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array)
ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), tmp)
if tmp != version_array
throw(CHOLMODException("your version of CHOLMOD differs from the version used when Julia was build. These versions must match."))
end
end
end

function set_print_level(cm::Array{UInt8}, lev::Integer)
cm[common_print] = reinterpret(UInt8, [int32(lev)])
end
Expand Down
9 changes: 0 additions & 9 deletions base/sparse/cholmod_h.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,3 @@ end
macro isok(A)
:($A == TRUE || throw(CHOLMODException("")))
end

const version_array = Array(Cint, 3)
if dlsym(dlopen("libcholmod"), :cholmod_version) != C_NULL
ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array)
else
ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), version_array)
end
const version = VersionNumber(version_array...)
const cholmod_com_sz = ccall((:jl_cholmod_common_size,:libsuitesparse_wrapper),Int,())

0 comments on commit a8ca62d

Please sign in to comment.