getFieldSplitSubKSP() -> segmentation fault for fieldsplit Schur PC

Issue #45 resolved
David created an issue

Hello,

I am setting up a PETSc solver with block preconditioning using fieldsplits via the petsc4py interface. However, the function getFieldSplitSubKSP() fails with a segmentation fault if a Schur preconditioner is selected. With additive preconditioning, no errors. If I set the Schur fieldsplits via command line petsc options instead of using getFieldSplitSubKSP() and the other python functions, it works fine, too.

Code snippet for illustrating the procedure & summary:

            ksp = PETSc.KSP().create()
            ksp.setType(PETSc.KSP.Type.MINRES)

            pc = ksp.getPC()
            pc.setType(PETSc.PC.Type.FIELDSPLIT)
            is0 = PETSc.IS().createGeneral(u_dofs)
            is1 = PETSc.IS().createGeneral(p_dofs)
            pc.setFieldSplitIS(('0', is0), ('1', is1))
            pc.setFieldSplitType(PETSc.PC.CompositeType.SCHUR) 
            pc.setFieldSplitSchurFactType(0)
            Sp = Sp.getSubMatrix(is1, is1)
            pc.setFieldSplitSchurPreType(PETSc.PC.SchurPreType.USER, Sp)

            subksps = pc.getFieldSplitSubKSP()
            subksps[0].setType("preonly")
            subksps[0].getPC().setType("hypre")
            subksps[1].setType("preonly")
            subksps[1].getPC().setType("jacobi")

doesn't work (segmentation fault). With setFieldSplitSchurPreType(0) it works, and by passing the options

               --petsc.fieldsplit_0_ksp_type preonly
               --petsc.fieldsplit_0_pc_type hypre
               --petsc.fieldsplit_1_ksp_type preonly
               --petsc.fieldsplit_1_pc_type jacobi

instead of using the last code block.

Bug or misunderstanding?

Regards, David

Comments (6)

  1. Arthur Besen Soprano

    I think you should have a ksp.setUp() before pc.getFieldSplitSubKSP()

    # ...
    ksp.setUp()
    subksps = pc.getFieldSplitSubKSP()
    # ...
    
  2. Lisandro Dalcin

    @arthursoprano Thanks for the report. This is trivial to add to petsc4py, however maybe the fix is should be done in core PETSc?

    @BarryFSmith @knepley What do you think? Should this fix go to core PETSc?

  3. Log in to comment