<div class="gmail_quote">On Tue, Apr 17, 2012 at 22:28, Jed Brown <span dir="ltr"><<a href="mailto:jedbrown@mcs.anl.gov">jedbrown@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 I still don't know if CG is correct, but it should be easy to check.</blockquote></div><br><div>So I tested with a random SPD matrix</div><div><br></div><div>octave:1> m = 10; A = rand(m) + 1i*rand(m); B = sparse(A'*A); b = rand(m,1) + 1i*rand(m,1); PetscBinaryWrite('csmat',B,b)</div>
<div><br></div><div><div>$ ./ex10 -f csmat -pc_type none -ksp_monitor_true_residual -ksp_converged_reason -ksp_rtol 1e-10 -ksp_type cg</div><div>  0 KSP preconditioned resid norm 2.336843772649e+00 true resid norm 2.336843772649e+00 ||r(i)||/||b|| 1.000000000000e+00</div>
<div>  1 KSP preconditioned resid norm 1.288273018515e+00 true resid norm 1.288273018515e+00 ||r(i)||/||b|| 5.512876100632e-01</div><div>  2 KSP preconditioned resid norm 1.728603874706e+00 true resid norm 1.728603874706e+00 ||r(i)||/||b|| 7.397173465072e-01</div>
<div>  3 KSP preconditioned resid norm 2.219311079430e+00 true resid norm 2.219311079430e+00 ||r(i)||/||b|| 9.497045140135e-01</div><div>  4 KSP preconditioned resid norm 1.417400703557e+00 true resid norm 1.417400703557e+00 ||r(i)||/||b|| 6.065449133342e-01</div>
<div>  5 KSP preconditioned resid norm 2.569214150239e+00 true resid norm 2.569214150239e+00 ||r(i)||/||b|| 1.099437703243e+00</div><div>  6 KSP preconditioned resid norm 3.358881724039e+00 true resid norm 3.358881724039e+00 ||r(i)||/||b|| 1.437358270738e+00</div>
<div>  7 KSP preconditioned resid norm 3.716784177439e+00 true resid norm 3.716784177439e+00 ||r(i)||/||b|| 1.590514616741e+00</div><div>  8 KSP preconditioned resid norm 2.185304345331e+00 true resid norm 2.185304345331e+00 ||r(i)||/||b|| 9.351520931385e-01</div>
<div>  9 KSP preconditioned resid norm 3.653287110983e+00 true resid norm 3.653287110983e+00 ||r(i)||/||b|| 1.563342468051e+00</div><div> 10 KSP preconditioned resid norm 2.935982891703e+01 true resid norm 2.935982891703e+01 ||r(i)||/||b|| 1.256388178819e+01</div>
<div> 11 KSP preconditioned resid norm 9.746366642500e-10 true resid norm 9.747315023720e-10 ||r(i)||/||b|| 4.171145344761e-10</div><div> 12 KSP preconditioned resid norm 1.046840786761e-11 true resid norm 1.030180230459e-11 ||r(i)||/||b|| 4.408425768623e-12</div>
<div>Linear solve converged due to CONVERGED_RTOL iterations 12</div><div>Number of iterations =  12</div><div>Residual norm 1.03018e-11</div></div><div><br></div><div><br></div><div>This looks okay. Interestingly, flipping the dot products produces essentially the same convergence behavior, though it is not identical. I guess CG has enough symmetry that it doesn't matter which way you conjugate.</div>
<div><br></div><div>The same test shows that broyden, lsqr, tcqmr, and cgne are currently incorrect for complex systems.</div>