Actual source code: pcgamgimpl.h
3: #include <petscksp.h>
4: #include <petsc/private/pcimpl.h>
5: #include <petsc/private/pcmgimpl.h>
6: #include <petscmatcoarsen.h>
8: struct _PCGAMGOps {
9: PetscErrorCode (*graph)(PC, Mat, Mat*);
10: PetscErrorCode (*coarsen)(PC, Mat*, PetscCoarsenData**);
11: PetscErrorCode (*prolongator)(PC, Mat, 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)(PetscOptionItems*,PC);
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 coarse_eq_limit;
31: PetscReal threshold_scale;
32: PetscReal threshold[PETSC_MG_MAXLEVELS]; /* common quatity to many AMG methods so keep it up here */
33: PetscInt level_reduction_factors[PETSC_MG_MAXLEVELS];
34: PetscInt current_level; /* stash construction state */
35: /* these 4 are all related to the method data and should be in the subctx */
36: PetscInt data_sz; /* nloc*data_rows*data_cols */
37: PetscInt data_cell_rows;
38: PetscInt data_cell_cols;
39: PetscInt orig_data_cell_rows;
40: PetscInt orig_data_cell_cols;
41: PetscReal *data; /* [data_sz] blocked vector of vertex data on fine grid (coordinates/nullspace) */
42: PetscReal *orig_data; /* cache data */
44: struct _PCGAMGOps *ops;
45: char *gamg_type_name;
47: void *subctx;
49: PetscBool use_sa_esteig;
50: PetscReal emin,emax;
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 PCGAMGCreateGraph(Mat, Mat*);
64: PetscErrorCode PCGAMGFilterGraph(Mat*, PetscReal, PetscBool);
65: PetscErrorCode PCGAMGGetDataWithGhosts(Mat, PetscInt, PetscReal[],PetscInt*, PetscReal **);
67: enum tag {SET1,SET2,GRAPH,GRAPH_MAT,GRAPH_FILTER,GRAPH_SQR,SET4,SET5,SET6,FIND_V,SET7,SET8,SET9,SET10,SET11,SET12,SET13,SET14,SET15,SET16,NUM_SET};
68: PETSC_EXTERN PetscLogEvent petsc_gamg_setup_events[NUM_SET];
69: PETSC_EXTERN PetscLogEvent PC_GAMGGraph_AGG;
70: PETSC_EXTERN PetscLogEvent PC_GAMGGraph_GEO;
71: PETSC_EXTERN PetscLogEvent PC_GAMGCoarsen_AGG;
72: PETSC_EXTERN PetscLogEvent PC_GAMGCoarsen_GEO;
73: PETSC_EXTERN PetscLogEvent PC_GAMGProlongator_AGG;
74: PETSC_EXTERN PetscLogEvent PC_GAMGProlongator_GEO;
75: PETSC_EXTERN PetscLogEvent PC_GAMGOptProlongator_AGG;
76: PETSC_EXTERN PetscLogEvent petsc_gamg_setup_matmat_events[PETSC_MG_MAXLEVELS][3];
78: typedef struct _PCGAMGHashTable {
79: PetscInt *table;
80: PetscInt *data;
81: PetscInt size;
82: } PCGAMGHashTable;
84: PETSC_INTERN PetscErrorCode PCGAMGHashTableCreate(PetscInt, PCGAMGHashTable*);
85: PETSC_INTERN PetscErrorCode PCGAMGHashTableDestroy(PCGAMGHashTable*);
86: PETSC_INTERN PetscErrorCode PCGAMGHashTableAdd(PCGAMGHashTable*,PetscInt,PetscInt);
88: #define GAMG_HASH(key) (PetscInt)((((PetscInt64)7)*(PetscInt64)key)%(PetscInt64)a_tab->size)
89: static inline PetscErrorCode PCGAMGHashTableFind(PCGAMGHashTable *a_tab, PetscInt a_key, PetscInt *a_data)
90: {
91: PetscInt kk,idx;
94: for (kk = 0, idx = GAMG_HASH(a_key); kk < a_tab->size; kk++, idx = (idx==(a_tab->size-1)) ? 0 : idx + 1) {
95: if (a_tab->table[idx] == a_key) {
96: *a_data = a_tab->data[idx];
97: break;
98: } else if (a_tab->table[idx] == -1) {
99: /* not here */
100: *a_data = -1;
101: break;
102: }
103: }
105: return 0;
106: }
108: #endif