Actual source code: agmres.c

      2: #define PETSCKSP_DLL

      4: #include <../src/ksp/ksp/impls/gmres/agmres/agmresimpl.h>

      6: #define AGMRES_DEFAULT_MAXK 30
      7: #define AGMRES_DELTA_DIRECTIONS 10
      8: static PetscErrorCode KSPAGMRESBuildSoln(KSP,PetscInt);
      9: static PetscErrorCode KSPAGMRESBuildBasis(KSP);
     10: static PetscErrorCode KSPAGMRESBuildHessenberg(KSP);

     12: PetscLogEvent KSP_AGMRESComputeDeflationData, KSP_AGMRESBuildBasis, KSP_AGMRESComputeShifts, KSP_AGMRESRoddec;

     14: extern PetscErrorCode KSPSetUp_DGMRES(KSP);
     15: extern PetscErrorCode KSPBuildSolution_DGMRES(KSP,Vec,Vec*);
     16: extern PetscErrorCode KSPSolve_DGMRES(KSP);
     17: extern PetscErrorCode KSPDGMRESComputeDeflationData_DGMRES(KSP,PetscInt*);
     18: extern PetscErrorCode KSPDGMRESComputeSchurForm_DGMRES(KSP,PetscInt*);
     19: extern PetscErrorCode KSPDGMRESApplyDeflation_DGMRES(KSP,Vec,Vec);
     20: extern PetscErrorCode KSPDestroy_DGMRES(KSP);
     21: extern PetscErrorCode KSPSetFromOptions_DGMRES(PetscOptionItems *,KSP);
     22: extern PetscErrorCode KSPDGMRESSetEigen_DGMRES(KSP,PetscInt);
     23: /*
     24:    This function allocates  data for the Newton basis GMRES implementation.
     25:    Note that most data are allocated in KSPSetUp_DGMRES and KSPSetUp_GMRES, including the space for the basis vectors, the various Hessenberg matrices and the Givens rotations coefficients

     27: */
     28: static PetscErrorCode KSPSetUp_AGMRES(KSP ksp)
     29: {
     30:   PetscErrorCode  ierr;
     31:   PetscInt        hes;
     32:   PetscInt        nloc;
     33:   KSP_AGMRES      *agmres = (KSP_AGMRES*)ksp->data;
     34:   PetscInt        neig    = agmres->neig;
     35:   const PetscInt  max_k   = agmres->max_k;
     36:   PetscInt        N       = MAXKSPSIZE;
     37:   PetscInt        lwork   = PetscMax(8 * N + 16, 4 * neig * (N - neig));

     40:   if (ksp->pc_side == PC_SYMMETRIC) SETERRQ(PetscObjectComm((PetscObject)ksp),PETSC_ERR_SUP,"no symmetric preconditioning for KSPAGMRES");
     41:   N     = MAXKSPSIZE;
     42:   /* Preallocate space during the call to KSPSetup_GMRES for the Krylov basis */
     43:   agmres->q_preallocate = PETSC_TRUE; /* No allocation on the fly */
     44:   /* Preallocate space to compute later the eigenvalues in GMRES */
     45:   ksp->calc_sings = PETSC_TRUE;
     46:   agmres->max_k   = N; /* Set the augmented size to be allocated in KSPSetup_GMRES */
     47:   KSPSetUp_DGMRES(ksp);
     48:   agmres->max_k   = max_k;
     49:   hes             = (N + 1) * (N + 1);

     51:   /* Data for the Newton basis GMRES */
     52:   PetscCalloc4(max_k,&agmres->Rshift,max_k,&agmres->Ishift,hes,&agmres->Rloc,(N+1)*4,&agmres->wbufptr);
     53:   PetscMalloc3(N+1,&agmres->tau,lwork,&agmres->work,N+1,&agmres->nrs);
     54:   PetscCalloc4(N+1,&agmres->Scale,N+1,&agmres->sgn,N+1,&agmres->tloc,N+1,&agmres->temp);

     56:   /* Allocate space for the vectors in the orthogonalized basis*/
     57:   VecGetLocalSize(agmres->vecs[0], &nloc);
     58:   PetscMalloc1(nloc*(N+1), &agmres->Qloc);

     60:   /* Init the ring of processors for the roddec orthogonalization */
     61:   KSPAGMRESRoddecInitNeighboor(ksp);

     63:   if (agmres->neig < 1) return(0);

     65:   /* Allocate space for the deflation */
     66:   PetscMalloc1(N, &agmres->select);
     67:   VecDuplicateVecs(VEC_V(0), N, &agmres->TmpU);
     68:   PetscMalloc2(N*N, &agmres->MatEigL, N*N, &agmres->MatEigR);
     69:   /*  PetscMalloc6(N*N, &agmres->Q, N*N, &agmres->Z, N, &agmres->wr, N, &agmres->wi, N, &agmres->beta, N, &agmres->modul); */
     70:   PetscMalloc3(N*N, &agmres->Q, N*N, &agmres->Z, N, &agmres->beta);
     71:   PetscMalloc2((N+1),&agmres->perm,(2*neig*N),&agmres->iwork);
     72:   return(0);
     73: }

     75: /*
     76:     Returns the current solution from the private data structure of AGMRES back to ptr.
     77: */
     78: static PetscErrorCode KSPBuildSolution_AGMRES(KSP ksp,Vec ptr, Vec *result)
     79: {
     80:   KSP_AGMRES     *agmres = (KSP_AGMRES*)ksp->data;

     84:   if (!ptr) {
     85:     if (!agmres->sol_temp) {
     86:       VecDuplicate(ksp->vec_sol,&agmres->sol_temp);
     87:       VecCopy(ksp->vec_sol,agmres->sol_temp);
     88:       PetscLogObjectParent((PetscObject)ksp,(PetscObject)agmres->sol_temp);
     89:     }
     90:     ptr = agmres->sol_temp;
     91:   } else {
     92:     VecCopy(ksp->vec_sol, ptr);
     93:   }
     94:   if (result) *result = ptr;
     95:   return(0);
     96: }

     98: /* Computes the shifts  needed to generate stable basis vectors (through the Newton polynomials)
     99:    At input, the operators (matrix and preconditioners) are used to create a new GMRES KSP.
    100:    One cycle of GMRES with the Arnoldi process is performed and the eigenvalues of the induced Hessenberg matrix (the Ritz values) are computed.
    101:    NOTE: This function is not currently used; the next function is rather used when  the eigenvectors are needed next to augment the basis
    102: */
    103: PetscErrorCode KSPComputeShifts_GMRES(KSP ksp)
    104: {
    105:   PetscErrorCode  ierr;
    106:   KSP_AGMRES      *agmres = (KSP_AGMRES*)(ksp->data);
    107:   KSP             kspgmres;
    108:   Mat             Amat, Pmat;
    109:   const PetscInt  max_k = agmres->max_k;
    110:   PC              pc;
    111:   PetscInt        m;
    112:   PetscScalar     *Rshift, *Ishift;
    113:   PetscBool       flg;

    116:   /* Perform one cycle of classical GMRES (with the Arnoldi process) to get the Hessenberg matrix
    117:    We assume here that the ksp is AGMRES and that the operators for the
    118:    linear system have been set in this ksp */
    119:   KSPCreate(PetscObjectComm((PetscObject)ksp), &kspgmres);
    120:   if (!ksp->pc) { KSPGetPC(ksp,&ksp->pc); }
    121:   PCGetOperators(ksp->pc, &Amat, &Pmat);
    122:   KSPSetOperators(kspgmres, Amat, Pmat);
    123:   KSPSetFromOptions(kspgmres);
    124:   PetscOptionsHasName(NULL,((PetscObject)ksp)->prefix, "-ksp_view", &flg);
    125:   if (flg) { PetscOptionsClearValue(NULL,"-ksp_view"); }
    126:   KSPSetType(kspgmres, KSPGMRES);
    127:   KSPGMRESSetRestart(kspgmres, max_k);
    128:   KSPGetPC(ksp, &pc);
    129:   KSPSetPC(kspgmres, pc);
    130:   /* Copy common options */
    131:   kspgmres->pc_side = ksp->pc_side;
    132:   /* Setup KSP context */
    133:   KSPSetComputeEigenvalues(kspgmres, PETSC_TRUE);
    134:   KSPSetUp(kspgmres);

    136:   kspgmres->max_it = max_k; /* Restrict the maximum number of iterations to one cycle of GMRES */
    137:   kspgmres->rtol   = ksp->rtol;

    139:   KSPSolve(kspgmres, ksp->vec_rhs, ksp->vec_sol);

    141:   ksp->guess_zero = PETSC_FALSE;
    142:   ksp->rnorm      = kspgmres->rnorm;
    143:   ksp->its        = kspgmres->its;
    144:   if (kspgmres->reason == KSP_CONVERGED_RTOL) {
    145:     ksp->reason = KSP_CONVERGED_RTOL;
    146:     return(0);
    147:   } else ksp->reason = KSP_CONVERGED_ITERATING;
    148:   /* Now, compute the Shifts values */
    149:   PetscMalloc2(max_k,&Rshift,max_k,&Ishift);
    150:   KSPComputeEigenvalues(kspgmres, max_k, Rshift, Ishift, &m);
    151:   if (m < max_k) SETERRQ(PetscObjectComm((PetscObject)ksp),PETSC_ERR_PLIB, "Unable to compute the Shifts for the Newton basis");
    152:   else {
    153:     KSPAGMRESLejaOrdering(Rshift, Ishift, agmres->Rshift, agmres->Ishift, max_k);

    155:     agmres->HasShifts = PETSC_TRUE;
    156:   }
    157:   /* Restore KSP view options */
    158:   if (flg) { PetscOptionsSetValue(NULL,"-ksp_view", ""); }
    159:   return(0);
    160: }

    162: /* Computes the shift values (Ritz values) needed to generate stable basis vectors
    163:    One cycle of DGMRES is performed to find the eigenvalues. The same data structures are used since AGMRES extends DGMRES
    164:    Note that when the basis is  to be augmented, then this function computes the harmonic Ritz vectors from this first cycle.
    165:    Input :
    166:     - The operators (matrix, preconditioners and right hand side) are  normally required.
    167:     - max_k : the size of the (non augmented) basis.
    168:     - neig: The number of eigenvectors to augment, if deflation is needed
    169:    Output :
    170:     - The shifts as complex pair of arrays in wr and wi (size max_k).
    171:     - The harmonic Ritz vectors (agmres->U) if deflation is needed.
    172: */
    173: static PetscErrorCode KSPComputeShifts_DGMRES(KSP ksp)
    174: {
    176:   KSP_AGMRES     *agmres = (KSP_AGMRES*)(ksp->data);
    177:   PetscInt       max_k   = agmres->max_k; /* size of the (non augmented) Krylov subspace */
    178:   PetscInt       Neig    = 0;
    179:   const PetscInt max_it  = ksp->max_it;
    180:   PetscBool      flg;

    182:   /* Perform one cycle of dgmres to find the eigenvalues and compute the first approximations of the eigenvectors */

    185:   PetscLogEventBegin(KSP_AGMRESComputeShifts, ksp, 0,0,0);
    186:   /* Send the size of the augmented basis to DGMRES */
    187:   ksp->max_it             = max_k; /* set this to have DGMRES performing only one cycle */
    188:   ksp->ops->buildsolution = KSPBuildSolution_DGMRES;
    189:   KSPSolve_DGMRES(ksp);
    190:   ksp->guess_zero         = PETSC_FALSE;
    191:   if (ksp->reason == KSP_CONVERGED_RTOL) {
    192:     PetscLogEventEnd(KSP_AGMRESComputeShifts, ksp, 0,0,0);
    193:     return(0);
    194:   } else ksp->reason = KSP_CONVERGED_ITERATING;

    196:   if ((agmres->r == 0) && (agmres->neig > 0)) {  /* Compute the eigenvalues for the shifts and the eigenvectors (to augment the Newton basis) */
    197:     agmres->HasSchur = PETSC_FALSE;
    198:     KSPDGMRESComputeDeflationData_DGMRES (ksp, &Neig);CHKERRQ (ierr);
    199:     Neig             = max_k;
    200:   } else { /* From DGMRES, compute only the eigenvalues needed as Shifts for the Newton Basis */
    201:      KSPDGMRESComputeSchurForm_DGMRES(ksp, &Neig);
    202:   }

    204:   /* It may happen that the Ritz values from one cycle of GMRES are not accurate enough to provide a good stability. In this case, another cycle of GMRES is performed.  The two sets of values thus generated are sorted and the most accurate are kept as shifts */
    205:   PetscOptionsHasName(NULL,NULL, "-ksp_agmres_ImproveShifts", &flg);
    206:   if (!flg) {
    207:     KSPAGMRESLejaOrdering(agmres->wr, agmres->wi, agmres->Rshift, agmres->Ishift, max_k);
    208:   } else { /* Perform another cycle of DGMRES to find another set of eigenvalues */
    209:     PetscInt    i;
    210:     PetscScalar *wr, *wi,*Rshift, *Ishift;
    211:     PetscMalloc4(2*max_k, &wr, 2*max_k, &wi, 2*max_k, &Rshift, 2*max_k, &Ishift);
    212:     for (i = 0; i < max_k; i++) {
    213:       wr[i] = agmres->wr[i];
    214:       wi[i] = agmres->wi[i];
    215:     }

    217:     KSPSolve_DGMRES(ksp);

    219:     ksp->guess_zero = PETSC_FALSE;
    220:     if (ksp->reason == KSP_CONVERGED_RTOL) return(0);
    221:     else ksp->reason = KSP_CONVERGED_ITERATING;
    222:     if (agmres->neig > 0) { /* Compute the eigenvalues for the shifts) and the eigenvectors (to augment the Newton basis */
    223:       agmres->HasSchur = PETSC_FALSE;

    225:       KSPDGMRESComputeDeflationData_DGMRES(ksp, &Neig);
    226:       Neig = max_k;
    227:     } else { /* From DGMRES, compute only the eigenvalues needed as Shifts for the Newton Basis */
    228:        KSPDGMRESComputeSchurForm_DGMRES(ksp, &Neig);
    229:     }
    230:     for (i = 0; i < max_k; i++) {
    231:       wr[max_k+i] = agmres->wr[i];
    232:       wi[max_k+i] = agmres->wi[i];
    233:     }
    234:     KSPAGMRESLejaOrdering(wr, wi, Rshift, Ishift, 2*max_k);
    235:     for (i = 0; i< max_k; i++) {
    236:       agmres->Rshift[i] = Rshift[i];
    237:       agmres->Ishift[i] = Ishift[i];
    238:     }
    239:     PetscFree(Rshift);
    240:     PetscFree(wr);
    241:     PetscFree(Ishift);
    242:     PetscFree(wi);
    243:   }
    244:   agmres->HasShifts = PETSC_TRUE;
    245:   ksp->max_it       = max_it;
    246:   PetscLogEventEnd(KSP_AGMRESComputeShifts, ksp, 0,0,0);
    247:   return(0);
    248: }

    250: /*
    251:    Generate the basis vectors from the Newton polynomials with shifts and scaling factors
    252:    The scaling factors are computed to obtain unit vectors. Note that this step can be avoided with the preprocessing option KSP_AGMRES_NONORM.
    253:    Inputs :
    254:     - Operators (Matrix and preconditioners and the first basis vector in VEC_V(0)
    255:     - Shifts values in agmres->Rshift and agmres->Ishift.
    256:    Output :
    257:     - agmres->vecs or VEC_V : basis vectors
    258:     - agmres->Scale : Scaling factors (equal to 1 if no scaling is done)
    259: */
    260: static PetscErrorCode KSPAGMRESBuildBasis(KSP ksp)
    261: {
    263:   KSP_AGMRES     *agmres = (KSP_AGMRES*)ksp->data;
    264:   PetscReal      *Rshift = agmres->Rshift;
    265:   PetscReal      *Ishift = agmres->Ishift;
    266:   PetscReal      *Scale  = agmres->Scale;
    267:   const PetscInt max_k   = agmres->max_k;
    268:   PetscInt       KspSize = KSPSIZE;  /* if max_k == KspSizen then the basis should not be augmented */
    269:   PetscInt       j       = 1;

    272:   PetscLogEventBegin(KSP_AGMRESBuildBasis, ksp, 0,0,0);
    273:   Scale[0] = 1.0;
    274:   while (j <= max_k) {
    275:     if (Ishift[j-1] == 0) {
    276:       if ((ksp->pc_side == PC_LEFT) && agmres->r && agmres->DeflPrecond) {
    277:         /* Apply the precond-matrix operators */
    278:         KSP_PCApplyBAorAB(ksp, VEC_V(j-1), VEC_TMP, VEC_TMP_MATOP);
    279:         /* Then apply deflation as a preconditioner */
    280:         KSPDGMRESApplyDeflation_DGMRES(ksp, VEC_TMP, VEC_V(j));
    281:       } else if ((ksp->pc_side == PC_RIGHT) && agmres->r && agmres->DeflPrecond) {
    282:         KSPDGMRESApplyDeflation_DGMRES(ksp, VEC_V(j-1), VEC_TMP);
    283:         KSP_PCApplyBAorAB(ksp, VEC_TMP, VEC_V(j), VEC_TMP_MATOP);
    284:       } else {
    285:         KSP_PCApplyBAorAB(ksp, VEC_V(j-1), VEC_V(j), VEC_TMP_MATOP);
    286:       }
    287:       VecAXPY(VEC_V(j), -Rshift[j-1], VEC_V(j-1));
    288: #if defined(KSP_AGMRES_NONORM)
    289:       Scale[j] = 1.0;
    290: #else
    291:       VecScale(VEC_V(j), Scale[j-1]); /* This step can be postponed until all vectors are built */
    292:       VecNorm(VEC_V(j), NORM_2, &(Scale[j]));
    293:       Scale[j] = 1.0/Scale[j];
    294: #endif

    296:       agmres->matvecs += 1;
    297:       j++;
    298:     } else {
    299:       if ((ksp->pc_side == PC_LEFT) && agmres->r && agmres->DeflPrecond) {
    300:         /* Apply the precond-matrix operators */
    301:         KSP_PCApplyBAorAB(ksp, VEC_V(j-1), VEC_TMP, VEC_TMP_MATOP);
    302:         /* Then apply deflation as a preconditioner */
    303:         KSPDGMRESApplyDeflation_DGMRES(ksp, VEC_TMP, VEC_V(j));
    304:       } else if ((ksp->pc_side == PC_RIGHT) && agmres->r && agmres->DeflPrecond) {
    305:         KSPDGMRESApplyDeflation_DGMRES(ksp, VEC_V(j-1), VEC_TMP);
    306:         KSP_PCApplyBAorAB(ksp, VEC_TMP, VEC_V(j), VEC_TMP_MATOP);
    307:       } else {
    308:         KSP_PCApplyBAorAB(ksp, VEC_V(j-1), VEC_V(j), VEC_TMP_MATOP);
    309:       }
    310:       VecAXPY(VEC_V(j), -Rshift[j-1], VEC_V(j-1));
    311: #if defined(KSP_AGMRES_NONORM)
    312:       Scale[j] = 1.0;
    313: #else
    314:       VecScale(VEC_V(j), Scale[j-1]);
    315:       VecNorm(VEC_V(j), NORM_2, &(Scale[j]));
    316:       Scale[j] = 1.0/Scale[j];
    317: #endif
    318:       agmres->matvecs += 1;
    319:       j++;
    320:       if ((ksp->pc_side == PC_LEFT) && agmres->r && agmres->DeflPrecond) {
    321:         /* Apply the precond-matrix operators */
    322:         KSP_PCApplyBAorAB(ksp, VEC_V(j-1), VEC_TMP, VEC_TMP_MATOP);
    323:         /* Then apply deflation as a preconditioner */
    324:         KSPDGMRESApplyDeflation_DGMRES(ksp, VEC_TMP, VEC_V(j));
    325:       } else if ((ksp->pc_side == PC_RIGHT) && agmres->r && agmres->DeflPrecond) {
    326:         KSPDGMRESApplyDeflation_DGMRES(ksp, VEC_V(j-1), VEC_TMP);
    327:         KSP_PCApplyBAorAB(ksp, VEC_TMP, VEC_V(j), VEC_TMP_MATOP);
    328:       } else {
    329:         KSP_PCApplyBAorAB(ksp, VEC_V(j-1), VEC_V(j), VEC_TMP_MATOP);
    330:       }
    331:       VecAXPY(VEC_V(j), -Rshift[j-2], VEC_V(j-1));
    332:       VecAXPY(VEC_V(j), Scale[j-2]*Ishift[j-2]*Ishift[j-2], VEC_V(j-2));
    333: #if defined(KSP_AGMRES_NONORM)
    334:       Scale[j] = 1.0;
    335: #else
    336:       VecNorm(VEC_V(j), NORM_2, &(Scale[j]));
    337:       Scale[j] = 1.0/Scale[j];
    338: #endif
    339:       agmres->matvecs += 1;
    340:       j++;
    341:     }
    342:   }
    343:   /* Augment the subspace with the eigenvectors*/
    344:   while (j <= KspSize) {
    345:     KSP_PCApplyBAorAB(ksp, agmres->U[j - max_k - 1], VEC_V(j), VEC_TMP_MATOP);
    346: #if defined(KSP_AGMRES_NONORM)
    347:     Scale[j] = 1.0;
    348: #else
    349:     VecScale(VEC_V(j), Scale[j-1]);
    350:     VecNorm(VEC_V(j), NORM_2, &(Scale[j]));
    351:     Scale[j] = 1.0/Scale[j];
    352: #endif
    353:     agmres->matvecs += 1;
    354:     j++;
    355:   }
    356:   PetscLogEventEnd(KSP_AGMRESBuildBasis, ksp, 0,0,0);
    357:   return(0);
    358: }

    360: /*
    361:   Form the Hessenberg matrix for the Arnoldi-like relation.
    362:    Inputs :
    363:    - Shifts values in agmres->Rshift and agmres->Ishift
    364:    - RLoc : Triangular matrix from the RODDEC orthogonalization
    365:    Outputs :
    366:    - H = agmres->hh_origin : The Hessenberg matrix.

    368:    NOTE: Note that the computed Hessenberg matrix is not mathematically equivalent to that in the real Arnoldi process (in KSP GMRES). If it is needed, it can be explicitly  formed as H <-- H * RLoc^-1.
    369:  */
    370: static PetscErrorCode KSPAGMRESBuildHessenberg(KSP ksp)
    371: {
    372:   KSP_AGMRES     *agmres = (KSP_AGMRES*)ksp->data;
    373:   PetscScalar    *Rshift = agmres->Rshift;
    374:   PetscScalar    *Ishift = agmres->Ishift;
    375:   PetscScalar    *Scale  = agmres->Scale;
    377:   PetscInt       i       = 0, j = 0;
    378:   const PetscInt max_k   = agmres->max_k;
    379:   PetscInt       KspSize = KSPSIZE;
    380:   PetscInt       N       = MAXKSPSIZE+1;

    383:   PetscArrayzero(agmres->hh_origin, (N+1)*N);
    384:   while (j < max_k) {
    385:     /* Real shifts */
    386:     if (Ishift[j] == 0) {
    387:       for (i = 0; i <= j; i++) {
    388:         *H(i,j) = *RLOC(i,j+1)/Scale[j]  + (Rshift[j] * *RLOC(i,j));
    389:       }
    390:       *H(j+1,j) = *RLOC(j+1,j+1)/Scale[j];
    391:       j++;
    392:     } else if (Ishift[j] > 0) {
    393:       for (i = 0; i <= j; i++) {
    394:         *H(i,j) = *RLOC(i,j+1)/Scale[j] +  Rshift[j] * *RLOC(i, j);
    395:       }
    396:       *H(j+1,j) = *RLOC(j+1, j+1)/Scale[j];
    397:       j++;
    398:       for (i = 0; i <= j; i++) {
    399:         *H(i,j) = (*RLOC(i,j+1) + Rshift[j-1] * *RLOC(i,j) - Scale[j-1] * Ishift[j-1]*Ishift[j-1]* *RLOC(i,j-1));
    400:       }
    401:       *H(j,j) = (*RLOC(j,j+1) + Rshift[j-1] * *RLOC(j,j));
    402:       *H(j+1,j) = *RLOC(j+1,j+1);
    403:       j++;
    404:     } else SETERRQ(PetscObjectComm((PetscObject)ksp), PETSC_ERR_ORDER, "BAD ORDERING OF THE SHIFTS VALUES IN THE NEWTON BASIS");
    405:   }
    406:   for (j = max_k; j< KspSize; j++) { /* take into account the norm of the augmented vectors */
    407:     for (i = 0; i <= j+1; i++) *H(i,j) = *RLOC(i, j+1)/Scale[j];
    408:   }
    409:   return(0);
    410: }

    412: /*
    413:   Form the new approximate solution from the least-square problem
    414: */
    415: static PetscErrorCode KSPAGMRESBuildSoln(KSP ksp,PetscInt it)
    416: {
    417:   KSP_AGMRES     *agmres = (KSP_AGMRES*)ksp->data;
    419:   const PetscInt max_k = agmres->max_k;       /* Size of the non-augmented Krylov basis */
    420:   PetscInt       i, j;
    421:   PetscInt       r = agmres->r;           /* current number of augmented eigenvectors */
    422:   PetscBLASInt   KspSize;
    423:   PetscBLASInt   lC;
    424:   PetscBLASInt   N;
    425:   PetscBLASInt   ldH = it + 1;
    426:   PetscBLASInt   lwork;
    427:   PetscBLASInt   info, nrhs = 1;

    430:   PetscBLASIntCast(KSPSIZE,&KspSize);
    431:   PetscBLASIntCast(4 * (KspSize+1),&lwork);
    432:   PetscBLASIntCast(KspSize+1,&lC);
    433:   PetscBLASIntCast(MAXKSPSIZE + 1,&N);
    434:   PetscBLASIntCast(N + 1,&ldH);
    435:   /* Save a copy of the Hessenberg matrix */
    436:   for (j = 0; j < N-1; j++) {
    437:     for (i = 0; i < N; i++) {
    438:       *HS(i,j) = *H(i,j);
    439:     }
    440:   }
    441:   /* QR factorize the Hessenberg matrix */
    442:   PetscStackCallBLAS("LAPACKgeqrf",LAPACKgeqrf_(&lC, &KspSize, agmres->hh_origin, &ldH, agmres->tau, agmres->work, &lwork, &info));
    443:   if (info) SETERRQ1(PetscObjectComm((PetscObject)ksp), PETSC_ERR_LIB,"Error in LAPACK routine XGEQRF INFO=%d", info);
    444:   /* Update the right hand side of the least square problem */
    445:   PetscArrayzero(agmres->nrs, N);

    447:   agmres->nrs[0] = ksp->rnorm;
    448:   PetscStackCallBLAS("LAPACKormqr",LAPACKormqr_("L", "T", &lC, &nrhs, &KspSize, agmres->hh_origin, &ldH, agmres->tau, agmres->nrs, &N, agmres->work, &lwork, &info));
    449:   if (info) SETERRQ1(PetscObjectComm((PetscObject)ksp), PETSC_ERR_LIB,"Error in LAPACK routine XORMQR INFO=%d",info);
    450:   ksp->rnorm = PetscAbsScalar(agmres->nrs[KspSize]);
    451:   /* solve the least-square problem */
    452:   PetscStackCallBLAS("LAPACKtrtrs",LAPACKtrtrs_("U", "N", "N", &KspSize, &nrhs, agmres->hh_origin, &ldH, agmres->nrs, &N, &info));
    453:   if (info) SETERRQ1(PetscObjectComm((PetscObject)ksp), PETSC_ERR_LIB,"Error in LAPACK routine XTRTRS INFO=%d",info);
    454:   /* Accumulate the correction to the solution of the preconditioned problem in VEC_TMP */
    455:   VecZeroEntries(VEC_TMP);
    456:   VecMAXPY(VEC_TMP, max_k, agmres->nrs, &VEC_V(0));
    457:   if (!agmres->DeflPrecond) { VecMAXPY(VEC_TMP, r, &agmres->nrs[max_k], agmres->U); }

    459:   if ((ksp->pc_side == PC_RIGHT) && agmres->r && agmres->DeflPrecond) {
    460:     KSPDGMRESApplyDeflation_DGMRES(ksp, VEC_TMP, VEC_TMP_MATOP);
    461:     VecCopy(VEC_TMP_MATOP, VEC_TMP);
    462:   }
    463:   KSPUnwindPreconditioner(ksp, VEC_TMP, VEC_TMP_MATOP);
    464:   /* add the solution to the previous one */
    465:   VecAXPY(ksp->vec_sol, 1.0, VEC_TMP);
    466:   return(0);
    467: }

    469: /*
    470:    Run  one cycle of the Newton-basis gmres, possibly augmented with eigenvectors.

    472:    Return residual history if requested.
    473:    Input :
    474:    - The vector VEC_V(0) is the initia residual
    475:    Output :
    476:     - the solution vector is in agmres->vec_sol
    477:    - itcount : number of inner iterations
    478:     - res : the new residual norm
    479:  .
    480:  NOTE: Unlike GMRES where the residual norm is available at each (inner) iteration,  here it is available at the end of the cycle.
    481: */
    482: static PetscErrorCode KSPAGMRESCycle(PetscInt *itcount,KSP ksp)
    483: {
    484:   KSP_AGMRES     *agmres = (KSP_AGMRES*)(ksp->data);
    485:   PetscReal      res;
    487:   PetscInt       KspSize = KSPSIZE;

    490:   /* check for the convergence */
    491:   res = ksp->rnorm; /* Norm of the initial residual vector */
    492:   if (!res) {
    493:     if (itcount) *itcount = 0;
    494:     ksp->reason = KSP_CONVERGED_ATOL;
    495:     PetscInfo(ksp,"Converged due to zero residual norm on entry\n");
    496:     return(0);
    497:   }
    498:   (*ksp->converged)(ksp,ksp->its,res,&ksp->reason,ksp->cnvP);
    499:   /* Build the Krylov basis with Newton polynomials */
    500:   KSPAGMRESBuildBasis(ksp);
    501:   /* QR Factorize the basis with RODDEC */
    502:   KSPAGMRESRoddec(ksp, KspSize+1);

    504:   /* Recover a (partial) Hessenberg matrix for the Arnoldi-like relation */
    505:   KSPAGMRESBuildHessenberg(ksp);
    506:   /* Solve the least square problem and unwind the preconditioner */
    507:   KSPAGMRESBuildSoln(ksp, KspSize);

    509:   res        = ksp->rnorm;
    510:   ksp->its  += KspSize;
    511:   agmres->it = KspSize-1;
    512:   /*  Test for the convergence */
    513:   (*ksp->converged)(ksp,ksp->its,res,&ksp->reason,ksp->cnvP);
    514:   KSPLogResidualHistory(ksp,res);
    515:   KSPMonitor(ksp,ksp->its,res);

    517:   *itcount = KspSize;
    518:   return(0);
    519: }

    521: static PetscErrorCode KSPSolve_AGMRES(KSP ksp)
    522: {
    524:   PetscInt       its;
    525:   KSP_AGMRES     *agmres    = (KSP_AGMRES*)ksp->data;
    526:   PetscBool      guess_zero = ksp->guess_zero;
    527:   PetscReal      res_old, res;
    528:   PetscInt       test;

    531:   PetscObjectSAWsTakeAccess((PetscObject)ksp);
    532:   ksp->its = 0;
    533:   PetscObjectSAWsGrantAccess((PetscObject)ksp);

    535:   ksp->reason = KSP_CONVERGED_ITERATING;
    536:   if (!agmres->HasShifts) { /* Compute Shifts for the Newton basis */
    537:     KSPComputeShifts_DGMRES(ksp);
    538:   }
    539:   /* NOTE: At this step, the initial guess is not equal to zero since one cycle of the classical GMRES is performed to compute the shifts */
    540:   (*ksp->converged)(ksp,0,ksp->rnorm,&ksp->reason,ksp->cnvP);
    541:   while (!ksp->reason) {
    542:     KSPInitialResidual(ksp,ksp->vec_sol,VEC_TMP,VEC_TMP_MATOP,VEC_V(0),ksp->vec_rhs);
    543:     if ((ksp->pc_side == PC_LEFT) && agmres->r && agmres->DeflPrecond) {
    544:       KSPDGMRESApplyDeflation_DGMRES(ksp, VEC_V(0), VEC_TMP);
    545:       VecCopy(VEC_TMP, VEC_V(0));

    547:       agmres->matvecs += 1;
    548:     }
    549:     VecNormalize(VEC_V(0),&(ksp->rnorm));
    550:     KSPCheckNorm(ksp,ksp->rnorm);
    551:     res_old = ksp->rnorm; /* Record the residual norm to test if deflation is needed */

    553:     ksp->ops->buildsolution = KSPBuildSolution_AGMRES;

    555:     KSPAGMRESCycle(&its,ksp);
    556:     if (ksp->its >= ksp->max_it) {
    557:       if (!ksp->reason) ksp->reason = KSP_DIVERGED_ITS;
    558:       break;
    559:     }
    560:     /* compute the eigenvectors to augment the subspace : use an adaptive strategy */
    561:     res = ksp->rnorm;
    562:     if (!ksp->reason && agmres->neig > 0) {
    563:       test = agmres->max_k * PetscLogReal(ksp->rtol/res) / PetscLogReal(res/res_old); /* estimate the remaining number of steps */
    564:       if ((test > agmres->smv*(ksp->max_it-ksp->its)) || agmres->force) {
    565:         if (!agmres->force && ((test > agmres->bgv*(ksp->max_it-ksp->its)) && ((agmres->r + 1) < agmres->max_neig))) {
    566:           agmres->neig += 1; /* Augment the number of eigenvalues to deflate if the convergence is too slow */
    567:         }
    568:         KSPDGMRESComputeDeflationData_DGMRES(ksp,&agmres->neig);
    569:       }
    570:     }
    571:     ksp->guess_zero = PETSC_FALSE; /* every future call to KSPInitialResidual() will have nonzero guess */
    572:   }
    573:   ksp->guess_zero = guess_zero; /* restore if user has provided nonzero initial guess */
    574:   return(0);
    575: }

    577: static PetscErrorCode KSPDestroy_AGMRES(KSP ksp)
    578: {
    580:   KSP_AGMRES     *agmres = (KSP_AGMRES*)ksp->data;

    583:   PetscFree(agmres->hh_origin);

    585:   PetscFree(agmres->Qloc);
    586:   PetscFree4(agmres->Rshift,agmres->Ishift,agmres->Rloc,agmres->wbufptr);
    587:   PetscFree3(agmres->tau,agmres->work,agmres->nrs);
    588:   PetscFree4(agmres->Scale,agmres->sgn,agmres->tloc,agmres->temp);

    590:   PetscFree(agmres->select);
    591:   PetscFree(agmres->wr);
    592:   PetscFree(agmres->wi);
    593:   if (agmres->neig) {
    594:     VecDestroyVecs(MAXKSPSIZE,&agmres->TmpU);
    595:     PetscFree(agmres->perm);
    596:     PetscFree(agmres->MatEigL);
    597:     PetscFree(agmres->MatEigR);
    598:     PetscFree(agmres->Q);
    599:     PetscFree(agmres->Z);
    600:     PetscFree(agmres->beta);
    601:   }
    602:   KSPDestroy_DGMRES(ksp);
    603:   return(0);
    604: }

    606: static PetscErrorCode KSPView_AGMRES(KSP ksp,PetscViewer viewer)
    607: {
    608:   KSP_AGMRES     *agmres = (KSP_AGMRES*)ksp->data;
    609:   const char     *cstr   = "RODDEC ORTHOGONOLIZATION";
    610:   char           ritzvec[25];
    612:   PetscBool      iascii,isstring;
    613: #if defined(KSP_AGMRES_NONORM)
    614:   const char *Nstr = "SCALING FACTORS : NO";
    615: #else
    616:   const char *Nstr = "SCALING FACTORS : YES";
    617: #endif

    620:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);
    621:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSTRING,&isstring);

    623:   if (iascii) {
    624:     PetscViewerASCIIPrintf(viewer, " restart=%d using %s\n", agmres->max_k, cstr);
    625:     PetscViewerASCIIPrintf(viewer, " %s\n", Nstr);
    626:     PetscViewerASCIIPrintf(viewer, " Number of matvecs : %D\n", agmres->matvecs);
    627:     if (agmres->force) {PetscViewerASCIIPrintf (viewer, " Adaptive strategy is used: FALSE\n");}
    628:     else PetscViewerASCIIPrintf(viewer, " Adaptive strategy is used: TRUE\n");
    629:     if (agmres->DeflPrecond) {
    630:       ierr=PetscViewerASCIIPrintf(viewer, " STRATEGY OF DEFLATION: PRECONDITIONER \n");
    631:       ierr=PetscViewerASCIIPrintf(viewer, "  Frequency of extracted eigenvalues = %D\n", agmres->neig);
    632:       ierr=PetscViewerASCIIPrintf(viewer, "  Total number of extracted eigenvalues = %D\n", agmres->r);
    633:       ierr=PetscViewerASCIIPrintf(viewer, "  Maximum number of eigenvalues set to be extracted = %D\n", agmres->max_neig);
    634:     } else {
    635:       if (agmres->ritz) sprintf(ritzvec, "Ritz vectors");
    636:       else sprintf(ritzvec, "Harmonic Ritz vectors");
    637:       PetscViewerASCIIPrintf(viewer, " STRATEGY OF DEFLATION: AUGMENT\n");
    638:       PetscViewerASCIIPrintf(viewer," augmented vectors  %d at frequency %d with %s\n", agmres->r, agmres->neig, ritzvec);
    639:     }
    640:     ierr=PetscViewerASCIIPrintf(viewer, " Minimum relaxation parameter for the adaptive strategy(smv)  = %g\n", agmres->smv);
    641:     ierr=PetscViewerASCIIPrintf(viewer, " Maximum relaxation parameter for the adaptive strategy(bgv)  = %g\n", agmres->bgv);
    642:   } else if (isstring) {
    643:     PetscViewerStringSPrintf(viewer,"%s restart %D",cstr,agmres->max_k);
    644:   }
    645:   return(0);
    646: }

    648: static PetscErrorCode KSPSetFromOptions_AGMRES(PetscOptionItems *PetscOptionsObject,KSP ksp)
    649: {
    651:   PetscInt       neig;
    652:   KSP_AGMRES     *agmres = (KSP_AGMRES*)ksp->data;
    653:   PetscBool      flg;

    656:   KSPSetFromOptions_DGMRES(PetscOptionsObject,ksp);  /* Set common options from DGMRES and GMRES */
    657:   PetscOptionsHead(PetscOptionsObject,"KSP AGMRES Options");
    658:   PetscOptionsInt("-ksp_agmres_eigen", "Number of eigenvalues to deflate", "KSPDGMRESSetEigen", agmres->neig, &neig, &flg);
    659:   if (flg) {
    660:     KSPDGMRESSetEigen_DGMRES(ksp, neig);
    661:     agmres->r = 0;
    662:   } else agmres->neig = 0;
    663:   PetscOptionsInt("-ksp_agmres_maxeigen", "Maximum number of eigenvalues to deflate", "KSPDGMRESSetMaxEigen", agmres->max_neig, &neig, &flg);
    664:   if (flg) agmres->max_neig = neig+EIG_OFFSET;
    665:   else agmres->max_neig = agmres->neig+EIG_OFFSET;
    666:   PetscOptionsBool("-ksp_agmres_DeflPrecond", "Determine if the deflation should be applied as a preconditioner -- similar to KSP DGMRES", "KSPGMRESDeflPrecond",agmres->DeflPrecond,&agmres->DeflPrecond,NULL);
    667:   PetscOptionsBool("-ksp_agmres_ritz", "Compute the Ritz vectors instead of the Harmonic Ritz vectors ", "KSPGMRESHarmonic",agmres->ritz,&agmres->ritz ,&flg);
    668:   PetscOptionsReal("-ksp_agmres_MinRatio", "Relaxation parameter in the adaptive strategy; smallest multiple of the remaining number of steps allowed", "KSPGMRESSetMinRatio", agmres->smv, &agmres->smv, NULL);
    669:   PetscOptionsReal("-ksp_agmres_MaxRatio", "Relaxation parameter in the adaptive strategy; Largest multiple of the remaining number of steps allowed", "KSPGMRESSetMaxRatio",agmres->bgv,&agmres->bgv, &flg);
    670:   PetscOptionsTail();
    671:   return(0);
    672: }

    674: /*MC
    675:  KSPAGMRES - Newton basis GMRES implementation with adaptive augmented eigenvectors

    677: The techniques used are best described in [1]. The contribution of this work is that it combines many of the previous work to reduce the amount of MPI messages and improve the robustness of the global approach by using deflation techniques. It has been successfully applied to a class of real and industrial problems. Please see [1] for numerical experiments and [2] for a description of these problems.
    678: There are  many ongoing work that aim at avoiding (or minimizing) the communication in Krylov subspace methods. This code can be used as an experimental framework to combine several techniques in the particular case of GMRES. For instance, the computation of the shifts can be improved with techniques described in [3]. The orthogonalization technique can be replaced by TSQR [4]. The generation of the basis can be done using s-steps approaches[5].

    681:  Options Database Keys:
    682:  +   -ksp_gmres_restart <restart> -  the number of Krylov directions
    683:  .   -ksp_gmres_krylov_monitor - plot the Krylov space generated
    684:  .   -ksp_agmres_eigen <neig> - Number of eigenvalues to deflate (Number of vectors to augment)
    685:  .   -ksp_agmres_maxeigen <max_neig> - Maximum number of eigenvalues to deflate
    686:  .   -ksp_agmres_MinRatio <1> - Relaxation parameter in the adaptive strategy; smallest multiple of the remaining number of steps allowed
    687:  .   -ksp_agmres_MaxRatio <1> - Relaxation parameter in the adaptive strategy; Largest multiple of the remaining number of steps allowed
    688:  .   -ksp_agmres_DeflPrecond - Apply deflation as a preconditioner, this is similar to DGMRES but it rather builds a Newton basis.  This is an experimental option.
    689:  -   -ksp_dgmres_force <0, 1> - Force the deflation at each restart.

    691:  Level: beginner

    693:  Notes:
    694:     Left and right preconditioning are supported, but not symmetric preconditioning. Complex arithmetic is not supported

    696:  Developer Notes:
    697:     This object is subclassed off of KSPDGMRES

    699:  Contributed by Desire NUENTSA WAKAM, INRIA <desire.nuentsa_wakam@inria.fr>
    700:  Inputs from Guy Atenekeng <atenekeng@yahoo.com> and R.B. Sidje <roger.b.sidje@ua.edu>

    702:  References :
    703:  +   [1] D. Nuentsa Wakam and J. Erhel, Parallelism and robustness in GMRES with the Newton basis and the deflated restarting. Research report INRIA RR-7787, November 2011,https://hal.inria.fr/inria-00638247/en,  in revision for ETNA.
    704:  .  [2] D. NUENTSA WAKAM and F. PACULL, Memory Efficient Hybrid Algebraic Solvers for Linear Systems Arising from Compressible Flows, Computers and Fluids, In Press, http://dx.doi.org/10.1016/j.compfluid.2012.03.023
    705:  .  [3] B. Philippe and L. Reichel, On the generation of Krylov subspace bases, Applied Numerical
    706: Mathematics, 62(9), pp. 1171-1186, 2012
    707:  .  [4] J. Demmel, L. Grigori, M. F. Hoemmen, and J. Langou, Communication-optimal parallel and sequential QR and LU factorizations, SIAM journal on Scientific Computing, 34(1), A206-A239, 2012
    708:  .  [5] M. Mohiyuddin, M. Hoemmen, J. Demmel, and K. Yelick, Minimizing communication in sparse matrix solvers, in SC '09: Proceedings of the Conference on High Performance Computing Networking, Storage and Analysis, New York, NY, USA, 2009, ACM, pp. 1154-1171.
    709:  .    Sidje, Roger B. Alternatives for parallel Krylov subspace basis computation. Numer. Linear Algebra Appl. 4 (1997), no. 4, 305-331

    711:  .seealso:  KSPCreate(), KSPSetType(), KSPType (for list of available types), KSP, KSPDGMRES, KSPPGMRES,
    712:  KSPGMRESSetRestart(), KSPGMRESSetHapTol(), KSPGMRESSetPreAllocateVectors(), KSPGMRESSetOrthogonalization(), KSPGMRESGetOrthogonalization(),
    713:  KSPGMRESClassicalGramSchmidtOrthogonalization(), KSPGMRESModifiedGramSchmidtOrthogonalization(),
    714:  KSPGMRESCGSRefinementType, KSPGMRESSetCGSRefinementType(), KSPGMRESGetCGSRefinementType(), KSPGMRESMonitorKrylov(), KSPSetPCSide()
    715:  M*/

    717: PETSC_EXTERN PetscErrorCode KSPCreate_AGMRES(KSP ksp)
    718: {
    719:   KSP_AGMRES     *agmres;

    723:   PetscNewLog(ksp,&agmres);
    724:   ksp->data = (void*)agmres;

    726:   KSPSetSupportedNorm(ksp,KSP_NORM_PRECONDITIONED,PC_LEFT,3);
    727:   KSPSetSupportedNorm(ksp,KSP_NORM_UNPRECONDITIONED,PC_RIGHT,2);
    728:   ksp->ops->buildsolution                = KSPBuildSolution_AGMRES;
    729:   ksp->ops->setup                        = KSPSetUp_AGMRES;
    730:   ksp->ops->solve                        = KSPSolve_AGMRES;
    731:   ksp->ops->destroy                      = KSPDestroy_AGMRES;
    732:   ksp->ops->view                         = KSPView_AGMRES;
    733:   ksp->ops->setfromoptions               = KSPSetFromOptions_AGMRES;
    734:   ksp->guess_zero                        = PETSC_TRUE;
    735:   ksp->ops->computeextremesingularvalues = KSPComputeExtremeSingularValues_GMRES;
    736:   ksp->ops->computeeigenvalues           = KSPComputeEigenvalues_GMRES;

    739:   PetscObjectComposeFunction((PetscObject) ksp,"KSPGMRESSetPreAllocateVectors_C",KSPGMRESSetPreAllocateVectors_GMRES);
    740:   PetscObjectComposeFunction((PetscObject) ksp,"KSPGMRESSetOrthogonalization_C",KSPGMRESSetOrthogonalization_GMRES);
    741:   PetscObjectComposeFunction((PetscObject) ksp,"KSPGMRESSetRestart_C",KSPGMRESSetRestart_GMRES);
    742:   PetscObjectComposeFunction((PetscObject) ksp,"KSPGMRESSetHapTol_C",KSPGMRESSetHapTol_GMRES);
    743:   PetscObjectComposeFunction((PetscObject) ksp,"KSPGMRESSetCGSRefinementType_C",KSPGMRESSetCGSRefinementType_GMRES);
    744:   /* -- New functions defined in DGMRES -- */
    745:   ierr=PetscObjectComposeFunction((PetscObject) ksp, "KSPDGMRESSetEigen_C",KSPDGMRESSetEigen_DGMRES);
    746:   ierr=PetscObjectComposeFunction((PetscObject) ksp, "KSPDGMRESComputeSchurForm_C",KSPDGMRESComputeSchurForm_DGMRES);
    747:   ierr=PetscObjectComposeFunction((PetscObject) ksp, "KSPDGMRESComputeDeflationData_C",KSPDGMRESComputeDeflationData_DGMRES);
    748:   ierr=PetscObjectComposeFunction((PetscObject) ksp, "KSPDGMRESApplyDeflation_C",KSPDGMRESApplyDeflation_DGMRES);

    750:   PetscLogEventRegister("AGMRESCompDefl",   KSP_CLASSID, &KSP_AGMRESComputeDeflationData);
    751:   PetscLogEventRegister("AGMRESBuildBasis", KSP_CLASSID, &KSP_AGMRESBuildBasis);
    752:   PetscLogEventRegister("AGMRESCompShifts", KSP_CLASSID, &KSP_AGMRESComputeShifts);
    753:   PetscLogEventRegister("AGMRESOrthog",     KSP_CLASSID, &KSP_AGMRESRoddec);

    755:   agmres->haptol         = 1.0e-30;
    756:   agmres->q_preallocate  = 0;
    757:   agmres->delta_allocate = AGMRES_DELTA_DIRECTIONS;
    758:   agmres->orthog         = KSPGMRESClassicalGramSchmidtOrthogonalization;
    759:   agmres->nrs            = NULL;
    760:   agmres->sol_temp       = NULL;
    761:   agmres->max_k          = AGMRES_DEFAULT_MAXK;
    762:   agmres->Rsvd           = NULL;
    763:   agmres->cgstype        = KSP_GMRES_CGS_REFINE_NEVER;
    764:   agmres->orthogwork     = NULL;

    766:   /* Default values for the deflation */
    767:   agmres->r           = 0;
    768:   agmres->neig        = 0;
    769:   agmres->max_neig    = 0;
    770:   agmres->lambdaN     = 0.0;
    771:   agmres->smv         = SMV;
    772:   agmres->bgv         = 1;
    773:   agmres->force       = PETSC_FALSE;
    774:   agmres->matvecs     = 0;
    775:   agmres->improve     = PETSC_FALSE;
    776:   agmres->HasShifts   = PETSC_FALSE;
    777:   agmres->r           = 0;
    778:   agmres->HasSchur    = PETSC_FALSE;
    779:   agmres->DeflPrecond = PETSC_FALSE;
    780:   PetscObjectGetNewTag((PetscObject)ksp,&agmres->tag);
    781:   return(0);
    782: }