Actual source code: pcgamgimpl.h
petsc-3.12.1 2019-10-22
3: #include <petsc/private/pcimpl.h>
4: #include <petsc/private/pcmgimpl.h>
5: #include <petscmatcoarsen.h>
7: struct _PCGAMGOps {
8: PetscErrorCode (*graph)(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)(PetscOptionItems*,PC);
15: PetscErrorCode (*destroy)(PC);
16: PetscErrorCode (*view)(PC,PetscViewer);
17: };
18: #define PETSC_GAMG_MAXLEVELS 30
19: /* Private context for the GAMG preconditioner */
20: typedef struct gamg_TAG {
21: PCGAMGType type;
22: PetscInt Nlevels;
23: PetscInt setup_count;
24: PetscBool repart;
25: PetscBool reuse_prol;
26: PetscBool use_aggs_in_asm;
27: PetscBool use_parallel_coarse_grid_solver;
28: PCGAMGLayoutType layout_type;
29: PetscBool cpu_pin_coarse_grids;
30: PetscInt min_eq_proc;
31: PetscInt coarse_eq_limit;
32: PetscReal threshold_scale;
33: PetscInt current_level; /* stash construction state */
34: PetscReal threshold[PETSC_GAMG_MAXLEVELS]; /* common quatity to many AMG methods so keep it up here */
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;
49: } PC_GAMG;
51: PetscErrorCode PCReset_MG(PC);
53: /* hooks create derivied classes */
54: PetscErrorCode PCCreateGAMG_GEO(PC);
55: PetscErrorCode PCCreateGAMG_AGG(PC);
56: PetscErrorCode PCCreateGAMG_Classical(PC);
58: PetscErrorCode PCDestroy_GAMG(PC);
60: /* helper methods */
61: PetscErrorCode PCGAMGCreateGraph(Mat, Mat*);
62: PetscErrorCode PCGAMGFilterGraph(Mat*, PetscReal, PetscBool);
63: PetscErrorCode PCGAMGGetDataWithGhosts(Mat, PetscInt, PetscReal[],PetscInt*, PetscReal **);
65: #if defined PETSC_USE_LOG
66: #define PETSC_GAMG_USE_LOG
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: #if defined PETSC_GAMG_USE_LOG
69: PETSC_EXTERN PetscLogEvent petsc_gamg_setup_events[NUM_SET];
70: #endif
71: PETSC_EXTERN PetscLogEvent PC_GAMGGraph_AGG;
72: PETSC_EXTERN PetscLogEvent PC_GAMGGraph_GEO;
73: PETSC_EXTERN PetscLogEvent PC_GAMGCoarsen_AGG;
74: PETSC_EXTERN PetscLogEvent PC_GAMGCoarsen_GEO;
75: PETSC_EXTERN PetscLogEvent PC_GAMGProlongator_AGG;
76: PETSC_EXTERN PetscLogEvent PC_GAMGProlongator_GEO;
77: PETSC_EXTERN PetscLogEvent PC_GAMGOptProlongator_AGG;
78: #endif
80: typedef struct _PCGAMGHashTable {
81: PetscInt *table;
82: PetscInt *data;
83: PetscInt size;
84: } PCGAMGHashTable;
87: PETSC_INTERN PetscErrorCode PCGAMGHashTableCreate(PetscInt, PCGAMGHashTable*);
88: PETSC_INTERN PetscErrorCode PCGAMGHashTableDestroy(PCGAMGHashTable*);
89: PETSC_INTERN PetscErrorCode PCGAMGHashTableAdd(PCGAMGHashTable*,PetscInt,PetscInt);
91: #define GAMG_HASH(key) (PetscInt)((((PetscInt64)7)*(PetscInt64)key)%(PetscInt64)a_tab->size)
92: PETSC_STATIC_INLINE PetscErrorCode PCGAMGHashTableFind(PCGAMGHashTable *a_tab, PetscInt a_key, PetscInt *a_data)
93: {
94: PetscInt kk,idx;
97: if (a_key<0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_USER,"Negative key %D.",a_key);
98: for (kk = 0, idx = GAMG_HASH(a_key); kk < a_tab->size; kk++, idx = (idx==(a_tab->size-1)) ? 0 : idx + 1) {
99: if (a_tab->table[idx] == a_key) {
100: *a_data = a_tab->data[idx];
101: break;
102: } else if (a_tab->table[idx] == -1) {
103: /* not here */
104: *a_data = -1;
105: break;
106: }
107: }
108: if (kk==a_tab->size) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_USER,"key %D not found in table",a_key);
109: return(0);
110: }
112: #endif