-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #371 from Circuitscape/RA/pardiso_lib
Move Pardiso solver to lib
- Loading branch information
Showing
6 changed files
with
72 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name = "CircuitscapeMKLPardiso" | ||
uuid = "f276a096-2d87-4069-b10e-355a3501ee6e" | ||
authors = ["ranjanan <[email protected]>"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
Circuitscape = "2b7a1792-8151-5239-925d-e2b8fdfa3201" | ||
Pardiso = "46dd5b70-b6fb-5a00-ae2d-e8fea33afaf2" | ||
|
||
[compat] | ||
Circuitscape = "5.11" | ||
Pardiso = "0.5" | ||
julia = "1.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module CircuitscapeMKLPardiso | ||
|
||
using Pardiso | ||
import Circuitscape: Solver, _check_eltype, MKLPardisoSolver, construct_cholesky_factor, solve_linear_system | ||
|
||
mutable struct MKLPardisoFactorize | ||
A | ||
ps::Pardiso.MKLPardisoSolver | ||
verbose::Bool | ||
firsttime::Bool | ||
end | ||
MKLPardisoFactorize(;verbose=false) = MKLPardisoFactorize(nothing,Pardiso.MKLPardisoSolver(),verbose,true) | ||
function (p::MKLPardisoFactorize)(x,A,b,update_matrix=false;kwargs...) | ||
if p.firsttime | ||
Pardiso.set_phase!(p.ps, Pardiso.ANALYSIS_NUM_FACT) | ||
Pardiso.pardiso(p.ps, x, A, b) | ||
p.firsttime = false | ||
end | ||
|
||
if update_matrix | ||
Pardiso.set_phase!(p.ps, Pardiso.NUM_FACT) | ||
Pardiso.pardiso(p.ps, x, A, b) | ||
p.A = A | ||
end | ||
|
||
Pardiso.set_phase!(p.ps, Pardiso.SOLVE_ITERATIVE_REFINE) | ||
Pardiso.pardiso(p.ps, x, A, b) | ||
end | ||
|
||
function compute_mklpardiso(str, batch_size = 5) | ||
cfg = parse_config(str) | ||
T = cfg["precision"] in SINGLE ? Float32 : Float64 | ||
if T == Float32 | ||
cswarn("Pardiso supports only double precision. Changing precision to double.") | ||
T = Float64 | ||
end | ||
V = cfg["use_64bit_indexing"] in TRUELIST ? Int64 : Int32 | ||
cfg["solver"] = "mklpardiso" | ||
_compute(T, V, cfg) | ||
end | ||
|
||
|
||
_check_eltype(a, solver::MKLPardisoSolver) = a | ||
construct_cholesky_factor(matrix, ::MKLPardisoSolver, suppress_info::Bool) = | ||
MKLPardisoFactorize() | ||
|
||
function solve_linear_system(factor::MKLPardisoFactorize, matrix, rhs) | ||
lhs = similar(rhs) | ||
mat = sparse(10eps(eltype(matrix))*I,size(matrix)...) + matrix | ||
x = zeros(eltype(matrix), size(matrix, 1)) | ||
for i = 1:size(lhs, 2) | ||
factor(x, mat, rhs[:,i]) | ||
@assert (norm(mat*x .- rhs[:,i]) / norm(rhs[:,i])) < 1e-6 | ||
lhs[:,i] .= x | ||
end | ||
lhs | ||
end | ||
|
||
end # module CircuitscapeMKLPardiso |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters