Hi Barry: Thanks you for your suggestions. Now both sequential and parallel cases work when I use CG.
Shao-Ching On Fri, Aug 01, 2008 at 08:56:23PM -0500, Barry Smith wrote: > > It is not the null space that is the problem. > > You are right to try the shift but > 1) first run on one process using -pc_type icc -ksp_type cg - > pc_factor_shift_positive_definite > this will keep increasing the shift until it produces a positive- > definite preconditioner. > > Run also with -ksp_view to confirm that it is using all the options you > provided. (you can run with -help to > see the option names) > > 2) If you have the sequential converging then use -pc_type bjacobi - > sub_pc_type icc -pc_factor_shift_positive_definite > > Barry > > On Aug 1, 2008, at 7:52 PM, Shao-Ching Huang wrote: > >> Hi, >> >> I am trying to use CG to solve a singular systems (i.e. Poisson >> equation with periodic conditions on all boundaries). >> >> The code works when I use GMRES, but it diverges when I switch CG. >> >> Since the null space is a constant vector, in the code I have: >> >> KSP ksp; >> MatNullSpace nullspace; >> ... >> MatNullSpaceCreate(MPI_COMM_WORLD, PETSC_TRUE, 0, PETSC_NULL, >> &nullspace); >> KSPSetNullSpace(ksp, nullspace); >> MatNullSpaceRemove(nullspace, f->p_rhs, PETSC_NULL); >> >> KSPSetFromOptions(ksp); >> KSPSetUp(ksp); >> KSPSolve(ksp, f->p_rhs, f->phi); >> >> [f->p_rhs is the RHS vector. f->phi is the solution vector.] >> >> When I use "-ksp_type gmres", it converges (shown by -ksp_monitor). >> >> However, when I switch to "-ksp_type cg", it diverges. >> In this case (cg), "-ksp_converged_reason" says: >> >> Linear solve did not converge due to DIVERGED_INDEFINITE_PC >> iterations 1 >> >> I also try adding "-sub_pc_factor_shift_nonzero 0.0000000001" but the >> CG case still fails. >> >> Am I missing some step in handling the null space when using CG? >> >> Thanks, >> >> Shao-Ching Huang >> >>
