Date: 2025-03-28T21:10:52+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("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:   Note:
    151:   This function never needs to be called by PETSc users.

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

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

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

    208: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)

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

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

    223: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */