Actual source code: pcgamgimpl.h

  1: #pragma once
  2: #include <petscksp.h>
  3: #include <petsc/private/pcimpl.h>
  4: #include <petsc/private/pcmgimpl.h>
  5: #include <petscmatcoarsen.h>
  6: #include <petsc/private/matimpl.h>

  8: struct _PCGAMGOps {
  9:   PetscErrorCode (*creategraph)(PC, Mat, Mat *);
 10:   PetscErrorCode (*coarsen)(PC, Mat *, PetscCoarsenData **);
 11:   PetscErrorCode (*prolongator)(PC, Mat, PetscCoarsenData *, Mat *);
 12:   PetscErrorCode (*optprolongator)(PC, Mat, Mat *);
 13:   PetscErrorCode (*createlevel)(PC, Mat, PetscInt, Mat *, Mat *, PetscMPIInt *, IS *, PetscBool);
 14:   PetscErrorCode (*createdefaultdata)(PC, Mat); /* for data methods that have a default (SA) */
 15:   PetscErrorCode (*setfromoptions)(PC, PetscOptionItems *);
 16:   PetscErrorCode (*destroy)(PC);
 17:   PetscErrorCode (*view)(PC, PetscViewer);
 18: };
 19: /* Private context for the GAMG preconditioner */
 20: typedef struct gamg_TAG {
 21:   PCGAMGType       type;
 22:   PetscInt         Nlevels;
 23:   PetscBool        repart;
 24:   PetscBool        reuse_prol;
 25:   PetscBool        use_aggs_in_asm;
 26:   PetscBool        use_parallel_coarse_grid_solver;
 27:   PCGAMGLayoutType layout_type;
 28:   PetscBool        cpu_pin_coarse_grids;
 29:   PetscInt         min_eq_proc;
 30:   PetscInt         asm_hem_aggs;
 31:   PetscInt         coarse_eq_limit;
 32:   PetscReal        threshold_scale;
 33:   PetscReal        threshold[PETSC_MG_MAXLEVELS]; /* common quatity to many AMG methods so keep it up here */
 34:   PetscInt         level_reduction_factors[PETSC_MG_MAXLEVELS];
 35:   PetscInt         current_level; /* stash construction state */
 36:   /* these 4 are all related to the method data and should be in the subctx */
 37:   PetscInt   data_sz; /* nloc*data_rows*data_cols */
 38:   PetscInt   data_cell_rows;
 39:   PetscInt   data_cell_cols;
 40:   PetscInt   orig_data_cell_rows;
 41:   PetscInt   orig_data_cell_cols;
 42:   PetscReal *data;      /* [data_sz] blocked vector of vertex data on fine grid (coordinates/nullspace) */
 43:   PetscReal *orig_data; /* cache data */

 45:   struct _PCGAMGOps *ops;
 46:   char              *gamg_type_name;

 48:   void *subctx;

 50:   PetscBool use_sa_esteig;
 51:   PetscReal emin, emax;
 52:   PetscBool recompute_esteig;
 53:   PetscInt  injection_index_size;
 54:   PetscInt  injection_index[MAT_COARSEN_STRENGTH_INDEX_SIZE];
 55: } PC_GAMG;

 57: PetscErrorCode PCReset_MG(PC);

 59: /* hooks create derivied classes */
 60: PetscErrorCode PCCreateGAMG_GEO(PC);
 61: PetscErrorCode PCCreateGAMG_AGG(PC);
 62: PetscErrorCode PCCreateGAMG_Classical(PC);

 64: PetscErrorCode PCDestroy_GAMG(PC);

 66: /* helper methods */
 67: PetscErrorCode PCGAMGGetDataWithGhosts(Mat, PetscInt, PetscReal[], PetscInt *, PetscReal **);

 69: enum tag {
 70:   GAMG_SETUP = 0,
 71:   GAMG_MESH,
 72:   GAMG_MATRIX,
 73:   GAMG_GRAPH,
 74:   GAMG_COARSEN,
 75:   GAMG_SQUARE,
 76:   GAMG_MIS,
 77:   GAMG_PROL,
 78:   GAMG_PROLA,
 79:   GAMG_PROLB,
 80:   GAMG_OPT,
 81:   GAMG_OPTSM,
 82:   GAMG_LEVEL,
 83:   GAMG_PTAP,
 84:   GAMG_REDUCE,
 85:   GAMG_REPART,
 86:   SET13,
 87:   SET14,
 88:   SET15,
 89:   GAMG_NUM_SET
 90: };
 91: PETSC_EXTERN PetscLogEvent petsc_gamg_setup_events[GAMG_NUM_SET];
 92: PETSC_EXTERN PetscLogEvent petsc_gamg_setup_matmat_events[PETSC_MG_MAXLEVELS][3];

 94: typedef struct _PCGAMGHashTable {
 95:   PetscInt *table;
 96:   PetscInt *data;
 97:   PetscInt  size;
 98: } PCGAMGHashTable;

100: PETSC_INTERN PetscErrorCode PCGAMGHashTableCreate(PetscInt, PCGAMGHashTable *);
101: PETSC_INTERN PetscErrorCode PCGAMGHashTableDestroy(PCGAMGHashTable *);
102: PETSC_INTERN PetscErrorCode PCGAMGHashTableAdd(PCGAMGHashTable *, PetscInt, PetscInt);

104: #define GAMG_HASH(key) (PetscInt)((((PetscInt64)7) * (PetscInt64)key) % (PetscInt64)a_tab->size)
105: static inline PetscErrorCode PCGAMGHashTableFind(PCGAMGHashTable *a_tab, PetscInt a_key, PetscInt *a_data)
106: {
107:   PetscInt kk, idx;

109:   PetscFunctionBegin;
110:   PetscCheck(a_key >= 0, PETSC_COMM_SELF, PETSC_ERR_USER, "Negative key %" PetscInt_FMT, a_key);
111:   for (kk = 0, idx = GAMG_HASH(a_key); kk < a_tab->size; kk++, idx = (idx == (a_tab->size - 1)) ? 0 : idx + 1) {
112:     if (a_tab->table[idx] == a_key) {
113:       *a_data = a_tab->data[idx];
114:       break;
115:     } else if (a_tab->table[idx] == -1) {
116:       /* not here */
117:       *a_data = -1;
118:       break;
119:     }
120:   }
121:   PetscCheck(kk != a_tab->size, PETSC_COMM_SELF, PETSC_ERR_USER, "key %" PetscInt_FMT " not found in table", a_key);
122:   PetscFunctionReturn(PETSC_SUCCESS);
123: }