<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/4.6.6">
</HEAD>
<BODY>
Mark,<BR>
<BR>
at first I thought the problem was due to my custom PC, but the same happens if I use (see attached files):<BR>
<BR>
-mg_coarse_ksp_type preonly<BR>
-mg_coarse_pc_type gamg<BR>
<BR>
If instead I use a direct solver, say:<BR>
<BR>
-mg_coarse_ksp_type preonly<BR>
-mg_coarse_pc_type lu<BR>
<BR>
the coarse KSP is set correctly.<BR>
<BR>
Michele<BR>
<BR>
<BR>
<BR>
On Sun, 2015-07-19 at 10:42 -0400, Mark Adams wrote:
<BLOCKQUOTE TYPE=CITE>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    On Thu, Jul 16, 2015 at 5:53 PM, Michele Rosso <<A HREF="mailto:mrosso@uci.edu">mrosso@uci.edu</A>> wrote:
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BLOCKQUOTE>
        Hi,<BR>
        <BR>
        I am performing a series of solves inside a loop. The matrix for each solve changes but not enough to justify a rebuilt of the PC at each solve.<BR>
        Therefore I am using  KSPSetReusePreconditioner to avoid rebuilding unless necessary. The solver is CG + MG with a custom  PC at the coarse level.<BR>
        <BR>
    </BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    Ah, OK this is the problem.  The code I just sent gets fooled but your custom PC, probably.
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    We should just remove this paternal code:
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
      PetscBool      preonly,lu,redundant,cholesky,svd<BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
       ...
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
      /*
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
          If coarse solver is not direct method then DO NOT USE preonly
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
      */
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
      ierr = PetscObjectTypeCompare((PetscObject)mglevels[0]->smoothd,KSPPREONLY,&preonly);CHKERRQ(ierr);
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
      if (preonly) {
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
        ierr = PetscObjectTypeCompare((PetscObject)cpc,PCBJACOBI,&bjaclu);CHKERRQ(ierr);
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
        if (bjaclu) {
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
          KSP *k2;
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
          PetscInt ii,first;
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
          ierr = PCBJacobiGetSubKSP(cpc,&ii,&first,&k2);CHKERRQ(ierr);
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
          if (ii==1) {
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
            PC pc2;
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
            ierr = KSPGetPC(k2[0],&pc2);CHKERRQ(ierr);
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
            ierr = PetscObjectTypeCompare((PetscObject)pc2,PCLU,&bjaclu);CHKERRQ(ierr);
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
          }
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
          else bjaclu = PETSC_FALSE;
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
        }
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
        ierr = PetscObjectTypeCompare((PetscObject)cpc,PCLU,&lu);CHKERRQ(ierr);
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
        ierr = PetscObjectTypeCompare((PetscObject)cpc,PCREDUNDANT,&redundant);CHKERRQ(ierr);
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
        ierr = PetscObjectTypeCompare((PetscObject)cpc,PCCHOLESKY,&cholesky);CHKERRQ(ierr);
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
        ierr = PetscObjectTypeCompare((PetscObject)cpc,PCSVD,&svd);CHKERRQ(ierr);
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
        if (!lu && !redundant && !cholesky && !svd && !bjaclu) {
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
          ierr = KSPSetType(mglevels[0]->smoothd,KSPGMRES);CHKERRQ(ierr);
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
        }
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
      }
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
     
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BLOCKQUOTE>
        If KSP is not updated each time, everything works as it is supposed to. <BR>
        When instead I allow the default PETSc  behavior, i.e. updating PC every time the matrix changes, the coarse level KSP , initially set to PREONLY, is changed into GMRES <BR>
        after the first solve. I am not sure where the problem lies (my PC or PETSc), so I would like to have your opinion on this.<BR>
        I attached the ksp_view for the 2 successive solve and the options stack.<BR>
        <BR>
        Thanks for your help,<BR>
        Michel<BR>
        <BR>
        <BR>
        <BR>
        <BR>
    </BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BR>
</BODY>
</HTML>