[petsc-users] Use block Jacobi preconditioner with SNES

Jed Brown jed at jedbrown.org
Fri Aug 24 17:32:14 CDT 2018


Ali Reza Khaz'ali <arkhazali at cc.iut.ac.ir> writes:

> Hi,
>
> I am trying to use block Jacobi preconditioner in SNES (SNESNEWTONLS). 
> However, PCBJacobiGetSubKSP function returns an error stating "Object is 
> in wrong state, Must call KSPSetUp() or PCSetUp() first". When I add 
> KSPSetUp, I got and error from them as: "Must call 
> DMShellSetGlobalVector() or DMShellSetCreateGlobalVector()", and if 
> PCSetUp is added, "Object is in wrong state, Matrix must be set first" 
> error is printed.

We'd need the entire trace, but this is a run-time option

  -snes_rtol 1e-1  # Really? Then why solve KSP that much more accurately?
  -ksp_rtol 1e-3
  -pc_type bjacobi -sub_pc_type lu -sub_pc_factor_mat_solver_type mkl_pardiso

optionally setting the number of blocks (it's uncommon to not want the
default)

  -pc_bjacobi_blocks N

> Below is a part of my code. It is run serially. Any help is much 
> appreciated.
>
>      ierr = SNESGetKSP(snes, &Petsc_ksp);
>      CHKERRQ(ierr);
>      ierr = KSPGetPC(Petsc_ksp, &Petsc_pc);
>      CHKERRQ(ierr);
>      ierr = KSPSetTolerances(Petsc_ksp, 1.e-3, 1e-3, PETSC_DEFAULT, 20000);
>      CHKERRQ(ierr);
>      ierr = SNESSetTolerances(snes, 1e-1, 1e-1, 1e-1, 2000, 2000);
>      CHKERRQ(ierr);
>      ierr = SNESSetType(snes, SNESNEWTONLS);
>      CHKERRQ(ierr);
>      ierr = KSPSetType(Petsc_ksp, KSPGMRES);
>      CHKERRQ(ierr);
>      ierr = PCSetType(Petsc_pc, PCBJACOBI);
>      CHKERRQ(ierr);
>      ierr = PCSetType(Petsc_pc, PCBJACOBI);
>      CHKERRQ(ierr);
>      ierr = PCBJacobiSetTotalBlocks(Petsc_pc, 2*Nx*Ny*Nz, SadeqSize);
>      CHKERRQ(ierr);
>
>      SNESSetUp(snes);
>      CHKERRQ(ierr);
>      ierr = PCBJacobiGetSubKSP(Petsc_pc, &nLocal, &Firstly, &subKSP);
>      CHKERRQ(ierr);
>
>      for (i = 0; i < nLocal; i++) {
>          ierr = KSPGetPC(subKSP[i], &SubPc);
>          CHKERRQ(ierr);
>          ierr = PCSetType(SubPc, PCLU);
>          CHKERRQ(ierr);
>          ierr = PCFactorSetMatSolverPackage(SubPc, "mkl_pardiso");
>          CHKERRQ(ierr);
>          ierr = KSPSetType(subKSP[i], KSPPREONLY);
>          CHKERRQ(ierr);
>          ierr = KSPSetTolerances(subKSP[i], 1.e-6, PETSC_DEFAULT, 
> PETSC_DEFAULT, PETSC_DEFAULT);
>          CHKERRQ(ierr);
>      }
>      ierr = SNESSolve(snes, NULL, Petsc_X);
>      CHKERRQ(ierr);
>
>
>
> -- 
> Ali Reza Khaz’ali
> Assistant Professor of Petroleum Engineering,
> Department of Chemical Engineering
> Isfahan University of Technology
> Isfahan, Iran


More information about the petsc-users mailing list