[petsc-users] Null space correction depends on solver?

Thomas Witkowski thomas.witkowski at tu-dresden.de
Thu Aug 30 08:25:14 CDT 2012


Am 28.08.2012 19:57, schrieb Jed Brown:
> On Tue, Aug 28, 2012 at 12:25 PM, Thomas Witkowski 
> <thomas.witkowski at tu-dresden.de 
> <mailto:thomas.witkowski at tu-dresden.de>> wrote:
>
>
>               GMRES uses left preconditioning by default which forces
>         the null space into the Krylov space at each iteration. FGMRES
>         uses right preconditioning and doesn't  do anything to the
>         null space because it is naturally in the Krylov space (since
>         the result with fgmres contains the constants this is why I
>         suspect the matrix actually doesn't have the null space you
>         think it has). You can try running -ksp_type gmres
>         -ksp_pc_side right      my guess is that you will not get near
>         zero for the dot.
>
>     Any idea how to debug this problem? Lets concentrate on the
>     gmres/no precon case first.
>
>
> Left preconditioning and anything using -pc_type none works correctly. 
> It is only the case of right preconditioning that is incorrect (and 
> needs to be fixed in PETSc).
If everything is fine for left preconditioning, can you please explain 
me what's going wrong in this minimal example. I patched 
src/ksp/ksp/examples/tutorials/ex4.c in the following way (just to make 
some test output):

--- ex4-o.c     2012-08-30 15:14:52.852519625 +0200
+++ ex4.c       2012-08-30 15:16:33.304517903 +0200
@@ -169,9 +169,22 @@
      ierr = KSPSetOperators(ksp, A, A, 
DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr);
      ierr = MatNullSpaceCreate(PETSC_COMM_WORLD, PETSC_TRUE, 0, 
PETSC_NULL, &nullsp);CHKERRQ(ierr);
      ierr = KSPSetNullSpace(ksp, nullsp);CHKERRQ(ierr);
+    ierr = MatNullSpaceRemove(nullsp, x, PETSC_NULL);CHKERRQ(ierr);
+    Vec  c, d;
+    ierr = VecDuplicate(x, &d);CHKERRQ(ierr);
+    ierr = VecDuplicate(x, &c);CHKERRQ(ierr);
+    ierr = VecSet(d, 1.0);CHKERRQ(ierr);
+    ierr = MatMult(A, d, c);CHKERRQ(ierr);
+    PetscScalar    dot;
+    ierr = VecNorm(c, NORM_2, &dot);CHKERRQ(ierr);
+    ierr = PetscPrintf(PETSC_COMM_WORLD, "Norm of mat-mult = %e\n", dot);
+    ierr = VecDot(x, d, &dot);CHKERRQ(ierr);
+    ierr = PetscPrintf(PETSC_COMM_WORLD, "Dot product rhs = %e\n", dot);
      ierr = MatNullSpaceDestroy(&nullsp);CHKERRQ(ierr);
      ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);
      ierr = KSPSolve(ksp, b, x);CHKERRQ(ierr);
+    ierr = VecDot(b, d, &dot);CHKERRQ(ierr);
+    ierr = PetscPrintf(PETSC_COMM_WORLD, "Dot product sol = %e\n", dot);
      ierr = VecDestroy(&x);CHKERRQ(ierr);
      ierr = VecDestroy(&b);CHKERRQ(ierr);
      /* Solve physical system:


I run this example with the following command:

mpiexec -np 1 ./ex4 -gpu no -cpu -view no -solve 
-ksp_monitor_true_residual -ksp_type gmres -pc_type none

The output is the following:

Norm of mat-mult = 0.000000e+00
Dot product rhs = 0.000000e+00
   0 KSP preconditioned resid norm 9.544889963521e-01 true resid norm 
1.322454133866e+00 ||r(i)||/||b|| 1.000000000000e+00
   1 KSP preconditioned resid norm 6.183073265542e-01 true resid norm 
1.104599312915e+00 ||r(i)||/||b|| 8.352647435007e-01
   2 KSP preconditioned resid norm 1.770056136651e-01 true resid norm 
9.322910914997e-01 ||r(i)||/||b|| 7.049704542680e-01
   3 KSP preconditioned resid norm 5.212633308436e-02 true resid norm 
9.168166919410e-01 ||r(i)||/||b|| 6.932691792200e-01
   4 KSP preconditioned resid norm 2.714317700314e-02 true resid norm 
9.157360122211e-01 ||r(i)||/||b|| 6.924520017526e-01
   5 KSP preconditioned resid norm 1.718946122098e-03 true resid norm 
9.153352646963e-01 ||r(i)||/||b|| 6.921489685398e-01
   6 KSP preconditioned resid norm 2.794230282044e-16 true resid norm 
9.153336506547e-01 ||r(i)||/||b|| 6.921477480502e-01
Dot product sol = 2.746001e+00

As you see, the constant vector is a member of the nullspace (and it 
should span it), the right hand side is orthogonal to the null space, 
but not the solution vector. Also the solver does not converge in the 
true residual norm.

Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120830/6cddb4d6/attachment.html>


More information about the petsc-users mailing list