Closed haampie closed 7 years ago
The same is basically true for cg.jl
. Test with a sparse matrix of size 10.000, converging in 194 iterations:
Current
BenchmarkTools.Trial:
memory estimate: 15.30 MiB
allocs estimate: 1026
--------------
minimum time: 562.136 ms (0.00% GC)
median time: 575.174 ms (0.46% GC)
mean time: 576.091 ms (0.32% GC)
maximum time: 592.723 ms (0.53% GC)
--------------
samples: 9
evals/sample: 1
Improved
BenchmarkTools.Trial:
memory estimate: 312.97 KiB
allocs estimate: 11
--------------
minimum time: 552.034 ms (0.00% GC)
median time: 565.630 ms (0.00% GC)
mean time: 562.870 ms (0.00% GC)
maximum time: 572.558 ms (0.00% GC)
--------------
samples: 9
evals/sample: 1
BenchmarkTools.TrialJudgement:
time: -1.66% => invariant (5.00% tolerance)
memory: -98.00% => improvement (1.00% tolerance)
Hope to resolve this soon.
It's not showing a timing change probably because the test problem is small. With a larger test problem, memory differences this large would lead to huge timing differences.
The current implementation of GMRES allocates too much memory. We should be able to guarantee that memory usage is fixed as
O(restart * n)
, wheren
is the height of the matrix.As a reference, I've coded up an improved GMRES version. The main difference is that it pre-allocates the
V
matrix and reuses that without throwing vectors away. Its implementation is super basic, it does not have preconditioners and does not factorize the Hessenberg matrix.Then I benchmarked against the version of IterativeSolvers.jl. GMRES does not converge for the specific matrix, so that you can compare results for a large number of iterations.
For
n = 5000
and1500
iterations with restarts after15
iterations, this is what I get:IterativeSolvers.jl
Improved version
So, memory usage is reduced a lot, just like the number of allocations. Maybe it can be improved upon.
Surprisingly it is faster as well... Maybe factorizing the Hessenberg matrix on the go is slower than a simple \.
With a smaller matrix I got some more samples (~10000):
TL;DR:
V
matrix and use indices to reduce the number of allocations