Skip to content

Commit 74de89d

Browse files
committed
Check CHOLMOD version at runtime
1 parent 5195cc8 commit 74de89d

File tree

2 files changed

+74
-19
lines changed

2 files changed

+74
-19
lines changed

base/sparse/cholmod.jl

+74-10
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,26 @@ using Base.SparseMatrix: AbstractSparseMatrix, SparseMatrixCSC, increment, indty
2121

2222
include("cholmod_h.jl")
2323

24+
### These offsets are defined in SuiteSparse_wrapper.c
25+
const common_size = ccall((:jl_cholmod_common_size,:libsuitesparse_wrapper),Int,())
26+
27+
const cholmod_com_offsets = Array(Csize_t, 19)
28+
ccall((:jl_cholmod_common_offsets, :libsuitesparse_wrapper),
29+
Void, (Ptr{Csize_t},), cholmod_com_offsets)
30+
31+
const common_supernodal = (1:4) + cholmod_com_offsets[4]
32+
const common_final_ll = (1:4) + cholmod_com_offsets[7]
33+
const common_print = (1:4) + cholmod_com_offsets[13]
34+
const common_itype = (1:4) + cholmod_com_offsets[18]
35+
const common_dtype = (1:4) + cholmod_com_offsets[19]
36+
2437
## macro to generate the name of the C function according to the integer type
2538
macro cholmod_name(nm,typ) string("cholmod_", eval(typ) == SuiteSparse_long ? "l_" : "", nm) end
2639

2740
for Ti in IndexTypes
2841
@eval begin
2942
function common(::Type{$Ti})
30-
a = fill(0xff, cholmod_com_sz)
43+
a = fill(0xff, common_size)
3144
@isok ccall((@cholmod_name "start" $Ti
3245
, :libcholmod), Cint, (Ptr{UInt8},), a)
3346
set_print_level(a, 0) # no printing from CHOLMOD by default
@@ -36,15 +49,66 @@ for Ti in IndexTypes
3649
end
3750
end
3851

39-
### These offsets are defined in SuiteSparse_wrapper.c
40-
const cholmod_com_offsets = Array(Csize_t, 19)
41-
ccall((:jl_cholmod_common_offsets, :libsuitesparse_wrapper),
42-
Void, (Ptr{Csize_t},), cholmod_com_offsets)
43-
const common_supernodal = (1:4) + cholmod_com_offsets[4]
44-
const common_final_ll = (1:4) + cholmod_com_offsets[7]
45-
const common_print = (1:4) + cholmod_com_offsets[13]
46-
const common_itype = (1:4) + cholmod_com_offsets[18]
47-
const common_dtype = (1:4) + cholmod_com_offsets[19]
52+
const version_array = Array(Cint, 3)
53+
if dlsym(dlopen("libcholmod"), :cholmod_version) != C_NULL
54+
ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array)
55+
else
56+
ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), version_array)
57+
end
58+
const version = VersionNumber(version_array...)
59+
60+
function __init__()
61+
if dlsym(dlopen("libcholmod"), :cholmod_version) == C_NULL
62+
warn("""
63+
64+
CHOLMOD version incompatibility
65+
66+
Julia was compiled with CHOLMOD version $version, but is currently linked with a
67+
version older than 2.1.0. This might cause Julia to terminate when working with
68+
sparse matrices for operations involving factorization of a matrix, e.g. solving
69+
systems of equations with \\.
70+
71+
It is recommended that you either upgrade the package that provides CHOLMOD or
72+
download the OS X or generic Linux binary from www.julialang.org, which is
73+
shipped with the correct versions of all dependencies.
74+
""")
75+
else
76+
tmp = Array(Cint, 3)
77+
ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array)
78+
ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), tmp)
79+
if tmp != version_array
80+
warn("""
81+
82+
CHOLMOD version incompatibility
83+
84+
Julia was compiled with CHOLMOD version $version, but is currently linked
85+
with version $(VersionNumber(tmp...)). This might cause Julia to terminate when working
86+
with sparse matrices for operations involving factorization of a matrix,
87+
e.g. solving systems of equations with \\.
88+
89+
It is recommended that you either upgrade the package that provides CHOLMOD
90+
or download the OS X or generic Linux binary from www.julialang.org, which
91+
is shipped with the correct versions of all dependencies.
92+
""")
93+
end
94+
end
95+
96+
intsize = Int(ccall((:jl_cholmod_sizeof_long,:libsuitesparse_wrapper),Csize_t,()))
97+
if intsize != 4length(IndexTypes)
98+
warn("""
99+
100+
CHOLMOD integer size incompatibility
101+
102+
Julia was compiled with a version of CHOLMOD that supported $(32length(IndexTypes)) bit integers,
103+
but is currently linked with version that supports $(8intsize) integers. This might
104+
cause Julia to terminate when working with sparse matrices for operations
105+
involving factorization of a matrix, e.g. solving systems of equations with \\.
106+
107+
This problem can be fixed by downloading the OS X or generic Linux binary from
108+
www.julialang.org, which are shipped with the correct versions of all dependencies.
109+
""")
110+
end
111+
end
48112

49113
function set_print_level(cm::Array{UInt8}, lev::Integer)
50114
cm[common_print] = reinterpret(UInt8, [Int32(lev)])

base/sparse/cholmod_h.jl

-9
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,3 @@ end
7575
macro isok(A)
7676
:($A == TRUE || throw(CHOLMODException("")))
7777
end
78-
79-
const version_array = Array(Cint, 3)
80-
if dlsym(dlopen("libcholmod"), :cholmod_version) != C_NULL
81-
ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array)
82-
else
83-
ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), version_array)
84-
end
85-
const version = VersionNumber(version_array...)
86-
const cholmod_com_sz = ccall((:jl_cholmod_common_size,:libsuitesparse_wrapper),Int,())

0 commit comments

Comments
 (0)