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>
7: struct _PCGAMGOps {
8: PetscErrorCode (*creategraph)(PC, Mat, Mat *);
9: PetscErrorCode (*coarsen)(PC, Mat *, PetscCoarsenData **);
10: PetscErrorCode (*prolongator)(PC, Mat, Mat, PetscCoarsenData *, Mat *);
11: PetscErrorCode (*optprolongator)(PC, Mat, Mat *);
12: PetscErrorCode (*createlevel)(PC, Mat, PetscInt, Mat *, Mat *, PetscMPIInt *, IS *, PetscBool);
13: PetscErrorCode (*createdefaultdata)(PC, Mat); /* for data methods that have a default (SA) */
14: PetscErrorCode (*setfromoptions)(PC, PetscOptionItems *);
15: PetscErrorCode (*destroy)(PC);
16: PetscErrorCode (*view)(PC, PetscViewer);
17: };
18: /* Private context for the GAMG preconditioner */
19: typedef struct gamg_TAG {
20: PCGAMGType type;
21: PetscInt Nlevels;
22: PetscBool repart;
23: PetscBool reuse_prol;
24: PetscBool use_aggs_in_asm;
25: PetscBool use_parallel_coarse_grid_solver;
26: PCGAMGLayoutType layout_type;
27: PetscBool cpu_pin_coarse_grids;
28: PetscInt min_eq_proc;
29: PetscInt coarse_eq_limit;
30: PetscReal threshold_scale;
31: PetscReal threshold[PETSC_MG_MAXLEVELS]; /* common quatity to many AMG methods so keep it up here */
32: PetscInt level_reduction_factors[PETSC_MG_MAXLEVELS];
33: PetscInt current_level; /* stash construction state */
34: /* these 4 are all related to the method data and should be in the subctx */
35: PetscInt data_sz; /* nloc*data_rows*data_cols */
36: PetscInt data_cell_rows;
37: PetscInt data_cell_cols;
38: PetscInt orig_data_cell_rows;
39: PetscInt orig_data_cell_cols;
40: PetscReal *data; /* [data_sz] blocked vector of vertex data on fine grid (coordinates/nullspace) */
41: PetscReal *orig_data; /* cache data */
43: struct _PCGAMGOps *ops;
44: char *gamg_type_name;
46: void *subctx;
48: PetscBool use_sa_esteig;
49: PetscReal emin, emax;
50: PetscBool recompute_esteig;
51: } PC_GAMG;
53: PetscErrorCode PCReset_MG(PC);
55: /* hooks create derivied classes */
56: PetscErrorCode PCCreateGAMG_GEO(PC);
57: PetscErrorCode PCCreateGAMG_AGG(PC);
58: PetscErrorCode PCCreateGAMG_Classical(PC);
60: PetscErrorCode PCDestroy_GAMG(PC);
62: /* helper methods */
63: PetscErrorCode PCGAMGGetDataWithGhosts(Mat, PetscInt, PetscReal[], PetscInt *, PetscReal **);
65: enum tag {
66: GAMG_SETUP = 0,
67: GAMG_MESH,
68: GAMG_MATRIX,
69: GAMG_GRAPH,
70: GAMG_COARSEN,
71: GAMG_SQUARE,
72: GAMG_MIS,
73: GAMG_PROL,
74: GAMG_PROLA,
75: GAMG_PROLB,
76: GAMG_OPT,
77: GAMG_OPTSM,
78: GAMG_LEVEL,
79: GAMG_PTAP,
80: GAMG_REDUCE,
81: GAMG_REPART,
82: SET13,
83: SET14,
84: SET15,
85: GAMG_NUM_SET
86: };
87: PETSC_EXTERN PetscLogEvent petsc_gamg_setup_events[GAMG_NUM_SET];
88: PETSC_EXTERN PetscLogEvent petsc_gamg_setup_matmat_events[PETSC_MG_MAXLEVELS][3];
90: typedef struct _PCGAMGHashTable {
91: PetscInt *table;
92: PetscInt *data;
93: PetscInt size;
94: } PCGAMGHashTable;
96: PETSC_INTERN PetscErrorCode PCGAMGHashTableCreate(PetscInt, PCGAMGHashTable *);
97: PETSC_INTERN PetscErrorCode PCGAMGHashTableDestroy(PCGAMGHashTable *);
98: PETSC_INTERN PetscErrorCode PCGAMGHashTableAdd(PCGAMGHashTable *, PetscInt, PetscInt);
100: #define GAMG_HASH(key) (PetscInt)((((PetscInt64)7) * (PetscInt64)key) % (PetscInt64)a_tab->size)
101: static inline PetscErrorCode PCGAMGHashTableFind(PCGAMGHashTable *a_tab, PetscInt a_key, PetscInt *a_data)
102: {
103: PetscInt kk, idx;
105: PetscFunctionBegin;
106: PetscCheck(a_key >= 0, PETSC_COMM_SELF, PETSC_ERR_USER, "Negative key %" PetscInt_FMT, a_key);
107: for (kk = 0, idx = GAMG_HASH(a_key); kk < a_tab->size; kk++, idx = (idx == (a_tab->size - 1)) ? 0 : idx + 1) {
108: if (a_tab->table[idx] == a_key) {
109: *a_data = a_tab->data[idx];
110: break;
111: } else if (a_tab->table[idx] == -1) {
112: /* not here */
113: *a_data = -1;
114: break;
115: }
116: }
117: PetscCheck(kk != a_tab->size, PETSC_COMM_SELF, PETSC_ERR_USER, "key %" PetscInt_FMT " not found in table", a_key);
118: PetscFunctionReturn(PETSC_SUCCESS);
119: }