[petsc-users] Problem with KSPGetPC within FieldSplit context
Lucia Barandiaran
lucia.barandiaran at upc.edu
Tue Mar 24 13:30:46 CDT 2026
Dear PETSc community,
We recently updated PETSc libraries and came across with a problem with
FieldSplit preconditioning (our code is implemented in Fortran 90).
In the older version, when calling PCFieldSplitGetSubKSP we declared the
subksp array as KSP and it worked perfectly. However, now we must
declare it as a Fortran pointer and allocate it before
calling PCFieldSplitGetSubKSP otherwise the code won't compile...
With the new modification, that part of the code is the following:
****Variable declarations
PetscInt :: n_splits_retrieved
IS :: IS_field(max_field)
KSP, pointer :: subksp_array(:)
PC :: subpc(max_field)
INTEGER(iwp) :: nfield, ifield
**** FieldSplit Part ****
! Allocate Fortran array to hold the KSP contexts
ALLOCATE(subksp_array(n_splits_retrieved))
! Second call to get the actual KSP contexts
CALL PCFieldSplitGetSubKSP(solver%pc, n_splits_retrieved, &
subksp_array, ierr)
IF (n_splits_retrieved >= 2) THEN
DO ifield = 1, n_splits_retrieved
! Configure the KSP for the velocity block (field 0)
CALL KSPGetPC(subksp_array(ifield), subpc(ifield), ierr)
CALL KSPSetType(subksp_array(ifield), KSPGMRES, ierr)
CALL PCSetType(subpc(ifield), PCJACOBI, ierr)
! Allows runtime options for sub-KSP
CALL KSPSetFromOptions(subksp_array(ifield), ierr)
! Choose a viewer (stdout for example)
! viewer = PETSC_VIEWER_STDOUT_WORLD
! CALL PCView(subpc(ifield),viewer,ierr)
END DO
END IF
When debugging the fortran code we observed that it stops with an error
when calling KSPGetPC and we can't figure out what are we doing
wrong... Maybe we need an interface when calling that function?
Thanks very much for your time,
Sincerely,
Lucía Barandiarán
Scientific software developer - Dracsys
Collaborator at MECMAT group - Universitat Politècnica de Catalunya (UPC)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20260324/b927fb9c/attachment.html>
More information about the petsc-users
mailing list