<p>You seem to have the solution and right hand side vectors mixed up.</p>
<div class="gmail_quote">On Aug 30, 2012 8:25 AM, "Thomas Witkowski" <<a href="mailto:thomas.witkowski@tu-dresden.de">thomas.witkowski@tu-dresden.de</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <div>Am 28.08.2012 19:57, schrieb Jed Brown:<br>
    </div>
    <blockquote type="cite">
      <div class="gmail_quote">On Tue, Aug 28, 2012 at 12:25 PM, Thomas
        Witkowski <span dir="ltr"><<a href="mailto:thomas.witkowski@tu-dresden.de" target="_blank">thomas.witkowski@tu-dresden.de</a>></span>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
          <div><br>
            <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
                    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.<br>
            </blockquote>
          </div>
          Any idea how to debug this problem? Lets concentrate on the
          gmres/no precon case first.</blockquote>
      </div>
      <br>
      <div>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).</div>
    </blockquote>
    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):<br>
    <br>
    --- ex4-o.c     2012-08-30 15:14:52.852519625 +0200<br>
    +++ ex4.c       2012-08-30 15:16:33.304517903 +0200<br>
    @@ -169,9 +169,22 @@<br>
         ierr = KSPSetOperators(ksp, A, A,
    DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr);<br>
         ierr = MatNullSpaceCreate(PETSC_COMM_WORLD, PETSC_TRUE, 0,
    PETSC_NULL, &nullsp);CHKERRQ(ierr);<br>
         ierr = KSPSetNullSpace(ksp, nullsp);CHKERRQ(ierr);<br>
    +    ierr = MatNullSpaceRemove(nullsp, x, PETSC_NULL);CHKERRQ(ierr);<br>
    +    Vec  c, d;<br>
    +    ierr = VecDuplicate(x, &d);CHKERRQ(ierr);<br>
    +    ierr = VecDuplicate(x, &c);CHKERRQ(ierr);<br>
    +    ierr = VecSet(d, 1.0);CHKERRQ(ierr);<br>
    +    ierr = MatMult(A, d, c);CHKERRQ(ierr);<br>
    +    PetscScalar    dot;<br>
    +    ierr = VecNorm(c, NORM_2, &dot);CHKERRQ(ierr);<br>
    +    ierr = PetscPrintf(PETSC_COMM_WORLD, "Norm of mat-mult = %e\n",
    dot);<br>
    +    ierr = VecDot(x, d, &dot);CHKERRQ(ierr);<br>
    +    ierr = PetscPrintf(PETSC_COMM_WORLD, "Dot product rhs = %e\n",
    dot);<br>
         ierr = MatNullSpaceDestroy(&nullsp);CHKERRQ(ierr);<br>
         ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);<br>
         ierr = KSPSolve(ksp, b, x);CHKERRQ(ierr);<br>
    +    ierr = VecDot(b, d, &dot);CHKERRQ(ierr);<br>
    +    ierr = PetscPrintf(PETSC_COMM_WORLD, "Dot product sol = %e\n",
    dot);<br>
         ierr = VecDestroy(&x);CHKERRQ(ierr);<br>
         ierr = VecDestroy(&b);CHKERRQ(ierr);<br>
         /* Solve physical system:<br>
    <br>
    <br>
    I run this example with the following command:<br>
    <br>
    mpiexec -np 1 ./ex4 -gpu no -cpu -view no -solve
    -ksp_monitor_true_residual -ksp_type gmres -pc_type none<br>
    <br>
    The output is the following:<br>
    <br>
    Norm of mat-mult = 0.000000e+00<br>
    Dot product rhs = 0.000000e+00<br>
      0 KSP preconditioned resid norm 9.544889963521e-01 true resid norm
    1.322454133866e+00 ||r(i)||/||b|| 1.000000000000e+00<br>
      1 KSP preconditioned resid norm 6.183073265542e-01 true resid norm
    1.104599312915e+00 ||r(i)||/||b|| 8.352647435007e-01<br>
      2 KSP preconditioned resid norm 1.770056136651e-01 true resid norm
    9.322910914997e-01 ||r(i)||/||b|| 7.049704542680e-01<br>
      3 KSP preconditioned resid norm 5.212633308436e-02 true resid norm
    9.168166919410e-01 ||r(i)||/||b|| 6.932691792200e-01<br>
      4 KSP preconditioned resid norm 2.714317700314e-02 true resid norm
    9.157360122211e-01 ||r(i)||/||b|| 6.924520017526e-01<br>
      5 KSP preconditioned resid norm 1.718946122098e-03 true resid norm
    9.153352646963e-01 ||r(i)||/||b|| 6.921489685398e-01<br>
      6 KSP preconditioned resid norm 2.794230282044e-16 true resid norm
    9.153336506547e-01 ||r(i)||/||b|| 6.921477480502e-01<br>
    Dot product sol = 2.746001e+00<br>
    <br>
    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.<br>
    <br>
    Thomas<br>
  </div>

</blockquote></div>