xref: /petsc/src/tao/interface/dlregistao.c (revision bcd4bb4a4158aa96f212e9537e87b40407faf83e)
1 #include <petsc/private/taoimpl.h>
2 
3 static PetscBool TaoPackageInitialized = PETSC_FALSE;
4 
5 /*@C
6   TaoFinalizePackage - This function destroys everything in the PETSc/Tao
7   interface to the Tao package. It is called from `PetscFinalize()`.
8 
9   Level: developer
10 
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 }
20 
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()
26 
27   Level: developer
28 
29   Note:
30   This function never needs to be called by PETSc users.
31 
32 .seealso: `TaoCreate()`, `TaoFinalizePackage()`, `TaoRegister()`, `TaoRegisterAll()`
33 @*/
34 PetscErrorCode TaoInitializePackage(void)
35 {
36   char      logList[256];
37   PetscBool opt, pkg;
38 
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];
57 
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 }
71 
72 #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
73 /*
74   PetscDLLibraryRegister - this function is called when the dynamic library it
75   is in is opened.
76 
77   This registers all of the Tao methods that are in the libtao
78   library.
79 
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 */
91