You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/generic_interface.md
+14-7Lines changed: 14 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,16 @@ They allow to build Krylov workspaces and call both in-place and out-of-place va
6
6
7
7
```@docs
8
8
krylov_workspace
9
-
krylov_solve!
10
9
krylov_solve
10
+
krylov_solve!
11
11
```
12
12
13
+
The section on [workspace accessors](@ref workspace-accessors) describes how to retrieve the solution, statistics, and other results from a workspace after calling `krylov_solve!`.
14
+
13
15
## Examples
14
16
15
-
```julia
16
-
using Krylov, Random
17
+
```@example op_interface
18
+
using Krylov, SparseArrays, LinearAlgebra
17
19
18
20
# Define a symmetric positive definite matrix A and a right-hand side vector b
19
21
n = 1000
@@ -29,16 +31,16 @@ for method in (:cg, :cr, :car)
29
31
end
30
32
```
31
33
32
-
```julia
33
-
using Krylov, Random
34
+
```@example ip_interface
35
+
using Krylov, SparseArrays, LinearAlgebra
34
36
35
37
# Define a square nonsymmetric matrix A and a right-hand side vector b
36
38
n = 100
37
39
A = sprand(n, n, 0.05) + I
38
40
b = rand(n)
39
41
40
42
# In-place interface
41
-
for method in (:bicgstab, :gmres)
43
+
for method in (:bicgstab, :gmres, :qmr)
42
44
# Create a workspace for the Krylov method
43
45
workspace = krylov_workspace(Val(method), A, b)
44
46
@@ -56,13 +58,18 @@ for method in (:bicgstab, :gmres)
56
58
println("Convergence of $method: ", solved)
57
59
58
60
# Display the number of iterations
59
-
niter = Krylov.niterations(workspace)
61
+
niter = Krylov.iteration_count(workspace)
60
62
println("Number of iterations for $method: ", niter)
61
63
62
64
# Display the elapsed timer
63
65
timer = Krylov.elapsed_time(workspace)
64
66
println("Elapsed time for $method: ", timer, " seconds")
65
67
68
+
# Display the number of operator-vector products with A and A'
69
+
nAprod = Krylov.Aprod_count(workspace)
70
+
nAtprod = Krylov.Atprod_count(workspace)
71
+
println("Number of operator-vector products with A and A' for $method: ", (nAprod, nAtprod))
Copy file name to clipboardExpand all lines: src/workspace_accessors.jl
+45-45Lines changed: 45 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -2,81 +2,84 @@
2
2
solution(workspace)
3
3
4
4
Return the solution(s) stored in the `workspace`.
5
+
5
6
Optionally you can specify which solution you want to recover,
6
7
`solution(workspace, 1)` returns `x` and `solution(workspace, 2)` returns `y`.
7
8
"""
8
9
function solution end
9
10
10
11
"""
11
-
nsolution(workspace)
12
+
statistics(workspace)
12
13
13
-
Return the number of outputs of `solution(workspace)`.
14
+
Return the statistics stored in `workspace`.
14
15
"""
15
-
functionnsolutionend
16
+
functionstatisticsend
16
17
17
18
"""
18
-
statistics(workspace)
19
+
results(workspace)
19
20
20
-
Return the statistics stored in `workspace`.
21
+
Return a tuple containing the solution(s) and the statistics associated with `workspace`.
22
+
This allows retrieving the output arguments of an out-of-place method from an in-place method.
23
+
24
+
For example, instead of `x, stats = cg(A, b)`, you can use:
25
+
```julia
26
+
workspace = CgWorkspace(A, b)
27
+
cg!(workspace, A, b)
28
+
x, stats = results(workspace)
29
+
```
21
30
"""
22
-
functionstatisticsend
31
+
functionresultsend
23
32
24
33
"""
25
34
issolved(workspace)
26
35
27
36
Return a boolean indicating whether the Krylov method associated with `workspace` has succeeded.
37
+
38
+
For the Krylov methods [`bilqr`](@ref) and [`trilqr`](@ref), you can use `issolved_primal(workspace)`
39
+
and `issolved_dual(workspace)` to separately check whether the solver has converged on the primal or dual system.
28
40
"""
29
41
function issolved end
30
42
31
43
"""
32
-
niterations(workspace)
44
+
elapsed_time(workspace)
33
45
34
-
Return the number of iterations performed by the Krylov method associated with `workspace`.
46
+
Return the elapsed time (in seconds) during the last call to the Krylov method associated with `workspace`.
35
47
"""
36
-
functionniterationsend
48
+
functionelapsed_timeend
37
49
38
50
"""
39
-
Aprod(workspace)
51
+
solution_count(workspace)
40
52
41
-
Return the number of operator-vector products with `A` performed by the Krylov method associated with `workspace`.
53
+
Return the number of outputs of `solution(workspace)`.
42
54
"""
43
-
functionAprodend
55
+
functionsolution_countend
44
56
45
57
"""
46
-
Atprod(workspace)
58
+
iteration_count(workspace)
47
59
48
-
Return the number of operator-vector products with `A'` performed by the Krylov method associated with `workspace`.
49
-
"""
50
-
function Atprod end
60
+
Return the number of iterations performed by the Krylov method associated with `workspace`.
51
61
62
+
The number of iterations alone is not a reliable basis for comparing different Krylov methods,
63
+
since the work performed in each iteration can vary significantly.
64
+
For a fairer performance comparison, use the total number of operator-vector products with `A` and `A'` (see [Aprod_count](@ref) and [Atprod_count](@ref)).
52
65
"""
53
-
Bprod(workspace)
66
+
function iteration_count end
54
67
55
-
Return the number of operator-vector products with `B` performed by the Krylov method associated with `workspace`.
56
68
"""
57
-
function Bprod end
69
+
Aprod_count(workspace)
58
70
59
-
"""
60
-
elapsed_time(workspace)
71
+
Return the number of operator-vector products with `A` performed by the Krylov method associated with `workspace`.
61
72
62
-
Return the elapsed time (in seconds) during the last call to the Krylov method associated with `workspace`.
73
+
This function can also be used to determine the number of operator-vector products with `B` in [`gpmr`](@ref), since it is the same as for `A`.
63
74
"""
64
-
functionelapsed_timeend
75
+
functionAprod_countend
65
76
66
77
"""
67
-
results(workspace)
78
+
Atprod_count(workspace)
68
79
69
-
Return a tuple containing the solution(s) and the statistics associated with `workspace`.
70
-
This allows retrieving the output arguments of an out-of-place method from an in-place method.
71
-
72
-
For example, instead of `x, stats = cg(A, b)`, you can use:
73
-
```julia
74
-
workspace = CgWorkspace(A, b)
75
-
cg!(workspace, A, b)
76
-
x, stats = results(workspace)
77
-
```
80
+
Return the number of operator-vector products with `A'` performed by the Krylov method associated with `workspace`.
78
81
"""
79
-
functionresultsend
82
+
functionAtprod_countend
80
83
81
84
"""
82
85
warm_start!(workspace, x0)
@@ -128,13 +131,10 @@ for (KS, fun, nsol, nA, nAt, warm_start) in [
0 commit comments