Skip to content

Commit 0760996

Browse files
authored
Merge pull request #116 from goulart-paul/panua_license_check
add panua license check
2 parents 81b40c2 + 00dc345 commit 0760996

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/Pardiso.jl

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export solve, solve!
5151
export get_matrix
5252
export schur_complement, pardisogetschur
5353
export fix_iparm!
54-
export mkl_is_available, panua_is_available
54+
export mkl_is_available, panua_is_available
55+
56+
VERSION >= v"1.11.0-DEV.469" && eval(Meta.parse("public panua_is_loaded, panua_is_licensed"))
5557

5658
struct PardisoException <: Exception
5759
info::String
@@ -112,9 +114,36 @@ const pardiso_chkvec = Ref{Ptr}()
112114
const pardiso_chkvec_z = Ref{Ptr}()
113115
const pardiso_get_schur_f = Ref{Ptr}()
114116
const PARDISO_LOADED = Ref(false)
117+
const PARDISO_LICENSED = Ref(false)
118+
119+
function panua_is_licensed()
120+
121+
if !PARDISO_LOADED[]
122+
return false
123+
elseif PARDISO_LICENSED[]
124+
return true
125+
end
126+
# Suppress unwanted output from pardisoinit, which prints license info to stdout
127+
redirect_stdout(devnull) do
128+
try
129+
ps = PardisoSolver(;loadchecks = false)
130+
pardisoinit(ps) # errors if unlicensed
131+
PARDISO_LICENSED[] = true
132+
return true
133+
catch e
134+
if isa(e, PardisoException)
135+
return false
136+
else
137+
rethrow(e)
138+
end
139+
end
140+
end
141+
end
115142

116-
panua_is_available() = PARDISO_LOADED[]
143+
panua_is_loaded() = PARDISO_LOADED[]
144+
panua_is_available() = panua_is_loaded() && panua_is_licensed()
117145

146+
118147
function __init__()
119148
global MKL_LOAD_FAILED
120149
if LOCAL_MKL_FOUND

src/panua_pardiso.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ mutable struct PardisoSolver <: AbstractPardisoSolver
1313
rowval::Vector{Int32}
1414
end
1515

16-
function PardisoSolver()
17-
if !panua_is_available()
18-
error("Panua pardiso library was not loaded")
16+
function PardisoSolver(; loadchecks::Bool = true)
17+
if loadchecks
18+
if !panua_is_loaded()
19+
error("Panua pardiso library was not loaded")
20+
elseif !panua_is_licensed()
21+
error("Panua pardiso library requires license")
22+
end
1923
end
2024

2125
pt = zeros(Int, 64)

0 commit comments

Comments
 (0)