Skip to content

Commit 0920aec

Browse files
committed
Interface Block-GMRES from Krylov.jl
1 parent afc7a12 commit 0920aec

File tree

3 files changed

+22
-36
lines changed

3 files changed

+22
-36
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ IterativeSolvers = "0.9.3"
8686
JET = "0.8.28, 0.9"
8787
KLU = "0.6"
8888
KernelAbstractions = "0.9.27"
89-
Krylov = "0.9"
89+
Krylov = "0.9.8"
9090
KrylovKit = "0.8"
9191
KrylovPreconditioners = "0.3"
9292
LazyArrays = "1.8, 2"

src/iterative_wrappers.jl

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ function KrylovJL_GMRES(args...; kwargs...)
6363
KrylovJL(args...; KrylovAlg = Krylov.gmres!, kwargs...)
6464
end
6565

66+
"""
67+
```julia
68+
KrylovJL_BLOCK_GMRES(args...; gmres_restart = 0, window = 0, kwargs...)
69+
```
70+
71+
A generic BLOCK-GMRES implementation for square non-Hermitian linear systems with multiple right-hand sides
72+
"""
73+
function KrylovJL_BLOCK_GMRES(args...; kwargs...)
74+
KrylovJL(args...; KrylovAlg = Krylov.block_gmres!, kwargs...)
75+
end
76+
6677
"""
6778
```julia
6879
KrylovJL_BICGSTAB(args...; kwargs...)
@@ -143,8 +154,10 @@ function get_KrylovJL_solver(KrylovAlg)
143154
Krylov.CrmrSolver
144155
elseif (KrylovAlg === Krylov.cg!)
145156
Krylov.CgSolver
146-
elseif (KrylovAlg === Krylov.cg_lanczos!)
157+
elseif (KrylovAlg === Krylov.cg_lanczos_shift!)
147158
Krylov.CgLanczosShiftSolver
159+
elseif (KrylovAlg === Krylov.cgls_lanczos_shift!)
160+
Krylov.CglsLanczosShiftSolver
148161
elseif (KrylovAlg === Krylov.cgls!)
149162
Krylov.CglsSolver
150163
elseif (KrylovAlg === Krylov.cg_lanczos!)
@@ -163,6 +176,8 @@ function get_KrylovJL_solver(KrylovAlg)
163176
Krylov.GpmrSolver
164177
elseif (KrylovAlg === Krylov.fom!)
165178
Krylov.FomSolver
179+
elseif (KrylovAlg === Krylov.block_gmres!)
180+
Krylov.BlockGmresSolver
166181
else
167182
error("Invalid Krylov method detected")
168183
end
@@ -181,7 +196,8 @@ function init_cacheval(alg::KrylovJL, A, b, u, Pl, Pr, maxiters::Int, abstol, re
181196
alg.KrylovAlg === Krylov.gmres! ||
182197
alg.KrylovAlg === Krylov.fgmres! ||
183198
alg.KrylovAlg === Krylov.gpmr! ||
184-
alg.KrylovAlg === Krylov.fom!)
199+
alg.KrylovAlg === Krylov.fom! ||
200+
alg.KrylovAlg === Krylov.block_gmres!)
185201
if A isa SparseMatrixCSC
186202
KS(SparseMatrixCSC(0, 0, [1], Int[], eltype(A)[]), eltype(b)[], 1)
187203
elseif A isa Matrix
@@ -206,7 +222,8 @@ function init_cacheval(alg::KrylovJL, A, b, u, Pl, Pr, maxiters::Int, abstol, re
206222
alg.KrylovAlg === Krylov.gmres! ||
207223
alg.KrylovAlg === Krylov.fgmres! ||
208224
alg.KrylovAlg === Krylov.gpmr! ||
209-
alg.KrylovAlg === Krylov.fom!)
225+
alg.KrylovAlg === Krylov.fom! ||
226+
alg.KrylovAlg === Krylov.block_gmres!)
210227
KS(A, b, memory)
211228
elseif (alg.KrylovAlg === Krylov.minres! ||
212229
alg.KrylovAlg === Krylov.symmlq! ||

src/simplegmres.jl

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -88,38 +88,7 @@ function update_cacheval!(cache::LinearCache, cacheval::SimpleGMRESCache, name::
8888
return cacheval
8989
end
9090

91-
"""
92-
(c, s, ρ) = _sym_givens(a, b)
93-
94-
Numerically stable symmetric Givens reflection.
95-
Given `a` and `b` reals, return `(c, s, ρ)` such that
96-
97-
[ c s ] [ a ] = [ ρ ]
98-
[ s -c ] [ b ] = [ 0 ].
99-
"""
100-
function _sym_givens(a::T, b::T) where {T <: AbstractFloat}
101-
# This has taken from Krylov.jl
102-
if b == 0
103-
c = ifelse(a == 0, one(T), sign(a)) # In Julia, sign(0) = 0.
104-
s = zero(T)
105-
ρ = abs(a)
106-
elseif a == 0
107-
c = zero(T)
108-
s = sign(b)
109-
ρ = abs(b)
110-
elseif abs(b) > abs(a)
111-
t = a / b
112-
s = sign(b) / sqrt(one(T) + t * t)
113-
c = s * t
114-
ρ = b / s # Computationally better than ρ = a / c since |c| ≤ |s|.
115-
else
116-
t = b / a
117-
c = sign(a) / sqrt(one(T) + t * t)
118-
s = c * t
119-
ρ = a / c # Computationally better than ρ = b / s since |s| ≤ |c|
120-
end
121-
return (c, s, ρ)
122-
end
91+
_sym_givens(a::T, b::T) where {T <: AbstractFloat} = Krylov.sym_givens(a, b)
12392

12493
function _sym_givens!(c, s, R, nr::Int, inner_iter::Int, bsize::Int, Hbis)
12594
if __is_extension_loaded(Val(:KernelAbstractions))

0 commit comments

Comments
 (0)