Actual source code: dlregistao.c

      1: #include <petsc/private/taoimpl.h>

      3: static PetscBool TaoPackageInitialized = PETSC_FALSE;

      5: /*@C
      6:   TaoFinalizePackage - This function destroys everything in the PETSc/Tao
      7:   interface to the Tao package. It is called from `PetscFinalize()`.

      9:   Level: developer

     11: .seealso: `TaoInitializePackage()`, `PetscFinalize()`, `TaoRegister()`, `TaoRegisterAll()`
     12: @*/
     13: PetscErrorCode TaoFinalizePackage(void)
     14: {
     15:   PetscFunctionBegin;
     16:   PetscCall(PetscFunctionListDestroy(&TaoList));
     17:   PetscCall(PetscFunctionListDestroy(&TaoTermList));
     18:   TaoPackageInitialized = PETSC_FALSE;
     19:   PetscFunctionReturn(PETSC_SUCCESS);
     20: }

     22: /*@C
     23:   TaoInitializePackage - This function sets up PETSc to use the Tao
     24:   package.  When using static or shared libraries, this function is called from the
     25:   first entry to `TaoCreate()`; when using shared or static libraries, it is called
     26:   from PetscDLLibraryRegister_tao()

     28:   Level: developer

     30:   Note:
     31:   This function never needs to be called by PETSc users.

     33: .seealso: `TaoCreate()`, `TaoFinalizePackage()`, `TaoRegister()`, `TaoRegisterAll()`
     34: @*/
     35: PetscErrorCode TaoInitializePackage(void)
     36: {
     37:   char      logList[256];
     38:   PetscBool opt, pkg;

     40:   PetscFunctionBegin;
     41:   if (TaoPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS);
     42:   TaoPackageInitialized = PETSC_TRUE;
     43:   /* Register Classes */
     44:   PetscCall(PetscClassIdRegister("Tao", &TAO_CLASSID));
     45:   PetscCall(PetscClassIdRegister("TaoTerm", &TAOTERM_CLASSID));
     46:   /* Register Constructors */
     47:   PetscCall(TaoRegisterAll());
     48:   PetscCall(TaoTermRegisterAll());
     49:   /* Register Events */
     50:   PetscCall(PetscLogEventRegister("TaoSolve", TAO_CLASSID, &TAO_Solve));
     51:   PetscCall(PetscLogEventRegister("TaoTermObjEval", TAOTERM_CLASSID, &TAOTERM_ObjectiveEval));
     52:   PetscCall(PetscLogEventRegister("TaoTermGradEval", TAOTERM_CLASSID, &TAOTERM_GradientEval));
     53:   PetscCall(PetscLogEventRegister("TaoTermObjGrad", TAOTERM_CLASSID, &TAOTERM_ObjGradEval));
     54:   PetscCall(PetscLogEventRegister("TaoTermHessEval", TAOTERM_CLASSID, &TAOTERM_HessianEval));
     55:   PetscCall(PetscLogEventRegister("TaoResidualEval", TAO_CLASSID, &TAO_ResidualEval));
     56:   PetscCall(PetscLogEventRegister("TaoConstrEval", TAO_CLASSID, &TAO_ConstraintsEval));
     57:   PetscCall(PetscLogEventRegister("TaoJacobianEval", TAO_CLASSID, &TAO_JacobianEval));
     58:   /* Process Info */
     59:   {
     60:     PetscClassId classids[2];

     62:     classids[0] = TAO_CLASSID;
     63:     classids[1] = TAOTERM_CLASSID;
     64:     PetscCall(PetscInfoProcessClass("tao", 1, classids));
     65:     PetscCall(PetscInfoProcessClass("taoterm", 1, &classids[1]));
     66:   }
     67:   /* Process summary exclusions */
     68:   PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
     69:   if (opt) {
     70:     PetscCall(PetscStrInList("tao", logList, ',', &pkg));
     71:     if (pkg) PetscCall(PetscLogEventExcludeClass(TAO_CLASSID));
     72:     PetscCall(PetscStrInList("taoterm", logList, ',', &pkg));
     73:     if (pkg) PetscCall(PetscLogEventExcludeClass(TAOTERM_CLASSID));
     74:   }
     75:   /* Register package finalizer */
     76:   PetscCall(PetscRegisterFinalize(TaoFinalizePackage));
     77:   PetscFunctionReturn(PETSC_SUCCESS);
     78: }

     80: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
     81: /*
     82:   PetscDLLibraryRegister - this function is called when the dynamic library it
     83:   is in is opened.

     85:   This registers all of the Tao methods that are in the libtao
     86:   library.

     88:   Input Parameter:
     89: . path - library path
     90: */
     91: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petsctao(void)
     92: {
     93:   PetscFunctionBegin;
     94:   PetscCall(TaoInitializePackage());
     95:   PetscCall(TaoLineSearchInitializePackage());
     96:   PetscFunctionReturn(PETSC_SUCCESS);
     97: }
     98: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */