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 Mar 13, 2015
1 parent 5195cc8 commit cefdb2c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
42 changes: 40 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,54 @@ 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__()
if dlsym(dlopen("libcholmod"), :cholmod_version) == C_NULL
warn(
"Julia was compiled with CHOLMOD version $version, but is currently linked with a version older than 2.1.0. This might cause Julia to terminate when working with sparse matrices for operations involving factorization of a matrix, e.g. solving systems of equations with \\.
It is recommended that you either upgrade the package that provides CHOLMOD or download the OS X or generic Linux binary from www.julialang.org, which is shipped with the correct versions of all dependencies.")
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
warn(
"Julia was compiled with CHOLMOD version $version, but is currently linked with version $(VersionNumber(tmp...)). This might cause Julia to terminate when working with sparse matrices for operations involving factorization of a matrix, e.g. solving systems of equations with \\.
It is recommended that you either upgrade the package that provides CHOLMOD or download the OS X or generic Linux binary from www.julialang.org, which is shipped with the correct versions of all dependencies.")
end
end

intsize = Int(ccall((:jl_cholmod_sizeof_long,:libsuitesparse_wrapper),Csize_t,()))
if intsize != 4length(IndexTypes)
warn(
"Julia was compiled with a version of CHOLMOD that supported $(32length(IndexTypes)) bit integers, but is currently linked with version that supports $(8intsize) integers. This might cause Julia to terminate when working with sparse matrices for operations involving factorization of a matrix, e.g. solving systems of equations with \\.
This problem can be fixed by downloading the OS X or generic Linux binary from www.julialang.org, which are shipped with the correct versions of all dependencies.")
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 cefdb2c

Please sign in to comment.