Skip to content

Commit 91791f2

Browse files
committed
introduce optional iparm etc parameters for pardiso constructors
1 parent 3e38305 commit 91791f2

File tree

3 files changed

+60
-22
lines changed

3 files changed

+60
-22
lines changed

src/factorizations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ LinearAlgebra.ldiv!(fact::AbstractFactorization, v)=ldiv!(fact.fact,v)
117117

118118
macro makefrommatrix(fact)
119119
return quote
120-
$(esc(fact))(A::ExtendableSparseMatrix{Tv,Ti}; kwargs...) where {Tv,Ti} = factorize!($(esc(fact))(;valuetype=Tv, indextype=Ti),A; kwargs...)
120+
$(esc(fact))(A::ExtendableSparseMatrix{Tv,Ti}; kwargs...) where {Tv,Ti} = factorize!($(esc(fact))(;valuetype=Tv, indextype=Ti, kwargs...),A)
121121
$(esc(fact))(A::SparseMatrixCSC{Tv,Ti}; kwargs...) where {Tv,Ti} = $(esc(fact))(ExtendableSparseMatrix(A); kwargs...)
122122
end
123123
end

src/pardiso_lu.jl

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,37 @@ mutable struct PardisoLU{Tv, Ti} <: AbstractPardisoLU{Tv,Ti}
66
phash::UInt64
77
end
88

9-
function PardisoLU{Tv,Ti}() where {Tv,Ti}
9+
function PardisoLU{Tv,Ti}(;iparm=nothing,dparm=nothing,matrixtype=nothing) where {Tv,Ti}
1010
fact=PardisoLU{Tv,Ti}(nothing,Pardiso.PardisoSolver(),0)
11-
set_default_matrixtype!(fact)
11+
default_initialize!(fact,iparm,dparm,matrixtype)
1212
end
1313

1414
"""
1515
```
16-
PardisoLU(;valuetype=Float64, indextype=Int64)
17-
PardisoLU(matrix)
16+
PardisoLU(;valuetype=Float64,
17+
indextype=Int64,
18+
iparm::Vector,
19+
dparm::Vector,
20+
matrixtype=Int)
21+
22+
PardisoLU(matrix; iparm,dparm,matrixtype)
1823
```
1924
2025
LU factorization based on pardiso. For using this, you need to issue `using Pardiso`
2126
and have the pardiso library from [pardiso-project.org](https://pardiso-project.org)
2227
[installed](https://github.com/JuliaSparse/Pardiso.jl#pardiso-60).
2328
24-
For (setting Pardiso internal parameters)[https://github.com/JuliaSparse/Pardiso.jl#readme],
25-
you can access the `PardisoSolver` e.g. like
29+
The optional keyword arguments `matrixtype`, `iparm` and `dparm` are
30+
(Pardiso internal parameters)[https://github.com/JuliaSparse/Pardiso.jl#readme].
31+
32+
Forsetting them, one can also access the `PardisoSolver` e.g. like
2633
```
2734
using Pardiso
2835
plu=PardisoLU()
2936
Pardiso.set_iparm!(plu.ps,5,13.0)
3037
```
3138
"""
32-
PardisoLU(;valuetype::Type=Float64, indextype::Type=Int64)=PardisoLU{valuetype,indextype}()
33-
39+
PardisoLU(;valuetype::Type=Float64, indextype::Type=Int64, kwargs...)=PardisoLU{valuetype,indextype}(;kwargs...)
3440

3541

3642
#############################################################################################
@@ -40,39 +46,60 @@ mutable struct MKLPardisoLU{Tv, Ti} <: AbstractPardisoLU{Tv,Ti}
4046
phash::UInt64
4147
end
4248

43-
function MKLPardisoLU{Tv,Ti}() where {Tv,Ti}
49+
function MKLPardisoLU{Tv,Ti}(;iparm=nothing,matrixtype=nothing) where {Tv,Ti}
4450
fact=MKLPardisoLU{Tv,Ti}(nothing,Pardiso.MKLPardisoSolver(),0)
45-
set_default_matrixtype!(fact)
51+
default_initialize!(fact, iparm,nothing,matrixtype)
4652
end
4753

4854

