Skip to content

Commit 297b698

Browse files
committed
Check CHOLMOD version at runtime
1 parent 3b110e8 commit 297b698

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

base/sparse/cholmod.jl

+27-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ macro cholmod_name(nm,typ) string("cholmod_", eval(typ) == SuiteSparse_long ? "l
2727
for Ti in IndexTypes
2828
@eval begin
2929
function common(::Type{$Ti})
30-
a = fill(0xff, cholmod_com_sz)
30+
a = fill(0xff, common_size)
3131
@isok ccall((@cholmod_name "start" $Ti
3232
, :libcholmod), Cint, (Ptr{UInt8},), a)
3333
set_print_level(a, 0) # no printing from CHOLMOD by default
@@ -36,16 +36,41 @@ for Ti in IndexTypes
3636
end
3737
end
3838

39+
const version_array = Array(Cint, 3)
40+
if dlsym(dlopen("libcholmod"), :cholmod_version) != C_NULL
41+
ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array)
42+
else
43+
ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), version_array)
44+
end
45+
const version = VersionNumber(version_array...)
46+
3947
### These offsets are defined in SuiteSparse_wrapper.c
48+
const common_size = ccall((:jl_cholmod_common_size,:libsuitesparse_wrapper),Int,())
49+
4050
const cholmod_com_offsets = Array(Csize_t, 19)
4151
ccall((:jl_cholmod_common_offsets, :libsuitesparse_wrapper),
42-
Void, (Ptr{Csize_t},), cholmod_com_offsets)
52+
Void, (Ptr{Csize_t},), cholmod_com_offsets)
53+
4354
const common_supernodal = (1:4) + cholmod_com_offsets[4]
4455
const common_final_ll = (1:4) + cholmod_com_offsets[7]
4556
const common_print = (1:4) + cholmod_com_offsets[13]
4657
const common_itype = (1:4) + cholmod_com_offsets[18]
4758
const common_dtype = (1:4) + cholmod_com_offsets[19]
4859

60+
function __init__()
61+
println("Hej")
62+
if dlsym(dlopen("libcholmod"), :cholmod_version) == C_NULL
63+
throw(CHOLMODException("your version of CHOLMOD is old. It might not work correctly with Julia. Please upgrade to a more recent version."))
64+
else
65+
tmp = Array(Cint, 3)
66+
ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array)
67+
ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), tmp)
68+
if tmp != version_array
69+
throw(CHOLMODException("your version of CHOLMOD differs from the version used when Julia was built. These versions must match."))
70+
end
71+
end
72+
end
73+
4974
function set_print_level(cm::Array{UInt8}, lev::Integer)
5075
cm[common_print] = reinterpret(UInt8, [int32(lev)])
5176
end

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)