Skip to content

Commit 0c0de1c

Browse files
committed
pardiso: format
1 parent 372ea1e commit 0c0de1c

File tree

3 files changed

+122
-109
lines changed

3 files changed

+122
-109
lines changed

ext/LinearSolvePardisoExt.jl

+5-6
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ function LinearSolve.init_cacheval(alg::PardisoJL,
2727

2828
if isnothing(vendor)
2929
if Pardiso.panua_is_available()
30-
vendor=:Panua
30+
vendor = :Panua
3131
else
32-
vendor=:MKL
32+
vendor = :MKL
3333
end
3434
end
3535

@@ -42,7 +42,7 @@ function LinearSolve.init_cacheval(alg::PardisoJL,
4242

4343
# for mkl 1 means conjugated and 2 means transposed.
4444
# https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2024-0/pardiso-iparm-parameter.html#IPARM37
45-
transposed_iparm = 2
45+
transposed_iparm = 2
4646

4747
solver
4848
else
@@ -53,15 +53,15 @@ function LinearSolve.init_cacheval(alg::PardisoJL,
5353
solver = Pardiso.PardisoSolver()
5454
Pardiso.pardisoinit(solver)
5555
solver_type !== nothing && Pardiso.set_solver!(solver, solver_type)
56-
56+
5757
solver
5858
else
5959
error("Panua Pardiso is not available.")
6060
end
6161
else
6262
error("Pardiso vendor must be either `:MKL` or `:Panua`")
6363
end
64-
64+
6565
if matrix_type !== nothing
6666
Pardiso.set_matrixtype!(solver, matrix_type)
6767
else
@@ -125,7 +125,6 @@ function LinearSolve.init_cacheval(alg::PardisoJL,
125125
b)
126126
end
127127

128-
>>>>>>> main
129128
return solver
130129
end
131130

src/extension_algs.jl

+8-9
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ All values default to `nothing` and the solver internally determines the values
108108
given the input types, and these keyword arguments are only for overriding the
109109
default handling process. This should not be required by most users.
110110
"""
111-
MKLPardisoFactorize(; kwargs...) = PardisoJL(; vendor=:MKL, solver_type = 0, kwargs...)
111+
MKLPardisoFactorize(; kwargs...) = PardisoJL(; vendor = :MKL, solver_type = 0, kwargs...)
112112

113113
"""
114114
```julia
@@ -136,8 +136,7 @@ All values default to `nothing` and the solver internally determines the values
136136
given the input types, and these keyword arguments are only for overriding the
137137
default handling process. This should not be required by most users.
138138
"""
139-
MKLPardisoIterate(; kwargs...) = PardisoJL(; vendor=:MKL, solver_type = 1, kwargs...)
140-
139+
MKLPardisoIterate(; kwargs...) = PardisoJL(; vendor = :MKL, solver_type = 1, kwargs...)
141140

142141
"""
143142
```julia
@@ -165,7 +164,8 @@ All values default to `nothing` and the solver internally determines the values
165164
given the input types, and these keyword arguments are only for overriding the
166165
default handling process. This should not be required by most users.
167166
"""
168-
PanuaPardisoFactorize(; kwargs...) = PardisoJL(; vendor=:Panua, solver_type = 0, kwargs...)
167+
PanuaPardisoFactorize(; kwargs...) = PardisoJL(;
168+
vendor = :Panua, solver_type = 0, kwargs...)
169169

170170
"""
171171
```julia
@@ -188,8 +188,7 @@ All values default to `nothing` and the solver internally determines the values
188188
given the input types, and these keyword arguments are only for overriding the
189189
default handling process. This should not be required by most users.
190190
"""
191-
PanuaPardisoIterate(; kwargs...) = PardisoJL(; vendor=:Panua, solver_type = 1, kwargs...)
192-
191+
PanuaPardisoIterate(; kwargs...) = PardisoJL(; vendor = :Panua, solver_type = 1, kwargs...)
193192

194193
"""
195194
```julia
@@ -198,7 +197,7 @@ PardisoJL(; nprocs::Union{Int, Nothing} = nothing,
198197
matrix_type = nothing,
199198
iparm::Union{Vector{Tuple{Int, Int}}, Nothing} = nothing,
200199
dparm::Union{Vector{Tuple{Int, Int}}, Nothing} = nothing,
201-
vendor::Union{Symbol,Nothing} = nothing
200+
vendor::Union{Symbol, Nothing} = nothing
202201
)
203202
```
204203
@@ -225,15 +224,15 @@ struct PardisoJL{T1, T2} <: LinearSolve.SciMLLinearSolveAlgorithm
225224
cache_analysis::Bool
226225
iparm::Union{Vector{Tuple{Int, Int}}, Nothing}
227226
dparm::Union{Vector{Tuple{Int, Int}}, Nothing}
228-
vendor::Union{Symbol,Nothing}
227+
vendor::Union{Symbol, Nothing}
229228

230229
function PardisoJL(; nprocs::Union{Int, Nothing} = nothing,
231230
solver_type = nothing,
232231
matrix_type = nothing,
233232
cache_analysis = false,
234233
iparm::Union{Vector{Tuple{Int, Int}}, Nothing} = nothing,
235234
dparm::Union{Vector{Tuple{Int, Int}}, Nothing} = nothing,
236-
vendor::Union{Symbol,Nothing}=nothing )
235+
vendor::Union{Symbol, Nothing} = nothing)
237236
ext = Base.get_extension(@__MODULE__, :LinearSolvePardisoExt)
238237
if ext === nothing
239238
error("PardisoJL requires that Pardiso is loaded, i.e. `using Pardiso`")

test/pardiso/pardiso.jl

+109-94
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,26 @@ cache_kwargs = (; abstol = 1e-8, reltol = 1e-8, maxiter = 30)
1818

1919
prob2 = LinearProblem(A2, b2)
2020

21-
algs=[PardisoJL()]
21+
algs=LinearSolve.SciMLLinearSolveAlgorithm[PardisoJL()]
22+
solvers=Pardiso.AbstractPardisoSolver[]
23+
extended_algs=LinearSolve.SciMLLinearSolveAlgorithm[PardisoJL()]
2224

2325
if Pardiso.mkl_is_available()
24-
algs=vcat(algs,[MKLPardisoFactorize(), MKLPardisoIterate()])
26+
push!(algs,MKLPardisoFactorize())
27+
push!(solvers,Pardiso.MKLPardisoSolver())
28+
extended_algs=vcat(extended_algs,[MKLPardisoFactorize(), MKLPardisoIterate()])
29+
@info "Testing MKL Pardiso"
2530
end
2631

2732
if Pardiso.panua_is_available()
28-
algs=vcat(algs,[PanuaPardisoFactorize(), PanuaPardisoIterate()])
33+
push!(algs,PanuaPardisoFactorize())
34+
push!(solvers,Pardiso.PardisoSolver())
35+
extended_algs=vcat(extended_algs,[PanuaPardisoFactorize(), PanuaPardisoIterate()])
36+
@info "Testing Panua Pardiso"
2937
end
3038

3139

32-
for alg in algs
40+
for alg in extended_algs
3341
u = solve(prob1, alg; cache_kwargs...).u
3442
@test A1 * u b1
3543

@@ -38,7 +46,6 @@ for alg in algs
3846
@test A2 * u b2
3947
end
4048

41-
return
4249

4350

4451
Random.seed!(10)
@@ -48,24 +55,27 @@ b1 = rand(n);
4855
b2 = rand(n);
4956
prob = LinearProblem(copy(A), copy(b1))
5057

51-
prob = LinearProblem(copy(A), copy(b1))
58+
5259
linsolve = init(prob, UMFPACKFactorization())
5360
sol11 = solve(linsolve)
5461
linsolve = LinearSolve.set_b(sol11.cache, copy(b2))
5562
sol12 = solve(linsolve)
5663
linsolve = LinearSolve.set_A(sol12.cache, copy(A2))
5764
sol13 = solve(linsolve)
5865

59-
linsolve = init(prob, MKLPardisoFactorize())
60-
sol31 = solve(linsolve)
61-
linsolve = LinearSolve.set_b(sol31.cache, copy(b2))
62-
sol32 = solve(linsolve)
63-
linsolve = LinearSolve.set_A(sol32.cache, copy(A2))
64-
sol33 = solve(linsolve)
6566

66-
@test sol11.u sol31.u
67-
@test sol12.u sol32.u
68-
@test sol13.u sol33.u
67+
68+
for alg in algs
69+
linsolve = init(prob, alg)
70+
sol31 = solve(linsolve)
71+
linsolve = LinearSolve.set_b(sol31.cache, copy(b2))
72+
sol32 = solve(linsolve)
73+
linsolve = LinearSolve.set_A(sol32.cache, copy(A2))
74+
sol33 = solve(linsolve)
75+
@test sol11.u sol31.u
76+
@test sol12.u sol32.u
77+
@test sol13.u sol33.u
78+
end
6979

7080

7181
# Test for problem from #497
@@ -78,87 +88,92 @@ function makeA()
7888
return(A)
7989
end
8090

81-
A=makeA()
82-
u0=fill(0.1,size(A,2))
83-
linprob = LinearProblem(A, A*u0)
84-
u = LinearSolve.solve(linprob, PardisoJL())
85-
@test norm(u-u0) < 1.0e-14
8691

92+
for alg in algs
93+
A=makeA()
94+
u0=fill(0.1,size(A,2))
95+
linprob = LinearProblem(A, A*u0)
96+
u = LinearSolve.solve(linprob, alg)
97+
@test norm(u-u0) < 1.0e-14
98+
end
8799

88100

89-
# Testing and demonstrating Pardiso.set_iparm! for MKLPardisoSolver
90-
solver = Pardiso.MKLPardisoSolver()
91-
iparm = [
92-
(1, 1),
93-
(2, 2),
94-
(3, 0),
95-
(4, 0),
96-
(5, 0),
97-
(6, 0),
98-
(7, 0),
99-
(8, 20),
100-
(9, 0),
101-
(10, 13),
102-
(11, 1),
103-
(12, 1),
104-
(13, 1),
105-
(14, 0),
106-
(15, 0),
107-
(16, 0),
108-
(17, 0),
109-
(18, -1),
110-
(19, -1),
111-
(20, 0),
112-
(21, 0),
113-
(22, 0),
114-
(23, 0),
115-
(24, 10),
116-
(25, 0),
117-
(26, 0),
118-
(27, 1),
119-
(28, 0),
120-
(29, 0),
121-
(30, 0),
122-
(31, 0),
123-
(32, 0),
124-
(33, 0),
125-
(34, 0),
126-
(35, 0),
127-
(36, 0),
128-
(37, 0),
129-
(38, 0),
130-
(39, 0),
131-
(40, 0),
132-
(41, 0),
133-
(42, 0),
134-
(43, 0),
135-
(44, 0),
136-
(45, 0),
137-
(46, 0),
138-
(47, 0),
139-
(48, 0),
140-
(49, 0),
141-
(50, 0),
142-
(51, 0),
143-
(52, 0),
144-
(53, 0),
145-
(54, 0),
146-
(55, 0),
147-
(56, 0),
148-
(57, 0),
149-
(58, 0),
150-
(59, 0),
151-
(60, 0),
152-
(61, 0),
153-
(62, 0),
154-
(63, 0),
155-
(64, 0)
156-
]
157-
158-
for i in iparm
159-
Pardiso.set_iparm!(solver, i...)
160-
end
161101

162-
for i in Base.OneTo(length(iparm))
163-
@test Pardiso.get_iparm(solver, i) == iparm[i][2]
102+
103+
# Testing and demonstrating Pardiso.set_iparm! for MKLPardisoSolver
104+
for solver in solvers
105+
iparm = [
106+
(1, 1),
107+
(2, 2),
108+
(3, 0),
109+
(4, 0),
110+
(5, 0),
111+
(6, 0),
112+
(7, 0),
113+
(8, 20),
114+
(9, 0),
115+
(10, 13),
116+
(11, 1),
117+
(12, 1),
118+
(13, 1),
119+
(14, 0),
120+
(15, 0),
121+
(16, 0),
122+
(17, 0),
123+
(18, -1),
124+
(19, -1),
125+
(20, 0),
126+
(21, 0),
127+
(22, 0),
128+
(23, 0),
129+
(24, 10),
130+
(25, 0),
131+
(26, 0),
132+
(27, 1),
133+
(28, 0),
134+
(29, 0),
135+
(30, 0),
136+
(31, 0),
137+
(32, 0),
138+
(33, 0),
139+
(34, 0),
140+
(35, 0),
141+
(36, 0),
142+
(37, 0),
143+
(38, 0),
144+
(39, 0),
145+
(40, 0),
146+
(41, 0),
147+
(42, 0),
148+
(43, 0),
149+
(44, 0),
150+
(45, 0),
151+
(46, 0),
152+
(47, 0),
153+
(48, 0),
154+
(49, 0),
155+
(50, 0),
156+
(51, 0),
157+
(52, 0),
158+
(53, 0),
159+
(54, 0),
160+
(55, 0),
161+
(56, 0),
162+
(57, 0),
163+
(58, 0),
164+
(59, 0),
165+
(60, 0),
166+
(61, 0),
167+
(62, 0),
168+
(63, 0),
169+
(64, 0)
170+
]
171+
172+
for i in iparm
173+
Pardiso.set_iparm!(solver, i...)
174+
end
175+
176+
for i in Base.OneTo(length(iparm))
177+
@test Pardiso.get_iparm(solver, i) == iparm[i][2]
178+
end
164179
end

0 commit comments

Comments
 (0)