Actual source code: gmresimpl.h

  1: /*
  2:    Private data structure used by the GMRES method. This data structure
  3:   must be identical to the beginning of the KSP_FGMRES data structure
  4:   so if you CHANGE anything here you must also change it there.
  5: */
  6: #pragma once

  8: #include <petsc/private/kspimpl.h>

 10: #define KSPGMRESHEADER \
 11:   /* Hessenberg matrix information. */ \
 12:   PetscScalar *hh_origin;  /* holds Hessenberg matrix that has been multiplied by plane rotations (upper tri) */ \
 13:   PetscScalar *hes_origin; /* holds the original (unmodified) Hessenberg matrix which may be used to estimate the Singular Values of the matrix */ \
 14:   PetscScalar *hes_ritz;   /* holds the last full Hessenberg matrix to compute (harmonic) Ritz pairs */ \
 15:   PetscScalar *cc_origin;  /* holds cosines for rotation matrices */ \
 16:   PetscScalar *ss_origin;  /* holds sines for rotation matrices */ \
 17:   PetscScalar *rs_origin;  /* holds the right-hand side of the Hessenberg system */ \
 18: \
 19:   /* Work space for computing eigenvalues/singular values */ \
 20:   PetscReal   *Dsvd; \
 21:   PetscScalar *Rsvd; \
 22: \
 23:   PetscReal haptol;      /* tolerance for happy breakdown */ \
 24:   PetscInt  max_k;       /* number of vectors in Krylov space, restart size */ \
 25:   PetscInt  nextra_vecs; /* number of extra vecs needed, e.g. for a pipeline */ \
 26: \
 27:   Vec      *vecs;           /* the work vectors */ \
 28:   Vec      *vecb;           /* holds the last full basis vectors of the Krylov subspace to compute (harmonic) Ritz pairs */ \
 29:   PetscBool q_preallocate;  /* Preallocate all the work vectors for the Krylov subspace */ \
 30:   PetscInt  delta_allocate; /* number of vectors to preallocaate in each block if not preallocated */ \
 31:   PetscInt  vv_allocated;   /* number of allocated gmres direction vectors */ \
 32:   PetscInt  vecs_allocated; /*   total number of vecs available */ \
 33:   /* Since we may call the user "obtain_work_vectors" several times, we have to keep track of the pointers that it has returned */ \
 34:   Vec     **user_work; \
 35:   PetscInt *mwork_alloc; /* Number of work vectors allocated as part of  a work-vector chunk */ \
 36:   PetscInt  nwork_alloc; /* Number of work vector chunks allocated */ \
 37: \
 38:   /* Information for building solution */ \
 39:   PetscInt     it;           /* Current iteration: inside restart */ \
 40:   PetscInt     fullcycle;    /* Current number of complete cycle */ \
 41:   PetscScalar *nrs;          /* temp that holds the coefficients of the Krylov vectors that form the minimum residual solution */ \
 42:   Vec          sol_temp;     /* used to hold temporary solution */ \
 43:   PetscReal    rnorm0;       /* residual norm at beginning of the GMRESCycle */ \
 44:   PetscReal    breakdowntol; /* A relative tolerance is used for breakdown check in GMRESCycle */

 46: typedef struct {
 47:   KSPGMRESHEADER
 48: } KSP_GMRES;

 50: PETSC_INTERN PetscErrorCode KSPView_GMRES(KSP, PetscViewer);
 51: PETSC_INTERN PetscErrorCode KSPSetUp_GMRES(KSP);
 52: PETSC_INTERN PetscErrorCode KSPSetFromOptions_GMRES(KSP, PetscOptionItems PetscOptionsObject);
 53: PETSC_INTERN PetscErrorCode KSPComputeExtremeSingularValues_GMRES(KSP, PetscReal *, PetscReal *);
 54: PETSC_INTERN PetscErrorCode KSPComputeEigenvalues_GMRES(KSP, PetscInt, PetscReal *, PetscReal *, PetscInt *);
 55: PETSC_INTERN PetscErrorCode KSPComputeRitz_GMRES(KSP, PetscBool, PetscBool, PetscInt *, Vec[], PetscReal *, PetscReal *);
 56: PETSC_INTERN PetscErrorCode KSPReset_GMRES(KSP);
 57: PETSC_INTERN PetscErrorCode KSPDestroy_GMRES(KSP);
 58: PETSC_INTERN PetscErrorCode KSPGMRESGetNewVectors(KSP, PetscInt);

 60: PETSC_INTERN PetscErrorCode KSPGMRESSetHapTol_GMRES(KSP, PetscReal);
 61: PETSC_INTERN PetscErrorCode KSPGMRESSetPreAllocateVectors_GMRES(KSP);
 62: PETSC_INTERN PetscErrorCode KSPGMRESSetRestart_GMRES(KSP, PetscInt);
 63: PETSC_INTERN PetscErrorCode KSPGMRESGetRestart_GMRES(KSP, PetscInt *);

 65: /* These macros are guarded because they are redefined by derived implementations */
 66: #if !defined(KSPGMRES_NO_MACROS)
 67:   #define HH(a, b)  (gmres->hh_origin + (b) * (gmres->max_k + 2) + (a))
 68:   #define HES(a, b) (gmres->hes_origin + (b) * (gmres->max_k + 1) + (a))
 69:   #define CC(a)     (gmres->cc_origin + (a))
 70:   #define SS(a)     (gmres->ss_origin + (a))
 71:   #define GRS(a)    (gmres->rs_origin + (a))

 73:   /* vector names */
 74:   #define VEC_OFFSET     2
 75:   #define VEC_TEMP       gmres->vecs[0]
 76:   #define VEC_TEMP_MATOP gmres->vecs[1]
 77:   #define VEC_VV(i)      gmres->vecs[VEC_OFFSET + (i)]
 78: #endif