4955
"""
5056
```
51-
MKLPardisoLU(;valuetype=Float64, indextype=Int64)
52-
MKLPardisoLU(matrix)
57+
MKLPardisoLU(;valuetype=Float64,
58+
indextype=Int64,
59+
iparm::Vector,
60+
matrixtype=Int)
61+
62+
MKLPardisoLU(matrix; iparm, matrixtype)
5363
```
5464
5565
LU factorization based on pardiso. For using this, you need to issue `using Pardiso`.
5666
This version uses the early 2000's fork in Intel's MKL library.
5767
68+
The optional keyword arguments `matrixtype` and `iparm` are
69+
(Pardiso internal parameters)[https://github.com/JuliaSparse/Pardiso.jl#readme].
5870
59-
For (setting Pardiso internal parameters)[https://github.com/JuliaSparse/Pardiso.jl#readme],
60-
you can access the `PardisoSolver` e.g. like
71+
For setting them you can also access the `PardisoSolver` e.g. like
6172
```
6273
using Pardiso
6374
plu=MKLPardisoLU()
6475
Pardiso.set_iparm!(plu.ps,5,13.0)
6576
```
6677
"""
67-
MKLPardisoLU(;valuetype::Type=Float64, indextype::Type=Int64)=MKLPardisoLU{valuetype,indextype}()
78+
MKLPardisoLU(;valuetype::Type=Float64, indextype::Type=Int64,kwargs...)=MKLPardisoLU{valuetype,indextype}(;kwargs...)
6879

6980

7081
##########################################################################################
71-
function set_default_matrixtype!(fact::AbstractPardisoLU{Tv,Ti}) where {Tv, Ti}
72-
if Tv<:Complex
73-
Pardiso.set_matrixtype!(fact.ps,Pardiso.COMPLEX_NONSYM)
82+
function default_initialize!(fact::AbstractPardisoLU{Tv,Ti}, iparm,dparm,matrixtype) where {Tv, Ti}
83+
if !isnothing(matrixtype)
84+
my_matrixtype=matrixtype
85+
elseif Tv<:Complex
86+
my_matrixtype=Pardiso.COMPLEX_NONSYM
7487
else
75-
Pardiso.set_matrixtype!(fact.ps,Pardiso.REAL_NONSYM)
88+
my_matrixtype=Pardiso.REAL_NONSYM
89+
end
90+
91+
Pardiso.set_matrixtype!(fact.ps,Pardiso.REAL_NONSYM)
92+
93+
if !isnothing(iparm)
94+
for i=1:min(length(iparm),length(fact.ps.iparm))
95+
Pardiso.set_iparm!(fact.ps,i,iparm[i])
96+
end
97+
end
98+
99+
if !isnothing(dparm)
100+
for i=1:min(length(dparm),length(fact.ps.dparm))
101+
Pardiso.set_dparm!(fact.ps,i,dparm[i])
102+
end
76103
end
77104
fact
78105
end
@@ -82,7 +109,6 @@ function update!(lufact::AbstractPardisoLU{Tv,Ti}) where {Tv, Ti}
82109
flush!(lufact.A)
83110
Acsc=lufact.A.cscmatrix
84111
if lufact.phash!=lufact.A.phash
85-
Pardiso.pardisoinit(ps)
86112
Pardiso.set_phase!(ps, Pardiso.RELEASE_ALL)
87113
Pardiso.pardiso(ps, Tv[], Acsc, Tv[])
88114
Pardiso.set_phase!(ps, Pardiso.ANALYSIS_NUM_FACT)

test/runtests.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ end
362362
@test test_lu2(1000,1,1,lufac=CholeskyFactorization())
363363
end
364364

365-
@testset "pardiso" begin
365+
@testset "mkl-pardiso" begin
366366
@test test_lu1(10,10,10,lufac=MKLPardisoLU())
367367
@test test_lu1(25,40,1,lufac=MKLPardisoLU())
368368
@test test_lu1(1000,1,1,lufac=MKLPardisoLU())
@@ -373,3 +373,15 @@ end
373373
end
374374

375375

376+
if Pardiso.PARDISO_LOADED[]
377+
@testset "pardiso" begin
378+
@test test_lu1(10,10,10,lufac=PardisoLU())
379+
@test test_lu1(25,40,1,lufac=PardisoLU())
380+
@test test_lu1(1000,1,1,lufac=PardisoLU())
381+
382+
@test test_lu2(10,10,10,lufac=PardisoLU())
383+
@test test_lu2(25,40,1,lufac=PardisoLU())
384+
@test test_lu2(1000,1,1,lufac=PardisoLU())
385+
end
386+
end
387+

0 commit comments

Comments
 (0)