-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block-Krylov processes #800
Merged
Merged
Conversation
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
amontoison
force-pushed
the
block-processes
branch
3 times, most recently
from
September 14, 2023 07:06
ba16fa4
to
114949d
Compare
Codecov ReportAttention:
... and 1 file with indirect coverage changes 📢 Thoughts on this report? Let us know!. |
amontoison
force-pushed
the
block-processes
branch
from
September 15, 2023 20:38
18bdbc0
to
34b875f
Compare
amontoison
force-pushed
the
block-processes
branch
from
September 23, 2023 17:18
3a6624c
to
c052088
Compare
amontoison
force-pushed
the
block-processes
branch
from
September 24, 2023 05:12
e37022a
to
8553f94
Compare
@frapac using Krylov, LinearAlgebra, Printf
function block_krylov(solver::String, A, B::AbstractMatrix{FC}; atol::FC=√eps(FC), rtol::FC=√eps(FC), itmax::Int=0, verbose::Bool=false) where FC
m, n = size(A)
t, p = size(B)
m == n || error("System must be square")
t == m || error("Inconsistent problem size")
(itmax == 0) && (itmax = div(n, p) + 1)
k = 0
Bnorm = norm(B)
Brank = rank(B)
ε = atol + rtol * Bnorm
solved = Bnorm ≤ ε
tired = false
algo = "householder"
local X
verbose && @printf("block-%s: system of %d equations in %d variables with %d rhs.\n", solver, m, n, p)
verbose && @printf("%5s %7s %8s\n", "k", "‖Rₖ‖", "rank(Rₖ)")
verbose && @printf("%5d %7.1e %8d\n", k, Bnorm, Brank)
while !(solved || tired)
k += 1
# Block-Krylov processes
if solver ∈ ("fom", "gmres")
V, Γ, H = arnoldi(A, B, k; algo)
elseif solver ∈ ("symmlq", "cg", "minres")
V, Ψ₁, T = hermitian_lanczos(A, B, k; algo)
elseif solver ∈ ("usymlq", "usymqr")
V, Ψ₁, T, U, Φ₁ᴴ, Tᴴ = saunders_simon_yip(A, B, B, k; algo)
elseif solver ∈ ("bilq", "bicg", "qmr")
V, Ψ₁, T, U, Φ₁ᴴ, Tᴴ = nonhermitian_lanczos(A, B, B, k)
else
error("The method block-$solver is not supported.")
end
# Block-Krylov methods
if solver == "fom"
rhs = zeros(FC, p*k, p)
rhs[1:p,1:p] .= Γ
Y = H[1:k*p,1:k*p] \ rhs
elseif solver == "gmres"
rhs = zeros(FC, p*(k+1), p)
rhs[1:p,1:p] .= Γ
Y = H \ rhs
elseif solver ∈ ("symmlq", "bilq", "usymlq")
if k == 1
Y = zeros(FC, p*k, p)
else
rhs = zeros(FC, p*(k-1), p)
rhs[1:p,1:p] .= Ψ₁
T = Matrix(T)
Y = T[1:(k-1)*p,1:k*p] \ rhs
end
elseif solver ∈ ("cg", "bicg")
rhs = zeros(FC, p*k, p)
rhs[1:p,1:p] .= Ψ₁
Y = T[1:k*p,1:k*p] \ rhs
elseif solver ∈ ("minres", "qmr", "usymqr")
rhs = zeros(FC, p*(k+1), p)
rhs[1:p,1:p] .= Ψ₁
Y = T \ rhs
end
# Compute the approximate solution Xₖ and the residual Rₖ
if solver ∈ ("usymlq", "usymqr")
X = U[:,1:k*p] * Y[1:k*p,:]
else
X = V[:,1:k*p] * Y[1:k*p,:]
end
R = B - A * X
Rnorm = norm(R)
Rrank = rank(R)
verbose && @printf("%5d %7.1e %8d\n", k, Rnorm, Rrank)
tired = k ≥ itmax
solved = Rnorm ≤ ε
end
return X
end
block_fom(A, B::AbstractMatrix{FC}; atol::FC=√eps(FC), rtol::FC=√eps(FC), itmax::Int=0, verbose::Bool=false) where FC = block_krylov("fom", A, B; atol, rtol, itmax, verbose)
block_gmres(A, B::AbstractMatrix{FC}; atol::FC=√eps(FC), rtol::FC=√eps(FC), itmax::Int=0, verbose::Bool=false) where FC = block_krylov("gmres", A, B; atol, rtol, itmax, verbose)
block_symmlq(A, B::AbstractMatrix{FC}; atol::FC=√eps(FC), rtol::FC=√eps(FC), itmax::Int=0, verbose::Bool=false) where FC = block_krylov("symmlq", A, B; atol, rtol, itmax, verbose)
block_cg(A, B::AbstractMatrix{FC}; atol::FC=√eps(FC), rtol::FC=√eps(FC), itmax::Int=0, verbose::Bool=false) where FC = block_krylov("cg", A, B; atol, rtol, itmax, verbose)
block_minres(A, B::AbstractMatrix{FC}; atol::FC=√eps(FC), rtol::FC=√eps(FC), itmax::Int=0, verbose::Bool=false) where FC = block_krylov("minres", A, B; atol, rtol, itmax, verbose)
block_usymlq(A, B::AbstractMatrix{FC}; atol::FC=√eps(FC), rtol::FC=√eps(FC), itmax::Int=0, verbose::Bool=false) where FC = block_krylov("usymlq", A, B; atol, rtol, itmax, verbose)
block_usymqr(A, B::AbstractMatrix{FC}; atol::FC=√eps(FC), rtol::FC=√eps(FC), itmax::Int=0, verbose::Bool=false) where FC = block_krylov("usymqr", A, B; atol, rtol, itmax, verbose)
block_bilq(A, B::AbstractMatrix{FC}; atol::FC=√eps(FC), rtol::FC=√eps(FC), itmax::Int=0, verbose::Bool=false) where FC = block_krylov("bilq", A, B; atol, rtol, itmax, verbose)
block_bicg(A, B::AbstractMatrix{FC}; atol::FC=√eps(FC), rtol::FC=√eps(FC), itmax::Int=0, verbose::Bool=false) where FC = block_krylov("bicg", A, B; atol, rtol, itmax, verbose)
block_qmr(A, B::AbstractMatrix{FC}; atol::FC=√eps(FC), rtol::FC=√eps(FC), itmax::Int=0, verbose::Bool=false) where FC = block_krylov("qmr", A, B; atol, rtol, itmax, verbose) |
amontoison
force-pushed
the
block-processes
branch
2 times, most recently
from
October 4, 2023 05:01
b4ca87d
to
21d9c95
Compare
amontoison
force-pushed
the
block-processes
branch
from
October 20, 2023 23:20
21d9c95
to
77d4f6d
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://jso.dev/Krylov.jl/previews/PR800/block_processes/