[petsc-dev] various dot products messed up for complex numbers?

Jed Brown jedbrown at mcs.anl.gov
Wed Apr 18 21:24:34 CDT 2012


On Tue, Apr 17, 2012 at 22:28, Jed Brown <jedbrown at mcs.anl.gov> wrote:

> I still don't know if CG is correct, but it should be easy to check.


So I tested with a random SPD matrix

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)

$ ./ex10 -f csmat -pc_type none -ksp_monitor_true_residual
-ksp_converged_reason -ksp_rtol 1e-10 -ksp_type cg
  0 KSP preconditioned resid norm 2.336843772649e+00 true resid norm
2.336843772649e+00 ||r(i)||/||b|| 1.000000000000e+00
  1 KSP preconditioned resid norm 1.288273018515e+00 true resid norm
1.288273018515e+00 ||r(i)||/||b|| 5.512876100632e-01
  2 KSP preconditioned resid norm 1.728603874706e+00 true resid norm
1.728603874706e+00 ||r(i)||/||b|| 7.397173465072e-01
  3 KSP preconditioned resid norm 2.219311079430e+00 true resid norm
2.219311079430e+00 ||r(i)||/||b|| 9.497045140135e-01
  4 KSP preconditioned resid norm 1.417400703557e+00 true resid norm
1.417400703557e+00 ||r(i)||/||b|| 6.065449133342e-01
  5 KSP preconditioned resid norm 2.569214150239e+00 true resid norm
2.569214150239e+00 ||r(i)||/||b|| 1.099437703243e+00
  6 KSP preconditioned resid norm 3.358881724039e+00 true resid norm
3.358881724039e+00 ||r(i)||/||b|| 1.437358270738e+00
  7 KSP preconditioned resid norm 3.716784177439e+00 true resid norm
3.716784177439e+00 ||r(i)||/||b|| 1.590514616741e+00
  8 KSP preconditioned resid norm 2.185304345331e+00 true resid norm
2.185304345331e+00 ||r(i)||/||b|| 9.351520931385e-01
  9 KSP preconditioned resid norm 3.653287110983e+00 true resid norm
3.653287110983e+00 ||r(i)||/||b|| 1.563342468051e+00
 10 KSP preconditioned resid norm 2.935982891703e+01 true resid norm
2.935982891703e+01 ||r(i)||/||b|| 1.256388178819e+01
 11 KSP preconditioned resid norm 9.746366642500e-10 true resid norm
9.747315023720e-10 ||r(i)||/||b|| 4.171145344761e-10
 12 KSP preconditioned resid norm 1.046840786761e-11 true resid norm
1.030180230459e-11 ||r(i)||/||b|| 4.408425768623e-12
Linear solve converged due to CONVERGED_RTOL iterations 12
Number of iterations =  12
Residual norm 1.03018e-11


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.

The same test shows that broyden, lsqr, tcqmr, and cgne are currently
incorrect for complex systems.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20120418/23687178/attachment.html>


More information about the petsc-dev mailing list