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: .seealso: `TaoCreate()`, `TaoFinalizePackage()`, `TaoRegister()`, `TaoRegisterAll()`
 30: @*/
 31: PetscErrorCode TaoInitializePackage(void)
 32: {
 33:   char      logList[256];
 34:   PetscBool opt, pkg;

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

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

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

 74:   This registers all of the Tao methods that are in the libtao
 75:   library.

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