xref: /petsc/src/tao/interface/dlregistao.c (revision 73fdd05bb67e49f40fd8fd311695ff6fdf0b9b8a)
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 PetscErrorCode TaoFinalizePackage(void)
12 {
13   PetscFunctionBegin;
14   PetscCall(PetscFunctionListDestroy(&TaoList));
15   TaoPackageInitialized = PETSC_FALSE;
16   PetscFunctionReturn(PETSC_SUCCESS);
17 }
18 
19 /*@C
20   TaoInitializePackage - This function sets up PETSc to use the Tao
21   package.  When using static or shared libraries, this function is called from the
22   first entry to `TaoCreate()`; when using shared or static libraries, it is called
23   from PetscDLLibraryRegister_tao()
24 
25   Level: developer
26 
27 .seealso: `TaoCreate()`
28 @*/
29 PetscErrorCode TaoInitializePackage(void)
30 {
31   char      logList[256];
32   PetscBool opt, pkg;
33 
34   PetscFunctionBegin;
35   if (TaoPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS);
36   TaoPackageInitialized = PETSC_TRUE;
37   /* Register Classes */
38   PetscCall(PetscClassIdRegister("Tao", &TAO_CLASSID));
39   /* Register Constructors */
40   PetscCall(TaoRegisterAll());
41   /* Register Events */
42   PetscCall(PetscLogEventRegister("TaoSolve", TAO_CLASSID, &TAO_Solve));
43   PetscCall(PetscLogEventRegister("TaoObjectiveEval", TAO_CLASSID, &TAO_ObjectiveEval));
44   PetscCall(PetscLogEventRegister("TaoGradientEval", TAO_CLASSID, &TAO_GradientEval));
45   PetscCall(PetscLogEventRegister("TaoObjGradEval", TAO_CLASSID, &TAO_ObjGradEval));
46   PetscCall(PetscLogEventRegister("TaoHessianEval", TAO_CLASSID, &TAO_HessianEval));
47   PetscCall(PetscLogEventRegister("TaoConstrEval", TAO_CLASSID, &TAO_ConstraintsEval));
48   PetscCall(PetscLogEventRegister("TaoJacobianEval", TAO_CLASSID, &TAO_JacobianEval));
49   /* Process Info */
50   {
51     PetscClassId classids[1];
52 
53     classids[0] = TAO_CLASSID;
54     PetscCall(PetscInfoProcessClass("tao", 1, classids));
55   }
56   /* Process summary exclusions */
57   PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
58   if (opt) {
59     PetscCall(PetscStrInList("tao", logList, ',', &pkg));
60     if (pkg) PetscCall(PetscLogEventExcludeClass(TAO_CLASSID));
61   }
62   /* Register package finalizer */
63   PetscCall(PetscRegisterFinalize(TaoFinalizePackage));
64   PetscFunctionReturn(PETSC_SUCCESS);
65 }
66 
67 #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
68 /*
69   PetscDLLibraryRegister - this function is called when the dynamic library it
70   is in is opened.
71 
72   This registers all of the Tao methods that are in the libtao
73   library.
74 
75   Input Parameter:
76 . path - library path
77 */
78 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petsctao(void)
79 {
80   PetscFunctionBegin;
81   PetscCall(TaoInitializePackage());
82   PetscCall(TaoLineSearchInitializePackage());
83   PetscFunctionReturn(PETSC_SUCCESS);
84 }
85 #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */
86