[petsc-users] pcsetup

Alex Fleeter luis.saturday at gmail.com
Tue Jul 21 17:11:22 CDT 2020


Hi:

I guess I could rephrase my question like this. I am using MATNEST.

When I updated the matrix, I did assembly only for the sub-matrices. Then
when I call the KSP solver, I can see that the pcsetup was called only in
the first time the solver gets called.

I tried to add MatAssembly for the big nest matrix as a second test. Then,
when I called my solver, I could see that the pcsetup gets called.

I assume that there is a state flag in the MatNest object that tells the
solver if it needs to update the preconditioner. After an assembly routine
gets called, this flag will be activated. Could you confirm that?

The problem is that I am trying to implement a shell preconditioner, which
gets the sub-matrices in the setup routine like the following
  MatNestGetSubMat(A, 0, 0, &newctx->submat[0]);
  MatNestGetSubMat(A, 0, 1, &newctx->submat[1]);
  MatNestGetSubMat(A, 1, 0, &newctx->submat[2]);
  MatNestGetSubMat(A, 1, 1, &newctx->submat[3]);

  KSPSetOperators(newctx->upper, newctx->submat[0], newctx->submat[0]);
  KSPSetOperators(newctx->lower, newctx->submat[3], newctx->submat[3]);

In the Apply stage, I do

PetscErrorCode blockpc_apply(PC pc, Vec x, Vec y)
{
  std::cout<<"APPLY PC\n";
  blockpc * newctx;
  PCShellGetContext(pc,(void**)&newctx);

  Vec x_v, x_p, y_v, y_p;
  VecGetSubVector(x, newctx->is[0], &x_v);
  VecGetSubVector(x, newctx->is[1], &x_p);
  VecGetSubVector(y, newctx->is[0], &y_v);
  VecGetSubVector(y, newctx->is[1], &y_p);

  KSPSolve( newctx -> upper, x_v, y_v );
  KSPSolve( newctx -> lower, x_p, y_p );

  VecRestoreSubVector(x, newctx->is[0], &x_v);
  VecRestoreSubVector(x, newctx->is[1], &x_p);
  VecRestoreSubVector(y, newctx->is[0], &y_v);
  VecRestoreSubVector(y, newctx->is[1], &y_p);

  return 0;
}

I want to know if I shall call an assembly for the big nest matrix so that
the pcsetup can be called everytime the solver is dealing with a new matrix.

Thanks,






On Tue, Jul 21, 2020 at 12:44 PM Alex Fleeter <luis.saturday at gmail.com>
wrote:

> Hi:
>
> I want to ask under what circumstance will trigger a call for pc setup.
>
> I call KSPSolve to solve with the same Mat object with different entry
> values each time. I can see that the pc setup is only called at the
> beginning of the first solve.
>
> I tried to read the implementation, but quickly get lost...
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200721/c8b485bb/attachment.html>


More information about the petsc-users mailing list