Actual source code: dlregisksp.c
1: #include <petsc/private/pcimpl.h>
2: #include <petsc/private/pcpatchimpl.h>
3: #include <petsc/private/kspimpl.h>
5: static const char *const PCSides_Shifted[] = {"DEFAULT", "LEFT", "RIGHT", "SYMMETRIC", "PCSide", "PC_", NULL};
6: const char *const *const PCSides = PCSides_Shifted + 1;
7: const char *const PCASMTypes[] = {"NONE", "RESTRICT", "INTERPOLATE", "BASIC", "PCASMType", "PC_ASM_", NULL};
8: const char *const PCGASMTypes[] = {"NONE", "RESTRICT", "INTERPOLATE", "BASIC", "PCGASMType", "PC_GASM_", NULL};
9: const char *const PCCompositeTypes[] = {"ADDITIVE", "MULTIPLICATIVE", "SYMMETRIC_MULTIPLICATIVE", "SPECIAL", "SCHUR", "GKB", "PCCompositeType", "PC_COMPOSITE", NULL};
10: const char *const PCPARMSGlobalTypes[] = {"RAS", "SCHUR", "BJ", "PCPARMSGlobalType", "PC_PARMS_", NULL};
11: const char *const PCPARMSLocalTypes[] = {"ILU0", "ILUK", "ILUT", "ARMS", "PCPARMSLocalType", "PC_PARMS_", NULL};
12: const char *const PCPatchConstructTypes[] = {"star", "vanka", "pardecomp", "user", "python", "PCPatchSetConstructType", "PC_PATCH_", NULL};
14: const char *const PCFailedReasons_Shifted[] = {"SETUP_ERROR", "FACTOR_NOERROR", "FACTOR_STRUCT_ZEROPIVOT", "FACTOR_NUMERIC_ZEROPIVOT", "FACTOR_OUTMEMORY", "FACTOR_OTHER", "PC_INCONSISTENT_RHS", "SUBPC_ERROR", NULL};
15: const char *const *const PCFailedReasons = PCFailedReasons_Shifted + 1;
17: static PetscBool PCPackageInitialized = PETSC_FALSE;
19: /*@C
20: PCFinalizePackage - This function destroys everything in the `PC` package. It is
21: called from `PetscFinalize()`.
23: Level: developer
25: .seealso: [](ch_ksp), `PetscFinalize()`, `PCInitializePackage()`
26: @*/
27: PetscErrorCode PCFinalizePackage(void)
28: {
29: PetscFunctionBegin;
30: PetscCall(PetscFunctionListDestroy(&PCList));
31: PetscCall(PetscFunctionListDestroy(&PCMGCoarseList));
32: PCPackageInitialized = PETSC_FALSE;
33: PCRegisterAllCalled = PETSC_FALSE;
34: PetscFunctionReturn(PETSC_SUCCESS);
35: }
37: /*@C
38: PCInitializePackage - This function initializes everything in the `PC` package. It is called
39: from `PetscDLLibraryRegister_petscksp()` when using dynamic libraries, and on the first call to `PCCreate()`
40: when using shared static libraries.
42: Level: developer
44: .seealso: [](ch_ksp), `PetscInitialize()`, `PCFinalizePackage()`
45: @*/
46: PetscErrorCode PCInitializePackage(void)
47: {
48: char logList[256];
49: PetscBool opt, pkg;
51: PetscFunctionBegin;
52: if (PCPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS);
53: PCPackageInitialized = PETSC_TRUE;
54: /* Initialize subpackages */
55: PetscCall(PCGAMGInitializePackage());
56: PetscCall(PCBDDCInitializePackage());
57: #if defined(PETSC_HAVE_HPDDM) && defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)
58: PetscCall(PCHPDDMInitializePackage());
59: #endif
60: /* Register Classes */
61: PetscCall(PetscClassIdRegister("Preconditioner", &PC_CLASSID));
62: /* Register Constructors */
63: PetscCall(PCRegisterAll());
64: /* Register Events */
65: PetscCall(PetscLogEventRegister("PCSetUp", PC_CLASSID, &PC_SetUp));
66: PetscCall(PetscLogEventRegister("PCSetUpOnBlocks", PC_CLASSID, &PC_SetUpOnBlocks));
67: PetscCall(PetscLogEventRegister("PCApply", PC_CLASSID, &PC_Apply));
68: PetscCall(PetscLogEventRegister("PCMatApply", PC_CLASSID, &PC_MatApply));
69: PetscCall(PetscLogEventRegister("PCApplyOnBlocks", PC_CLASSID, &PC_ApplyOnBlocks));
70: PetscCall(PetscLogEventRegister("PCApplyCoarse", PC_CLASSID, &PC_ApplyCoarse));
71: PetscCall(PetscLogEventRegister("PCApplyMultiple", PC_CLASSID, &PC_ApplyMultiple));
72: PetscCall(PetscLogEventRegister("PCApplySymmLeft", PC_CLASSID, &PC_ApplySymmetricLeft));
73: PetscCall(PetscLogEventRegister("PCApplySymmRight", PC_CLASSID, &PC_ApplySymmetricRight));
74: PetscCall(PetscLogEventRegister("PCModifySubMatri", PC_CLASSID, &PC_ModifySubMatrices));
76: PetscCall(PetscLogEventRegister("PCPATCHCreate", PC_CLASSID, &PC_Patch_CreatePatches));
77: PetscCall(PetscLogEventRegister("PCPATCHComputeOp", PC_CLASSID, &PC_Patch_ComputeOp));
78: PetscCall(PetscLogEventRegister("PCPATCHSolve", PC_CLASSID, &PC_Patch_Solve));
79: PetscCall(PetscLogEventRegister("PCPATCHApply", PC_CLASSID, &PC_Patch_Apply));
80: PetscCall(PetscLogEventRegister("PCPATCHPrealloc", PC_CLASSID, &PC_Patch_Prealloc));
82: PetscCall(PetscLogEventRegister("KSPSolve_FS_0", KSP_CLASSID, &KSP_Solve_FS_0));
83: PetscCall(PetscLogEventRegister("KSPSolve_FS_1", KSP_CLASSID, &KSP_Solve_FS_1));
84: PetscCall(PetscLogEventRegister("KSPSolve_FS_2", KSP_CLASSID, &KSP_Solve_FS_2));
85: PetscCall(PetscLogEventRegister("KSPSolve_FS_3", KSP_CLASSID, &KSP_Solve_FS_3));
86: PetscCall(PetscLogEventRegister("KSPSolve_FS_4", KSP_CLASSID, &KSP_Solve_FS_4));
87: PetscCall(PetscLogEventRegister("KSPSolve_FS_Schu", KSP_CLASSID, &KSP_Solve_FS_S));
88: PetscCall(PetscLogEventRegister("KSPSolve_FS_Up", KSP_CLASSID, &KSP_Solve_FS_U));
89: PetscCall(PetscLogEventRegister("KSPSolve_FS_Low", KSP_CLASSID, &KSP_Solve_FS_L));
91: /* Process Info */
92: {
93: PetscClassId classids[1];
95: classids[0] = PC_CLASSID;
96: PetscCall(PetscInfoProcessClass("pc", 1, classids));
97: }
98: /* Process summary exclusions */
99: PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
100: if (opt) {
101: PetscCall(PetscStrInList("pc", logList, ',', &pkg));
102: if (pkg) PetscCall(PetscLogEventExcludeClass(PC_CLASSID));
103: }
104: /* Register data */
105: PetscCall(PetscObjectComposedDataRegister(&PetscMGLevelId));
106: /* Register package finalizer */
107: PetscCall(PetscRegisterFinalize(PCFinalizePackage));
108: PetscFunctionReturn(PETSC_SUCCESS);
109: }
111: const char *const KSPCGTypes[] = {"SYMMETRIC", "HERMITIAN", "KSPCGType", "KSP_CG_", NULL};
112: const char *const KSPGMRESCGSRefinementTypes[] = {"REFINE_NEVER", "REFINE_IFNEEDED", "REFINE_ALWAYS", "KSPGMRESRefinementType", "KSP_GMRES_CGS_", NULL};
113: const char *const KSPNormTypes_Shifted[] = {"DEFAULT", "NONE", "PRECONDITIONED", "UNPRECONDITIONED", "NATURAL", "KSPNormType", "KSP_NORM_", NULL};
114: const char *const *const KSPNormTypes = KSPNormTypes_Shifted + 1;
115: const char *const KSPConvergedReasons_Shifted[] = {"DIVERGED_PC_FAILED", "DIVERGED_INDEFINITE_MAT", "DIVERGED_NANORINF", "DIVERGED_INDEFINITE_PC", "DIVERGED_NONSYMMETRIC", "DIVERGED_BREAKDOWN_BICG", "DIVERGED_BREAKDOWN", "DIVERGED_DTOL", "DIVERGED_ITS", "DIVERGED_NULL", "", "CONVERGED_ITERATING", "CONVERGED_RTOL_NORMAL", "CONVERGED_RTOL", "CONVERGED_ATOL", "CONVERGED_ITS", "CONVERGED_NEG_CURVE", "CONVERGED_STEP_LENGTH", "CONVERGED_HAPPY_BREAKDOWN", "CONVERGED_ATOL_NORMAL", "KSPConvergedReason", "KSP_", NULL};
116: const char *const *KSPConvergedReasons = KSPConvergedReasons_Shifted + 11;
117: const char *const KSPFCDTruncationTypes[] = {"STANDARD", "NOTAY", "KSPFCDTruncationTypes", "KSP_FCD_TRUNC_TYPE_", NULL};
119: static PetscBool KSPPackageInitialized = PETSC_FALSE;
121: /*@C
122: KSPFinalizePackage - This function destroys everything in the `KSP` package. It is
123: called from `PetscFinalize()`.
125: Level: developer
127: .seealso: [](ch_ksp), `PetscFinalize()`, `KSPInitializePackage()`
128: @*/
129: PetscErrorCode KSPFinalizePackage(void)
130: {
131: PetscFunctionBegin;
132: PetscCall(PetscFunctionListDestroy(&KSPList));
133: PetscCall(PetscFunctionListDestroy(&KSPGuessList));
134: PetscCall(PetscFunctionListDestroy(&KSPMonitorList));
135: PetscCall(PetscFunctionListDestroy(&KSPMonitorCreateList));
136: PetscCall(PetscFunctionListDestroy(&KSPMonitorDestroyList));
137: KSPPackageInitialized = PETSC_FALSE;
138: KSPRegisterAllCalled = PETSC_FALSE;
139: KSPMonitorRegisterAllCalled = PETSC_FALSE;
140: PetscFunctionReturn(PETSC_SUCCESS);
141: }
143: /*@C
144: KSPInitializePackage - This function initializes everything in the `KSP` package. It is called
145: from `PetscDLLibraryRegister_petscksp()` when using dynamic libraries, and on the first call to `KSPCreate()`
146: when using shared or static libraries.
148: Level: developer
150: .seealso: [](ch_ksp), `PetscInitialize()`, `KSPFinalizePackage()`
151: @*/
152: PetscErrorCode KSPInitializePackage(void)
153: {
154: char logList[256];
155: PetscBool opt, pkg, cls;
157: PetscFunctionBegin;
158: if (KSPPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS);
159: KSPPackageInitialized = PETSC_TRUE;
160: /* Register Classes */
161: PetscCall(PetscClassIdRegister("Krylov Solver", &KSP_CLASSID));
162: PetscCall(PetscClassIdRegister("DMKSP interface", &DMKSP_CLASSID));
163: PetscCall(PetscClassIdRegister("KSPGuess interface", &KSPGUESS_CLASSID));
164: /* Register Constructors */
165: PetscCall(KSPRegisterAll());
166: /* Register matrix implementations packaged in KSP */
167: PetscCall(KSPMatRegisterAll());
168: /* Register KSP guesses implementations */
169: PetscCall(KSPGuessRegisterAll());
170: /* Register Monitors */
171: PetscCall(KSPMonitorRegisterAll());
172: /* Register Events */
173: PetscCall(PetscLogEventRegister("KSPSetUp", KSP_CLASSID, &KSP_SetUp));
174: PetscCall(PetscLogEventRegister("KSPSolve", KSP_CLASSID, &KSP_Solve));
175: PetscCall(PetscLogEventRegister("KSPGMRESOrthog", KSP_CLASSID, &KSP_GMRESOrthogonalization));
176: PetscCall(PetscLogEventRegister("KSPSolveTranspos", KSP_CLASSID, &KSP_SolveTranspose));
177: PetscCall(PetscLogEventRegister("KSPMatSolve", KSP_CLASSID, &KSP_MatSolve));
178: PetscCall(PetscLogEventRegister("KSPMatSolveTrans", KSP_CLASSID, &KSP_MatSolveTranspose));
179: /* Process Info */
180: {
181: PetscClassId classids[3];
183: classids[0] = KSP_CLASSID;
184: classids[1] = DMKSP_CLASSID;
185: classids[2] = KSPGUESS_CLASSID;
186: PetscCall(PetscInfoProcessClass("ksp", 1, &classids[0]));
187: PetscCall(PetscInfoProcessClass("dm", 1, &classids[1]));
188: PetscCall(PetscInfoProcessClass("kspguess", 1, &classids[2]));
189: }
190: /* Process summary exclusions */
191: PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
192: if (opt) {
193: PetscCall(PetscStrInList("ksp", logList, ',', &pkg));
194: if (pkg) PetscCall(PetscLogEventExcludeClass(KSP_CLASSID));
195: PetscCall(PetscStrInList("dm", logList, ',', &cls));
196: if (pkg || cls) PetscCall(PetscLogEventExcludeClass(DMKSP_CLASSID));
197: PetscCall(PetscStrInList("kspguess", logList, ',', &cls));
198: if (pkg || cls) PetscCall(PetscLogEventExcludeClass(KSPGUESS_CLASSID));
199: }
200: /* Register package finalizer */
201: PetscCall(PetscRegisterFinalize(KSPFinalizePackage));
202: PetscFunctionReturn(PETSC_SUCCESS);
203: }
205: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
207: /*
208: PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.
210: This one registers all the `KSP` and `PC` methods that are in the basic PETSc libpetscksp library.
211: */
212: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscksp(void)
213: {
214: PetscFunctionBegin;
215: PetscCall(PCInitializePackage());
216: PetscCall(KSPInitializePackage());
217: PetscFunctionReturn(PETSC_SUCCESS);
218: }
220: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */