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:   TaoPackageInitialized = PETSC_FALSE;
     18:   PetscFunctionReturn(PETSC_SUCCESS);
     19: }

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

     27:   Level: developer

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

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

     39:   PetscFunctionBegin;
     40:   if (TaoPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS);
     41:   TaoPackageInitialized = PETSC_TRUE;
     42:   /* Register Classes */
     43:   PetscCall(PetscClassIdRegister("Tao", &TAO_CLASSID));
     44:   /* Register Constructors */
     45:   PetscCall(TaoRegisterAll());
     46:   /* Register Events */
     47:   PetscCall(PetscLogEventRegister("TaoSolve", TAO_CLASSID, &TAO_Solve));
     48:   PetscCall(PetscLogEventRegister("TaoObjectiveEval", TAO_CLASSID, &TAO_ObjectiveEval));
     49:   PetscCall(PetscLogEventRegister("TaoGradientEval", TAO_CLASSID, &TAO_GradientEval));
     50:   PetscCall(PetscLogEventRegister("TaoObjGradEval", TAO_CLASSID, &TAO_ObjGradEval));
     51:   PetscCall(PetscLogEventRegister("TaoHessianEval", TAO_CLASSID, &TAO_HessianEval));
     52:   PetscCall(PetscLogEventRegister("TaoConstrEval", TAO_CLASSID, &TAO_ConstraintsEval));
     53:   PetscCall(PetscLogEventRegister("TaoJacobianEval", TAO_CLASSID, &TAO_JacobianEval));
     54:   /* Process Info */
     55:   {
     56:     PetscClassId classids[1];

     58:     classids[0] = TAO_CLASSID;
     59:     PetscCall(PetscInfoProcessClass("tao", 1, classids));
     60:   }
     61:   /* Process summary exclusions */
     62:   PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
     63:   if (opt) {
     64:     PetscCall(PetscStrInList("tao", logList, ',', &pkg));
     65:     if (pkg) PetscCall(PetscLogEventExcludeClass(TAO_CLASSID));
     66:   }
     67:   /* Register package finalizer */
     68:   PetscCall(PetscRegisterFinalize(TaoFinalizePackage));
     69:   PetscFunctionReturn(PETSC_SUCCESS);
     70: }

     72: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
     73: /*
     74:   PetscDLLibraryRegister - this function is called when the dynamic library it
     75:   is in is opened.

     77:   This registers all of the Tao methods that are in the libtao
     78:   library.

     80:   Input Parameter:
     81: . path - library path
     82: */
     83: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petsctao(void)
     84: {
     85:   PetscFunctionBegin;
     86:   PetscCall(TaoInitializePackage());
     87:   PetscCall(TaoLineSearchInitializePackage());
     88:   PetscFunctionReturn(PETSC_SUCCESS);
     89: }
     90: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */