running solvers on submatrices

Peter Schröder ps at
Sun Nov 25 18:01:51 CST 2007

Following advice from Barry yesterday I am now using IS to subselect 
parts of my matrix. So far so good. I am having problems with the PC 
though on the second round of invoking the solver. Basically the PC 
still has the old number of variables. Here is the basic flow:

KSPCreate( PETSC_COMM_SELF, &ksp );
KSPSetType( ksp, KSPCG );
KSPGetPC( ksp, &m_pc );
PCSetType( pc, PCJACOBI );

Loop over decreasing numbers of variables
  mess with the index set to get the correct columns/rows
  Mat A;
  MatGetSubMatrix( K, is, is, PETSC_DECIDE, MAT_INITIAL_MATRIX, &A );
  KSPSetUp( ksp );
  KSPSolve( ksp, b, x );
  MatDestroy( A );

(Mat K contains the entire matrix from which I am subselecting.) The 
first solve works fine. Then I kill one variable (A is rebuilt from K) 
and now I die in KSPSetUp with the Jacobi precon finding that the 
working array diag is still the old size while mat (A) is the new size 
(one variable less).

What's the proper way to deal with this? I would prefer not to destroy 
and recreate the ksp and pc each time through the loop as this implies 
file I/O to read .petscrc (which I use to control what type of solver is 
used in this section).


More information about the petsc-users mailing list