running solvers on submatrices
Barry Smith
bsmith at mcs.anl.gov
Sun Nov 25 18:12:06 CST 2007
Peter,
The design of PETSc requires destroying the KSP and creating a
new one. A mechanism
to allow resizing would require a major redo of PETSc.
The .petscrc is actually only read ONCE in PetscInitialize() so
there is no extra IO for each KSP creation.
Also, the time to create and destroy the KSP each time is not
noticable; this is what we do in the
active set code.
Barry
On Nov 25, 2007, at 6:01 PM, Peter Schröder wrote:
> 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 );
> KSPSetOperators( ksp, A, A, DIFFERENT_NONZERO_PATTERN);
> 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).
>
> Peter
>
More information about the petsc-users
mailing list