JuliaSmoothOptimizers / Krylov.jl

A Julia Basket of Hand-Picked Krylov Methods
Other
349 stars 51 forks source link

GMRES Convergence Without Meeting atol/rtol #774

Closed alexQueue closed 1 year ago

alexQueue commented 1 year ago

I've been banging my head against this issue for a few days now.

I have a system, and am setting my tolerances to 1e-9, and my solution converges "good enough given atol and rtol", however I get a much worse residual than 1e-9 and I'm trying to understand why. I assume there is an internal residual measure that is used as a stopping criterion that is different from the one that is output. I've run it in a number of configurations and get the same behavior (using atol, using rtol, using both, using a preconditioner, not using a preconditioner, measuring residual directly via a callback (not yet working as expected):

Here's an example output:

TOL=1e-9
x, stats = Krylov.gmres(MA, Mrhs, restart=false, atol=TOL, rtol=TOL, itmax=50, verbose=1, history=true)

GMRES: system of size 350679
 pass      k     ‖rₖ‖   hₖ₊₁.ₖ  timer
    0      0  1.9e+04  ✗ ✗ ✗ ✗  0.36s
    1      1  6.4e+03  3.8e-01  15.29s
    1      2  1.6e+03  2.6e-01  29.46s
    1      3  8.2e+02  5.8e-01  42.66s
    1      4  3.4e+02  3.9e-01  55.64s
    1      5  9.3e+01  3.3e-01  68.45s
    1      6  4.4e+01  4.8e-01  81.49s
    1      7  1.4e+01  4.1e-01  95.12s
    1      8  6.1e+00  4.4e-01  108.67s
    1      9  1.9e+00  3.9e-01  121.53s
    1     10  9.8e-01  6.0e-01  134.34s
    1     11  4.0e-01  4.5e-01  147.18s
    1     12  1.8e-01  5.1e-01  160.38s
    1     13  9.2e-02  5.5e-01  173.98s
    1     14  4.7e-02  6.1e-01  187.62s
    1     15  2.4e-02  5.2e-01  200.45s
    1     16  1.5e-02  7.2e-01  213.24s
    1     17  8.3e-03  5.8e-01  226.10s
    1     18  4.6e-03  6.1e-01  239.49s
    1     19  2.3e-03  5.7e-01  253.11s
    1     20  1.3e-03  5.8e-01  266.67s
    1     21  6.3e-04  5.9e-01  279.63s
    1     22  3.1e-04  5.0e-01  292.59s
    1     23  1.8e-04  6.4e-01  305.64s

stats
SimpleStats
 niter: 23
 solved: true
 inconsistent: false
 residuals: [ 1.9e+04  6.4e+03  1.6e+03 ...  6.3e-04  3.1e-04  1.8e-04 ]
 Aresiduals: []
 κ₂(A): []
 timer: 305.64s
 status: solution good enough given atol and rtol

Julia 1.7 (I'm unable to update on this server), Krylov.jl 0.9.1

Thanks for any help!

amontoison commented 1 year ago

Hi @alexQueue! GMRES should stop when ||r_k|| <= atol + rtol * ||r_0||. The initial residual r_0 is b. You can set rtol=0.0 in your case. I still don't understand why GMRES stops before that ||r_k|| <= 1.9 * 1e-5 is reached. Can you save and share your linear system with MatrixMarket.jl?

amontoison commented 1 year ago

@alexQueue Can you give me an update about your issue?

alexQueue commented 1 year ago

@amontoison Ah I was sure I replied. You were correct. Using rtol=0.0 fixed it. It seems like I was misunderstanding the meaning of rtol.