From 9ad1ebe4d4fad9bb42d30dac506e0dec1f56dc74 Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Mon, 7 Sep 2015 17:33:56 +0200 Subject: [PATCH 1/2] Only warn in case of CHOLMOD major version mismatch The check introduced in #10362 is actually too strict, as ABI break only happen with mismatches in the major version. Warning on minor version differences means distributions cannot update SuiteSparse without rebuiling Julia (#12841). We also require at least libcholmod 2.1.1. Call dlsym_e instead of dlsym, which raises an error instead of returning C_NULL. Also fix the incorrect wording introuced in 25eb444: this message corresponds to the case where the version is different, not necessarily older. --- base/sparse/cholmod.jl | 71 ++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/base/sparse/cholmod.jl b/base/sparse/cholmod.jl index 818f3500726e1..3ba2e33df6863 100644 --- a/base/sparse/cholmod.jl +++ b/base/sparse/cholmod.jl @@ -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,()) @@ -55,7 +57,7 @@ end common() = commonStruct const version_array = Array(Cint, 3) -if Libdl.dlsym(Libdl.dlopen("libcholmod"), :cholmod_version) != C_NULL +if Libdl.dlsym_e(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) @@ -65,46 +67,47 @@ const version = VersionNumber(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 + if Libdl.dlsym_e(Libdl.dlopen("libcholmod"), :cholmod_version) != C_NULL + tmp = Array(Cint, 3) + ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array) + ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), tmp) + hasversion = true + else # CHOLMOD < 2.1.1 does not include cholmod_version() hasversion = false + end + + if !hasversion || VersionNumber(version_array...) < CHOLMOD_MIN_VERSION + warn(""" + + CHOLMOD version incompatibility + + Julia was compiled with CHOLMOD version $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 tmp[1] != 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 $version. It + is currently linked with version $(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 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,())) From 4c25109326e45a5db05ea2b27be0d1d3739b1b2a Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Wed, 9 Sep 2015 11:05:51 +0200 Subject: [PATCH 2/2] Simplify logic checking CHOLMOD version Use jl_cholmod_version only once to get the version used during the build, and do not modify this constant in __init__(). Rename variables to make them more explicit. Also only register gc tracked allocator if current version (and not build version) is recent enough. --- base/sparse/cholmod.jl | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/base/sparse/cholmod.jl b/base/sparse/cholmod.jl index 3ba2e33df6863..f2a956625750f 100644 --- a/base/sparse/cholmod.jl +++ b/base/sparse/cholmod.jl @@ -56,32 +56,28 @@ end common() = commonStruct -const version_array = Array(Cint, 3) -if Libdl.dlsym_e(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_e(Libdl.dlopen("libcholmod"), :cholmod_version) != C_NULL - tmp = Array(Cint, 3) - ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array) - ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), tmp) - hasversion = true + 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() - hasversion = false + current_version = v"0.0.0" end - if !hasversion || VersionNumber(version_array...) < CHOLMOD_MIN_VERSION + + if current_version < CHOLMOD_MIN_VERSION warn(""" CHOLMOD version incompatibility - Julia was compiled with CHOLMOD version $version. It is + 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, @@ -92,13 +88,13 @@ function __init__() from www.julialang.org, which ship with the correct versions of all dependencies. """) - elseif tmp[1] != version_array[1] + 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 version $(VersionNumber(tmp...)). + 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 \\. @@ -154,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) @@ -249,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