Date: 2026-07-30T21:14:08+00:00

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("PCApplySymmLeft", PC_CLASSID, &PC_ApplySymmetricLeft));
     72:   PetscCall(PetscLogEventRegister("PCApplySymmRight", PC_CLASSID, &PC_ApplySymmetricRight));
     73:   PetscCall(PetscLogEventRegister("PCModifySubMatri", PC_CLASSID, &PC_ModifySubMatrices));

     75:   PetscCall(PetscLogEventRegister("PCPATCHCreate", PC_CLASSID, &PC_Patch_CreatePatches));
     76:   PetscCall(PetscLogEventRegister("PCPATCHComputeOp", PC_CLASSID, &PC_Patch_ComputeOp));
     77:   PetscCall(PetscLogEventRegister("PCPATCHSolve", PC_CLASSID, &PC_Patch_Solve));
     78:   PetscCall(PetscLogEventRegister("PCPATCHApply", PC_CLASSID, &PC_Patch_Apply));
     79:   PetscCall(PetscLogEventRegister("PCPATCHPrealloc", PC_CLASSID, &PC_Patch_Prealloc));

     81:   PetscCall(PetscLogEventRegister("KSPSolve_FS_0", KSP_CLASSID, &KSP_Solve_FS_0));
     82:   PetscCall(PetscLogEventRegister("KSPSolve_FS_1", KSP_CLASSID, &KSP_Solve_FS_1));
     83:   PetscCall(PetscLogEventRegister("KSPSolve_FS_2", KSP_CLASSID, &KSP_Solve_FS_2));
     84:   PetscCall(PetscLogEventRegister("KSPSolve_FS_3", KSP_CLASSID, &KSP_Solve_FS_3));
     85:   PetscCall(PetscLogEventRegister("KSPSolve_FS_4", KSP_CLASSID, &KSP_Solve_FS_4));
     86:   PetscCall(PetscLogEventRegister("KSPSolve_FS_Schu", KSP_CLASSID, &KSP_Solve_FS_S));
     87:   PetscCall(PetscLogEventRegister("KSPSolve_FS_Up", KSP_CLASSID, &KSP_Solve_FS_U));
     88:   PetscCall(PetscLogEventRegister("KSPSolve_FS_Low", KSP_CLASSID, &KSP_Solve_FS_L));

     90:   /* Process Info */
     91:   {
     92:     PetscClassId classids[1];

     94:     classids[0] = PC_CLASSID;
     95:     PetscCall(PetscInfoProcessClass("pc", 1, classids));
     96:   }
     97:   /* Process summary exclusions */
     98:   PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
     99:   if (opt) {
    100:     PetscCall(PetscStrInList("pc", logList, ',', &pkg));
    101:     if (pkg) PetscCall(PetscLogEventExcludeClass(PC_CLASSID));
    102:   }
    103:   /* Register data */
    104:   PetscCall(PetscObjectComposedDataRegister(&PetscMGLevelId));
    105:   /* Register package finalizer */
    106:   PetscCall(PetscRegisterFinalize(PCFinalizePackage));
    107:   PetscFunctionReturn(PETSC_SUCCESS);
    108: }

    110: const char *const        KSPCGTypes[]                 = {"SYMMETRIC", "HERMITIAN", "KSPCGType", "KSP_CG_", NULL};
    111: const char *const        KSPGMRESCGSRefinementTypes[] = {"REFINE_NEVER", "REFINE_IFNEEDED", "REFINE_ALWAYS", "KSPGMRESRefinementType", "KSP_GMRES_CGS_", NULL};
    112: const char *const        KSPNormTypes_Shifted[]       = {"DEFAULT", "NONE", "PRECONDITIONED", "UNPRECONDITIONED", "NATURAL", "KSPNormType", "KSP_NORM_", NULL};
    113: const char *const *const KSPNormTypes                 = KSPNormTypes_Shifted + 1;
    114: const char *const KSPConvergedReasons_Shifted[] = {"DIVERGED_USER", "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_EQUATIONS", "CONVERGED_RTOL", "CONVERGED_ATOL", "CONVERGED_ITS", "CONVERGED_NEG_CURVE", "CONVERGED_STEP_LENGTH", "CONVERGED_HAPPY_BREAKDOWN", "CONVERGED_USER", "CONVERGED_ATOL_NORMAL_EQUATIONS", "KSPConvergedReason", "KSP_", NULL};
    115: const char *const *KSPConvergedReasons     = KSPConvergedReasons_Shifted + 12;
    116: const char *const  KSPFCDTruncationTypes[] = {"STANDARD", "NOTAY", "KSPFCDTruncationTypes", "KSP_FCD_TRUNC_TYPE_", NULL};

    118: static PetscBool KSPPackageInitialized = PETSC_FALSE;

    120: /*@C
    121:   KSPFinalizePackage - This function destroys everything in the `KSP` package. It is
    122:   called from `PetscFinalize()`.

    124:   Level: developer

    126: .seealso: [](ch_ksp), `PetscFinalize()`, `KSPInitializePackage()`
    127: @*/
    128: PetscErrorCode KSPFinalizePackage(void)
    129: {
    130:   PetscFunctionBegin;
    131:   PetscCall(PetscFunctionListDestroy(&KSPList));
    132:   PetscCall(PetscFunctionListDestroy(&KSPGuessList));
    133:   PetscCall(PetscFunctionListDestroy(&KSPMonitorList));
    134:   PetscCall(PetscFunctionListDestroy(&KSPMonitorCreateList));
    135:   PetscCall(PetscFunctionListDestroy(&KSPMonitorDestroyList));
    136:   KSPPackageInitialized       = PETSC_FALSE;
    137:   KSPRegisterAllCalled        = PETSC_FALSE;
    138:   KSPMonitorRegisterAllCalled = PETSC_FALSE;
    139:   PetscFunctionReturn(PETSC_SUCCESS);
    140: }

    142: /*@C
    143:   KSPInitializePackage - This function initializes everything in the `KSP` package. It is called
    144:   from `PetscDLLibraryRegister_petscksp()` when using dynamic libraries, and on the first call to `KSPCreate()`
    145:   when using shared or static libraries.

    147:   Level: developer

    149:   Note:
    150:   This function never needs to be called by PETSc users.

    152: .seealso: [](ch_ksp), `PetscInitialize()`, `KSPFinalizePackage()`
    153: @*/
    154: PetscErrorCode KSPInitializePackage(void)
    155: {
    156:   char      logList[256];
    157:   PetscBool opt, pkg, cls;

    159:   PetscFunctionBegin;
    160:   if (KSPPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS);
    161:   KSPPackageInitialized = PETSC_TRUE;
    162:   /* Register Classes */
    163:   PetscCall(PetscClassIdRegister("Krylov Solver", &KSP_CLASSID));
    164:   PetscCall(PetscClassIdRegister("DMKSP interface", &DMKSP_CLASSID));
    165:   PetscCall(PetscClassIdRegister("KSPGuess interface", &KSPGUESS_CLASSID));
    166:   /* Register Constructors */
    167:   PetscCall(KSPRegisterAll());
    168:   /* Register matrix implementations packaged in KSP */
    169:   PetscCall(KSPMatRegisterAll());
    170:   /* Register KSP guesses implementations */
    171:   PetscCall(KSPGuessRegisterAll());
    172:   /* Register Monitors */
    173:   PetscCall(KSPMonitorRegisterAll());
    174:   /* Register Events */
    175:   PetscCall(PetscLogEventRegister("KSPSetUp", KSP_CLASSID, &KSP_SetUp));
    176:   PetscCall(PetscLogEventRegister("KSPSolve", KSP_CLASSID, &KSP_Solve));
    177:   PetscCall(PetscLogEventRegister("KSPGMRESOrthog", KSP_CLASSID, &KSP_GMRESOrthogonalization));
    178:   PetscCall(PetscLogEventRegister("KSPSolveTranspos", KSP_CLASSID, &KSP_SolveTranspose));
    179:   PetscCall(PetscLogEventRegister("KSPMatSolve", KSP_CLASSID, &KSP_MatSolve));
    180:   PetscCall(PetscLogEventRegister("KSPMatSolveTrans", KSP_CLASSID, &KSP_MatSolveTranspose));
    181:   /* Process Info */
    182:   {
    183:     PetscClassId classids[3];

    185:     classids[0] = KSP_CLASSID;
    186:     classids[1] = DMKSP_CLASSID;
    187:     classids[2] = KSPGUESS_CLASSID;
    188:     PetscCall(PetscInfoProcessClass("ksp", 1, &classids[0]));
    189:     PetscCall(PetscInfoProcessClass("dm", 1, &classids[1]));
    190:     PetscCall(PetscInfoProcessClass("kspguess", 1, &classids[2]));
    191:   }
    192:   /* Process summary exclusions */
    193:   PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
    194:   if (opt) {
    195:     PetscCall(PetscStrInList("ksp", logList, ',', &pkg));
    196:     if (pkg) PetscCall(PetscLogEventExcludeClass(KSP_CLASSID));
    197:     PetscCall(PetscStrInList("dm", logList, ',', &cls));
    198:     if (pkg || cls) PetscCall(PetscLogEventExcludeClass(DMKSP_CLASSID));
    199:     PetscCall(PetscStrInList("kspguess", logList, ',', &cls));
    200:     if (pkg || cls) PetscCall(PetscLogEventExcludeClass(KSPGUESS_CLASSID));
    201:   }
    202:   /* Register package finalizer */
    203:   PetscCall(PetscRegisterFinalize(KSPFinalizePackage));
    204:   PetscFunctionReturn(PETSC_SUCCESS);
    205: }

    207: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)

    209: /*
    210:   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.

    212:   This one registers all the `KSP` and `PC` methods that are in the basic PETSc libpetscksp library.
    213:  */
    214: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscksp(void)
    215: {
    216:   PetscFunctionBegin;
    217:   PetscCall(PCInitializePackage());
    218:   PetscCall(KSPInitializePackage());
    219:   PetscFunctionReturn(PETSC_SUCCESS);
    220: }

    222: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */