Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cgls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ args_cgls = (:A, :b)
kwargs_cgls = (:M, :ldiv, :radius, , :atol, :rtol, :itmax, :timemax, :verbose, :history, :callback, :iostream)

@eval begin
function cgls!(workspace :: CglsWorkspace{T,FC,S}, $(def_args_cgls...); $(def_kwargs_cgls...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}, S <: AbstractVector{FC}}
function cgls!(workspace :: CglsWorkspace{T,FC,Sm,Sn}, $(def_args_cgls...); $(def_kwargs_cgls...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}, Sm <: AbstractVector{FC}, Sn <: AbstractVector{FC}}

# Timer
start_time = time_ns()
Expand All @@ -142,13 +142,13 @@ kwargs_cgls = (:M, :ldiv, :radius, :λ, :atol, :rtol, :itmax, :timemax, :verbose

# Check type consistency
eltype(A) == FC || @warn "eltype(A) ≠ $FC. This could lead to errors or additional allocations in operator-vector products."
ktypeof(b) == S || error("ktypeof(b) must be equal to $S")
ktypeof(b) == Sm || error("ktypeof(b) must be equal to $Sm")

# Compute the adjoint of A
Aᴴ = A'

# Set up workspace.
allocate_if(!MisI, workspace, :Mr, S, workspace.r) # The length of Mr is m
allocate_if(!MisI, workspace, :Mr, Sm, workspace.r) # The length of Mr is m
x, p, s, r, q, stats = workspace.x, workspace.p, workspace.s, workspace.r, workspace.q, workspace.stats
rNorms, ArNorms = stats.residuals, stats.Aresiduals
reset!(stats)
Expand Down
14 changes: 7 additions & 7 deletions src/gpmr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ optargs_gpmr = (:x0, :y0)
kwargs_gpmr = (:C, :D, :E, :F, :ldiv, :gsp, , , :reorthogonalization, :atol, :rtol, :itmax, :timemax, :verbose, :history, :callback, :iostream)

@eval begin
function gpmr!(workspace :: GpmrWorkspace{T,FC,S}, $(def_args_gpmr...); $(def_kwargs_gpmr...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}, S <: AbstractVector{FC}}
function gpmr!(workspace :: GpmrWorkspace{T,FC,Sm,Sn}, $(def_args_gpmr...); $(def_kwargs_gpmr...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}, Sm <: AbstractVector{FC}, Sn <: AbstractVector{FC}}

# Timer
start_time = time_ns()
Expand All @@ -181,8 +181,8 @@ kwargs_gpmr = (:C, :D, :E, :F, :ldiv, :gsp, :λ, :μ, :reorthogonalization, :ato
# Check type consistency
eltype(A) == FC || @warn "eltype(A) ≠ $FC. This could lead to errors or additional allocations in operator-vector products."
eltype(B) == FC || @warn "eltype(B) ≠ $FC. This could lead to errors or additional allocations in operator-vector products."
ktypeof(b) == S || error("ktypeof(b) must be equal to $S")
ktypeof(c) == S || error("ktypeof(c) must be equal to $S")
ktypeof(b) == Sm || error("ktypeof(b) must be equal to $Sm")
ktypeof(c) == Sn || error("ktypeof(c) must be equal to $Sn")

# Determine λ and μ associated to generalized saddle point systems.
gsp &&= one(FC) ; μ = zero(FC))
Expand All @@ -192,10 +192,10 @@ kwargs_gpmr = (:C, :D, :E, :F, :ldiv, :gsp, :λ, :μ, :reorthogonalization, :ato
warm_start && 0) && !FisI && error("Warm-start with right preconditioners is not supported.")

# Set up workspace.
allocate_if(!CisI, workspace, :q , S, workspace.x) # The length of q is m
allocate_if(!DisI, workspace, :p , S, workspace.y) # The length of p is n
allocate_if(!EisI, workspace, :wB, S, workspace.x) # The length of wB is m
allocate_if(!FisI, workspace, :wA, S, workspace.y) # The length of wA is n
allocate_if(!CisI, workspace, :q , Sm, workspace.x) # The length of q is m
allocate_if(!DisI, workspace, :p , Sn, workspace.y) # The length of p is n
allocate_if(!EisI, workspace, :wB, Sm, workspace.x) # The length of wB is m
allocate_if(!FisI, workspace, :wA, Sn, workspace.y) # The length of wA is n
wA, wB, dA, dB, Δx, Δy = workspace.wA, workspace.wB, workspace.dA, workspace.dB, workspace.Δx, workspace.Δy
x, y, V, U, gs, gc = workspace.x, workspace.y, workspace.V, workspace.U, workspace.gs, workspace.gc
zt, R, stats = workspace.zt, workspace.R, workspace.stats
Expand Down
60 changes: 59 additions & 1 deletion src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ for (workspace, krylov, args, def_args, optargs, def_optargs, kwargs, def_kwargs

krylov_solve(::Val{Symbol($krylov)}, $(def_args...); $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}} = $(krylov)($(args...); $(kwargs...))
end
elseif krylov in (:diom, :dqgmres, :fom, :gmres, :fgmres, :gpmr)
elseif krylov in (:diom, :dqgmres, :fom, :gmres, :fgmres)
@eval begin
function $(krylov)($(def_args...); memory::Int = 20, $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}}
start_time = time_ns()
Expand All @@ -164,6 +164,35 @@ for (workspace, krylov, args, def_args, optargs, def_optargs, kwargs, def_kwargs
return results(workspace)
end

krylov_solve(::Val{Symbol($krylov)}, $(def_args...), $(def_optargs...); memory::Int = 20, $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}} = $(krylov)($(args...), $(optargs...); memory, $(kwargs...))
end
end
elseif krylov == :gpmr
@eval begin
function $(krylov)($(def_args...); memory::Int = 20, $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}}
start_time = time_ns()
workspace = $workspace(KrylovConstructor(b, c, similar(b, 0), similar(c, 0)); memory)
elapsed_time = start_time |> ktimer
timemax -= elapsed_time
$(krylov!)(workspace, $(args...); $(kwargs...))
workspace.stats.timer += elapsed_time
return results(workspace)
end

