getFieldSplitSubKSP() -> segmentation fault for fieldsplit Schur PC
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)
-
-
@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?
-
I don't think we can blindly call KSPSetUp() at this point (because that requires the matrix to have been set). I think we need to require the user to call that routine.
I have added the very useful error message based on Arthur's suggestion in the branch https://bitbucket.org/petsc/petsc/branch/barry/add-errorcheck-pcfieldsplitgetsubksp to prevent people from stumbling over this in the future.
-
reporter Good to know, thanks for clarifying
-
- changed status to resolved
-
Note that I've filed a related report https://bitbucket.org/petsc/petsc/issues/160.
- Log in to comment
I think you should have a
ksp.setUp()
beforepc.getFieldSplitSubKSP()