Skip to content

Commit cda37ad

Browse files
authored
Use the suffix Workspace instead of Solver (#990)
1 parent 0baf80e commit cda37ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2488
-2475
lines changed

docs/src/api.md

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,51 @@ Krylov.LsmrStats
1515
## Workspace of Krylov methods
1616

1717
```@docs
18-
KrylovSolver
19-
MinresSolver
20-
MinaresSolver
21-
CgSolver
22-
CrSolver
23-
CarSolver
24-
SymmlqSolver
25-
CgLanczosSolver
26-
CgLanczosShiftSolver
27-
MinresQlpSolver
28-
DiomSolver
29-
FomSolver
30-
DqgmresSolver
31-
GmresSolver
32-
UsymlqSolver
33-
UsymqrSolver
34-
TricgSolver
35-
TrimrSolver
36-
TrilqrSolver
37-
CgsSolver
38-
BicgstabSolver
39-
BilqSolver
40-
QmrSolver
41-
BilqrSolver
42-
CglsSolver
43-
CglsLanczosShiftSolver
44-
CrlsSolver
45-
CgneSolver
46-
CrmrSolver
47-
LslqSolver
48-
LsqrSolver
49-
LsmrSolver
50-
LnlqSolver
51-
CraigSolver
52-
CraigmrSolver
53-
GpmrSolver
54-
FgmresSolver
18+
KrylovWorkspace
19+
MinresWorkspace
20+
MinaresWorkspace
21+
CgWorkspace
22+
CrWorkspace
23+
CarWorkspace
24+
SymmlqWorkspace
25+
CgLanczosWorkspace
26+
CgLanczosShiftWorkspace
27+
MinresQlpWorkspace
28+
DiomWorkspace
29+
FomWorkspace
30+
DqgmresWorkspace
31+
GmresWorkspace
32+
UsymlqWorkspace
33+
UsymqrWorkspace
34+
TricgWorkspace
35+
TrimrWorkspace
36+
TrilqrWorkspace
37+
CgsWorkspace
38+
BicgstabWorkspace
39+
BilqWorkspace
40+
QmrWorkspace
41+
BilqrWorkspace
42+
CglsWorkspace
43+
CglsLanczosShiftWorkspace
44+
CrlsWorkspace
45+
CgneWorkspace
46+
CrmrWorkspace
47+
LslqWorkspace
48+
LsqrWorkspace
49+
LsmrWorkspace
50+
LnlqWorkspace
51+
CraigWorkspace
52+
CraigmrWorkspace
53+
GpmrWorkspace
54+
FgmresWorkspace
5555
```
5656

5757
## Workspace of block-Krylov methods
5858

5959
```@docs
60-
BlockKrylovSolver
61-
BlockMinresSolver
62-
BlockGmresSolver
60+
BlockKrylovWorkspace
61+
BlockMinresWorkspace
62+
BlockGmresWorkspace
6363
```
6464

6565
## Utilities

docs/src/callbacks.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
# [Callbacks](@id callbacks)
22

3-
Each Krylov method is able to call a callback function as `callback(solver)` at each iteration.
3+
Each Krylov method is able to call a callback function as `callback(workspace)` at each iteration.
44
The callback should return `true` if the main loop should terminate, and `false` otherwise.
55
If the method terminated because of the callback, the output status will be `"user-requested exit"`.
6-
For example, if the user defines `minres_callback(solver::MinresSolver)`, it can be passed to the solver using
6+
For example, if the user defines `minres_callback(workspace::MinresWorkspace)`, it can be passed to the solver using
77

88
```julia
99
(x, stats) = minres(A, b, callback = minres_callback)
1010
```
1111

12-
If you need to write a callback that uses variables that are not in a `KrylovSolver`, use a closure:
12+
If you need to write a callback that uses variables that are not in a `KrylovWorkspace`, use a closure:
1313

1414
```julia
15-
function custom_stopping_condition(solver::KrylovSolver, A, b, r, tol)
16-
mul!(r, A, solver.x)
15+
function custom_stopping_condition(workspace::KrylovWorkspace, A, b, r, tol)
16+
mul!(r, A, workspace.x)
1717
r .-= b # r := b - Ax
1818
bool = norm(r) tol # tolerance based on the 2-norm of the residual
1919
return bool
2020
end
2121

22-
cg_callback(solver) = custom_stopping_condition(solver, A, b, r, tol)
22+
cg_callback(workspace) = custom_stopping_condition(workspace, A, b, r, tol)
2323
(x, stats) = cg(A, b, callback = cg_callback)
2424
```
2525

@@ -33,10 +33,10 @@ mutable struct CallbackWorkspace{T}
3333
tol::T
3434
end
3535

36-
function (workspace::CallbackWorkspace)(solver::KrylovSolver)
37-
mul!(workspace.r, workspace.A, solver.x)
38-
workspace.r .-= workspace.b
39-
bool = norm(workspace.r) workspace.tol
36+
function (callback::CallbackWorkspace)(workspace::KrylovWorkspace)
37+
mul!(callback.r, callback.A, workspace.x)
38+
callback.r .-= callback.b
39+
bool = norm(callback.r) callback.tol
4040
return bool
4141
end
4242

@@ -51,12 +51,12 @@ We now illustrate how to store all iterates $x_k$ of the GMRES method.
5151
S = Krylov.ktypeof(b)
5252
global X = S[] # Storage for GMRES iterates
5353

54-
function gmres_callback(solver)
55-
z = solver.z
56-
k = solver.inner_iter
54+
function gmres_callback(workspace)
55+
z = workspace.z
56+
k = workspace.inner_iter
5757
nr = sum(1:k)
58-
V = solver.V
59-
R = solver.R
58+
V = workspace.V
59+
R = workspace.R
6060
y = copy(z)
6161

6262
# Solve Rk * yk = zk

docs/src/custom_workspaces.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,12 @@ b = HaloVector(data)
326326
327327
# Allocate the workspace
328328
kc = KrylovConstructor(b)
329-
solver = CgSolver(kc)
329+
workspace = CgWorkspace(kc)
330330
331331
# Solve the system with CG
332-
Krylov.cg!(solver, A, b, atol=1e-12, rtol=0.0, verbose=1)
333-
u_sol = solution(solver)
334-
stats = statistics(solver)
332+
Krylov.cg!(workspace, A, b, atol=1e-12, rtol=0.0, verbose=1)
333+
u_sol = solution(workspace)
334+
stats = statistics(workspace)
335335
```
336336

337337
```@example halo-regions
@@ -439,11 +439,11 @@ We now solve the system $Ax = b$ using `minres` with our preconditioner:
439439
using Krylov
440440
441441
kc = KrylovConstructor(b)
442-
solver = MinresSolver(kc)
443-
minres!(solver, A, b; M=P)
442+
workspace = MinresWorkspace(kc)
443+
minres!(workspace, A, b; M=P)
444444
445-
x = solution(solver)
446-
stats = statistics(solver)
445+
x = solution(workspace)
446+
stats = statistics(workspace)
447447
niter = stats.niter
448448
```
449449

docs/src/generic_interface.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ b = randn(n)
3434

3535
# Out-of-place interface
3636
for method in (:cg, :cr, :car)
37-
x, stats = krylov_solve(Val{method}(), A, b)
37+
x, stats = krylov_solve(Val(method), A, b)
3838
r = b - A * x
3939
println("Residual norm for $(method): ", norm(r))
4040
end
@@ -51,23 +51,23 @@ b = rand(n)
5151
# In-place interface
5252
for method in (:bicgstab, :gmres)
5353
# Create a workspace for the Krylov method
54-
solver = krylov_workspace(Val(method), A, b)
54+
workspace = krylov_workspace(Val(method), A, b)
5555

5656
# Solve the system in-place
57-
krylov_solve!(solver, A, b)
57+
krylov_solve!(workspace, A, b)
5858

5959
# Get the statistics
60-
stats = statistics(solver)
60+
stats = statistics(workspace)
6161

6262
# Retrieve the solution
63-
x = solution(solver)
63+
x = solution(workspace)
6464

6565
# Check if the solver converged
66-
solved = issolved(solver)
66+
solved = issolved(workspace)
6767
println("Converged $method: ", solved)
6868

6969
# Display the number of iterations
70-
niter = niterations(solver)
70+
niter = niterations(workspace)
7171
println("Number of iterations for $method: ", niter)
7272
end
7373
```

docs/src/inplace.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
## [In-place methods](@id in-place)
22

33
All solvers in Krylov.jl have an in-place variant implemented in a method whose name ends with `!`.
4-
A workspace (`KrylovSolver`), which contains the storage needed by a Krylov method, can be used to solve multiple linear systems with the same dimensions and the same floating-point precision.
4+
A workspace (`KrylovWorkspace`), which contains the storage needed by a Krylov method, can be used to solve multiple linear systems with the same dimensions and the same floating-point precision.
55
The section [storage requirements](@ref storage-requirements) specifies the memory needed for each Krylov method.
66

7-
Each `KrylovSolver` has three constructors with consistent argument patterns:
7+
Each `KrylovWorkspace` has three constructors with consistent argument patterns:
88

99
```@constructors
10-
XyzSolver(A, b)
11-
XyzSolver(m, n, S)
12-
XyzSolver(kc::KrylovConstructor)
10+
XyzWorkspace(A, b)
11+
XyzWorkspace(m, n, S)
12+
XyzWorkspace(kc::KrylovConstructor)
1313
```
14-
The only exceptions are `CgLanczosShiftSolver` and `CglsLanczosShiftSolver`, which require an additional argument `nshifts`.
14+
The only exceptions are `CgLanczosShiftWorkspace` and `CglsLanczosShiftWorkspace`, which require an additional argument `nshifts`.
1515
Additionally, some constructors accept keyword arguments.
1616

1717
`Xyz` represents the name of the Krylov method, written in lowercase except for its first letter (such as `Cg`, `Minres`, `Lsmr` or `Bicgstab`).
18-
If the name of the Krylov method contains an underscore (e.g., `minres_qlp` or `cgls_lanczos_shift`), the workspace constructor transforms it by capitalizing each word and removing underscores, resulting in names like `MinresQlpSolver` or `CglsLanczosShiftSolver`.
18+
If the name of the Krylov method contains an underscore (e.g., `minres_qlp` or `cgls_lanczos_shift`), the workspace constructor transforms it by capitalizing each word and removing underscores, resulting in names like `MinresQlpWorkspace` or `CglsLanczosShiftWorkspace`.
1919

20-
Given an operator `A` and a right-hand side `b`, you can create a `KrylovSolver` based on the size of `A` and the type of `b`, or explicitly provide the dimensions `(m, n)` and the storage type `S`.
20+
Given an operator `A` and a right-hand side `b`, you can create a `KrylovWorkspace` based on the size of `A` and the type of `b`, or explicitly provide the dimensions `(m, n)` and the storage type `S`.
2121

2222
We assume that `S(undef, 0)`, `S(undef, n)`, and `S(undef, m)` are well-defined for the storage type `S`.
2323
For more advanced vector types, workspaces can also be created with the help of a `KrylovConstructor`.
@@ -31,17 +31,17 @@ For example, use `S = Vector{Float64}` if you want to solve linear systems in do
3131
The workspace is always the first argument of the in-place methods:
3232

3333
```@solvers
34-
minres_solver = MinresSolver(m, n, Vector{Float64})
35-
minres!(minres_solver, A1, b1)
34+
minres_workspace = MinresWorkspace(m, n, Vector{Float64})
35+
minres!(minres_workspace, A1, b1)
3636
37-
bicgstab_solver = BicgstabSolver(m, n, Vector{ComplexF64})
38-
bicgstab!(bicgstab_solver, A2, b2)
37+
bicgstab_workspace = BicgstabWorkspace(m, n, Vector{ComplexF64})
38+
bicgstab!(bicgstab_workspace, A2, b2)
3939
40-
gmres_solver = GmresSolver(m, n, Vector{BigFloat})
41-
gmres!(gmres_solver, A3, b3)
40+
gmres_workspace = GmresWorkspace(m, n, Vector{BigFloat})
41+
gmres!(gmres_workspace, A3, b3)
4242
43-
lsqr_solver = LsqrSolver(m, n, CuVector{Float32})
44-
lsqr!(lsqr_solver, A4, b4)
43+
lsqr_workspace = LsqrWorkspace(m, n, CuVector{Float32})
44+
lsqr!(lsqr_workspace, A4, b4)
4545
```
4646

4747
## Examples
@@ -62,18 +62,18 @@ function newton(∇f, ∇²f, x₀; itmax = 200, tol = 1e-8)
6262
6363
iter = 0
6464
S = typeof(x)
65-
solver = CgSolver(n, n, S)
66-
Δx = solver.x
65+
workspace = CgWorkspace(n, n, S)
66+
Δx = workspace.x
6767
6868
solved = false
6969
tired = false
7070
7171
while !(solved || tired)
7272
73-
Hx = ∇²f(x) # Compute ∇²f(xₖ)
74-
cg!(solver, Hx, -gx) # Solve ∇²f(xₖ)Δx = -∇f(xₖ)
75-
x = x + Δx # Update xₖ₊₁ = xₖ + Δx
76-
gx = ∇f(x) # ∇f(xₖ₊₁)
73+
Hx = ∇²f(x) # Compute ∇²f(xₖ)
74+
cg!(workspace, Hx, -gx) # Solve ∇²f(xₖ)Δx = -∇f(xₖ)
75+
x = x + Δx # Update xₖ₊₁ = xₖ + Δx
76+
gx = ∇f(x) # ∇f(xₖ₊₁)
7777
7878
iter += 1
7979
solved = norm(gx) ≤ tol
@@ -97,19 +97,19 @@ function gauss_newton(F, JF, x₀; itmax = 200, tol = 1e-8)
9797
9898
iter = 0
9999
S = typeof(x)
100-
solver = LsmrSolver(m, n, S)
101-
Δx = solver.x
100+
workspace = LsmrWorkspace(m, n, S)
101+
Δx = workspace.x
102102
103103
solved = false
104104
tired = false
105105
106106
while !(solved || tired)
107107
108-
Jx = JF(x) # Compute J(xₖ)
109-
lsmr!(solver, Jx, -Fx) # Minimize ‖J(xₖ)Δx + F(xₖ)‖
110-
x = x + Δx # Update xₖ₊₁ = xₖ + Δx
111-
Fx_old = Fx # F(xₖ)
112-
Fx = F(x) # F(xₖ₊₁)
108+
Jx = JF(x) # Compute J(xₖ)
109+
lsmr!(workspace, Jx, -Fx) # Minimize ‖J(xₖ)Δx + F(xₖ)‖
110+
x = x + Δx # Update xₖ₊₁ = xₖ + Δx
111+
Fx_old = Fx # F(xₖ)
112+
Fx = F(x) # F(xₖ₊₁)
113113
114114
iter += 1
115115
solved = norm(Fx - Fx_old) / norm(Fx) ≤ tol

docs/src/storage.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ Each table summarizes the storage requirements of Krylov methods recommended to
105105

106106
## Practical storage requirements
107107

108-
Each method has its own `KrylovSolver` that contains all the storage needed by the method.
109-
In the REPL, the size in bytes of each attribute and the total amount of memory allocated by the solver are displayed when we show a `KrylovSolver`.
108+
Each method has its own `KrylovWorkspace` that contains all the storage needed by the method.
109+
In the REPL, the size in bytes of each attribute and the total amount of memory allocated by the solver are displayed when we show a `KrylovWorkspace`.
110110

111111
```@example storage
112112
using Krylov
@@ -115,14 +115,14 @@ m = 5000
115115
n = 12000
116116
A = rand(Float64, m, n)
117117
b = rand(Float64, m)
118-
solver = LsmrSolver(A, b)
119-
show(stdout, solver, show_stats=false)
118+
workspace = LsmrWorkspace(A, b)
119+
show(stdout, workspace, show_stats=false)
120120
```
121121

122-
If we want the total number of bytes used by the solver, we can call `nbytes = sizeof(solver)`.
122+
If we want the total number of bytes used by the workspace, we can call `nbytes = sizeof(workspace)`.
123123

124124
```@example storage
125-
nbytes = sizeof(solver)
125+
nbytes = sizeof(workspace)
126126
```
127127

128128
Thereafter, we can use `Base.format_bytes(nbytes)` to recover what is displayed in the REPL.
@@ -140,7 +140,7 @@ ncoefs_lsmr = 5*n + 2*m # number of coefficients
140140
nbytes_lsmr = sizeof(FC) * ncoefs_lsmr # number of bytes
141141
```
142142

143-
Therefore, you can check that you have enough memory in RAM to allocate a `KrylovSolver`.
143+
Therefore, you can check that you have enough memory in RAM to allocate a `KrylovWorkspace`.
144144

145145
```@example storage
146146
free_nbytes = Sys.free_memory()

0 commit comments

Comments
 (0)