krylov_solve(::Val{Symbol($krylov)}, $(def_args...); memory::Int = 20, $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}} = $(krylov)($(args...); memory, $(kwargs...))

if !isempty($optargs)
function $(krylov)($(def_args...), $(def_optargs...); memory::Int = 20, $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}}
start_time = time_ns()
workspace = $workspace(KrylovConstructor(b, c, similar(b, 0), similar(c, 0)); memory)
warm_start!(workspace, $(optargs...))
elapsed_time = start_time |> ktimer
timemax -= elapsed_time
$(krylov!)(workspace, $(args...); $(kwargs...))
workspace.stats.timer += elapsed_time
return results(workspace)
end

krylov_solve(::Val{Symbol($krylov)}, $(def_args...), $(def_optargs...); memory::Int = 20, $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}} = $(krylov)($(args...), $(optargs...); memory, $(kwargs...))
end
end
Expand Down Expand Up @@ -196,6 +225,35 @@ for (workspace, krylov, args, def_args, optargs, def_optargs, kwargs, def_kwargs
krylov_solve(::Val{Symbol($krylov)}, $(def_args...), $(def_optargs...); window::Int = 5, $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}} = $(krylov)($(args...), $(optargs...); window, $(kwargs...))
end
end
elseif krylov in (:tricg, :trimr)
@eval begin
function $(krylov)($(def_args...); $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}}
start_time = time_ns()
workspace = $workspace(KrylovConstructor(b, c, similar(b, 0), similar(c, 0)))
elapsed_time = start_time |> ktimer
timemax -= elapsed_time
$(krylov!)(workspace, $(args...); $(kwargs...))
workspace.stats.timer += elapsed_time
return results(workspace)
end

krylov_solve(::Val{Symbol($krylov)}, $(def_args...); $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}} = $(krylov)($(args...); $(kwargs...))

if !isempty($optargs)
function $(krylov)($(def_args...), $(def_optargs...); $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}}
start_time = time_ns()
workspace = $workspace(KrylovConstructor(b, c, similar(b, 0), similar(c, 0)))
warm_start!(workspace, $(optargs...))
elapsed_time = start_time |> ktimer
timemax -= elapsed_time
$(krylov!)(workspace, $(args...); $(kwargs...))
workspace.stats.timer += elapsed_time
return results(workspace)
end

krylov_solve(::Val{Symbol($krylov)}, $(def_args...), $(def_optargs...); $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}} = $(krylov)($(args...), $(optargs...); $(kwargs...))
end
end
else
@eval begin
function $(krylov)($(def_args...); $(def_kwargs...)) where {T <: AbstractFloat, FC <: FloatOrComplex{T}}
Expand Down
4 changes: 2 additions & 2 deletions src/krylov_show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ end

Statistics of `workspace` are displayed if `show_stats` is set to true.
"""
function show(io :: IO, workspace :: Union{KrylovWorkspace{T,FC,S}, BlockKrylovWorkspace{T,FC,S}}; show_stats :: Bool=true) where {T <: AbstractFloat, FC <: FloatOrComplex{T}, S <: AbstractVector{FC}}
function show(io :: IO, workspace :: Union{KrylovWorkspaceNext{T,FC,S}, BlockKrylovWorkspace{T,FC,S}}; show_stats :: Bool=true) where {T <: AbstractFloat, FC <: FloatOrComplex{T}, S <: AbstractVector{FC}}
type_workspace = typeof(workspace)
name_workspace = string(type_workspace.name.name)
name_stats = string(typeof(workspace.stats).name.name)
nbytes = sizeof(workspace)
storage = format_bytes(nbytes)
architecture = S <: Vector ? "CPU" : "GPU"
architecture = S <: Vector ? "CPU" : "GPU" # FIXME cannot assume that all non-Vector types are GPU types
l1 = max(length(name_workspace), length(string(FC)) + 11) # length("Precision: ") = 11
nchar = type_workspace <: Union{CgLanczosShiftWorkspace, FomWorkspace, DiomWorkspace, DqgmresWorkspace, GmresWorkspace, FgmresWorkspace, GpmrWorkspace, BlockGmresWorkspace} ? 8 : 0 # length("Vector{}") = 8
l2 = max(ndigits(workspace.m) + 7, length(architecture) + 14, length(string(S)) + nchar) # length("nrows: ") = 7 and length("Architecture: ") = 14
Expand Down
Loading
Loading