Skip to content

Commit

Permalink
Merge pull request JuliaLang#13000 from JuliaLang/nl/choldmod
Browse files Browse the repository at this point in the history
Improve CHOLMOD version mismatch detection
  • Loading branch information
nalimilan committed Sep 9, 2015
2 parents fc26785 + 4c25109 commit e9f4e20
Showing 1 changed file with 42 additions and 43 deletions.
85 changes: 42 additions & 43 deletions base/sparse/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ using Base.SparseMatrix: AbstractSparseMatrix, SparseMatrixCSC, increment, indty

include("cholmod_h.jl")

const CHOLMOD_MIN_VERSION = v"2.1.1"

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

Expand Down Expand Up @@ -54,57 +56,54 @@ end

common() = commonStruct

const version_array = Array(Cint, 3)
if Libdl.dlsym(Libdl.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 build_version_array = Array(Cint, 3)
ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), build_version_array)
const build_version = VersionNumber(build_version_array...)

function __init__()
try
### Check if the linked library is compatible with the Julia code
if Libdl.dlsym(Libdl.dlopen("libcholmod"), :cholmod_version) == C_NULL
hasversion = false
if Libdl.dlsym_e(Libdl.dlopen("libcholmod"), :cholmod_version) != C_NULL
current_version_array = Array(Cint, 3)
ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), current_version_array)
current_version = VersionNumber(current_version_array...)
else # CHOLMOD < 2.1.1 does not include cholmod_version()
current_version = v"0.0.0"
end


if current_version < CHOLMOD_MIN_VERSION
warn("""
CHOLMOD version incompatibility
Julia was compiled with CHOLMOD version $build_version. It is
currently linked with a version older than
$(CHOLMOD_MIN_VERSION). This might cause Julia to
terminate when working with sparse matrix factorizations,
e.g. solving systems of equations with \\.
It is recommended that you use Julia with a recent version
of CHOLMOD, or download the generic binaries
from www.julialang.org, which ship with the correct
versions of all dependencies.
""")
elseif build_version_array[1] != current_version_array[1]
warn("""
CHOLMOD version incompatibility
Julia was compiled with CHOLMOD version $version. It is
currently linked with a version older than 2.1.0. This
might cause Julia to terminate when working with sparse
matrix factorizations, e.g. solving systems of equations
with \\.
Julia was compiled with CHOLMOD version $build_version. It is
currently linked with version $current_version.
This might cause Julia to terminate when working with
sparse matrix factorizations, e.g. solving systems of
equations with \\.
It is recommended that you use Julia with a recent version
of CHOLMOD, or download the OS X or generic Linux binaries
from www.julialang.org, which ship with the correct
versions of all dependencies.
It is recommended that you use Julia with the same major
version of CHOLMOD as the one used during the build, or
download the generic binaries from www.julialang.org,
which ship with the correct versions of all dependencies.
""")
else
hasversion = true
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("""
CHOLMOD version incompatibility
Julia was compiled with CHOLMOD version $version. It
is currently linked with a version older than
$(VersionNumber(tmp...)). This might cause Julia to
terminate when working with sparse matrix
factorizations, e.g. solving systems of equations
with \\.
It is recommended that you use Julia with a recent
version of CHOLMOD, or download the OS X or generic
Linux binary from www.julialang.org, which ship with
the correct versions of all dependencies.
""")
end
end

intsize = Int(ccall((:jl_cholmod_sizeof_long,:libsuitesparse_wrapper),Csize_t,()))
Expand Down Expand Up @@ -151,7 +150,7 @@ function __init__()
set_print_level(commonStruct, 0) # no printing from CHOLMOD by default

# Register gc tracked allocator if CHOLMOD is new enough
if hasversion && version >= v"3.0.0"
if current_version >= v"3.0.0"
cnfg = cglobal((:SuiteSparse_config, :libsuitesparseconfig), Ptr{Void})
unsafe_store!(cnfg, cglobal(:jl_malloc, Ptr{Void}), 1)
unsafe_store!(cnfg, cglobal(:jl_calloc, Ptr{Void}), 2)
Expand Down Expand Up @@ -246,7 +245,7 @@ Sparse{Tv<:VTypes}(p::Ptr{C_Sparse{Tv}}) = Sparse{Tv}(p)

# Factor

if version >= v"2.1.0" # CHOLMOD version 2.1.0 or later
if build_version >= v"2.1.0" # CHOLMOD version 2.1.0 or later
immutable C_Factor{Tv<:VTypes}
n::Csize_t
minor::Csize_t
Expand Down

0 comments on commit e9f4e20

Please sign in to comment.