xref: /petsc/src/sys/classes/viewer/interface/dlregispetsc.c (revision 1b37a2a7cc4a4fb30c3e967db1c694c0a1013f51)
1 #include <petscdraw.h>
2 #include <petscviewer.h>
3 #include <petsc/private/viewerimpl.h>
4 
5 static PetscBool PetscSysPackageInitialized = PETSC_FALSE;
6 
7 /*@C
8   PetscSysFinalizePackage - This function destroys everything in the system library portion of PETSc.
9   It is called from `PetscFinalize()`.
10 
11   Level: developer
12 
13 .seealso: `PetscSysInitializePackage()`, `PetscFinalize()`
14 @*/
15 PetscErrorCode PetscSysFinalizePackage(void)
16 {
17   PetscFunctionBegin;
18   if (Petsc_Seq_keyval != MPI_KEYVAL_INVALID) PetscCallMPI(MPI_Comm_free_keyval(&Petsc_Seq_keyval));
19   PetscSysPackageInitialized = PETSC_FALSE;
20   PetscFunctionReturn(PETSC_SUCCESS);
21 }
22 
23 /*@C
24   PetscSysInitializePackage - This function initializes everything in the system library portion of PETSc. It is called
25   from `PetscDLLibraryRegister_petsc()` when using dynamic libraries, and in the call to `PetscInitialize()`
26   when using shared or static libraries.
27 
28   Level: developer
29 
30 .seealso: `PetscSysFinalizePackage()`, `PetscInitialize()`
31 @*/
32 PetscErrorCode PetscSysInitializePackage(void)
33 {
34   char      logList[256];
35   PetscBool opt, pkg;
36 
37   PetscFunctionBegin;
38   if (PetscSysPackageInitialized) PetscFunctionReturn(PETSC_SUCCESS);
39   PetscSysPackageInitialized = PETSC_TRUE;
40   /* Register Classes */
41   PetscCall(PetscClassIdRegister("Object", &PETSC_OBJECT_CLASSID));
42   PetscCall(PetscClassIdRegister("Container", &PETSC_CONTAINER_CLASSID));
43 
44   /* Register Events */
45   PetscCall(PetscLogEventRegister("PetscBarrier", PETSC_SMALLEST_CLASSID, &PETSC_Barrier));
46   PetscCall(PetscLogEventRegister("BuildTwoSided", PETSC_SMALLEST_CLASSID, &PETSC_BuildTwoSided));
47   PetscCall(PetscLogEventRegister("BuildTwoSidedF", PETSC_SMALLEST_CLASSID, &PETSC_BuildTwoSidedF));
48   /* Process Info */
49   {
50     PetscClassId classids[1];
51 
52     classids[0] = PETSC_SMALLEST_CLASSID;
53     PetscCall(PetscInfoProcessClass("sys", 1, classids));
54   }
55   /* Process summary exclusions */
56   PetscCall(PetscOptionsGetString(NULL, NULL, "-log_exclude", logList, sizeof(logList), &opt));
57   if (opt) {
58     PetscCall(PetscStrInList("null", logList, ',', &pkg));
59     if (pkg) PetscCall(PetscLogEventExcludeClass(PETSC_SMALLEST_CLASSID));
60   }
61   PetscCall(PetscRegisterFinalize(PetscSysFinalizePackage));
62   PetscFunctionReturn(PETSC_SUCCESS);
63 }
64 
65 #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
66 
67   #if defined(PETSC_USE_SINGLE_LIBRARY)
68 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscvec(void);
69 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscmat(void);
70 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscdm(void);
71 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscksp(void);
72 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscsnes(void);
73 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscts(void);
74   #endif
75 
76   /*
77   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.
78 
79   This one registers all the system level objects.
80 
81  */
82   #if defined(PETSC_USE_SINGLE_LIBRARY)
83 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petsc(void)
84   #else
85 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscsys(void)
86   #endif
87 {
88   PetscFunctionBegin;
89   /*
90       If we got here then PETSc was properly loaded
91   */
92   PetscCall(PetscSysInitializePackage());
93   PetscCall(PetscDrawInitializePackage());
94   PetscCall(PetscViewerInitializePackage());
95   PetscCall(PetscRandomInitializePackage());
96 
97   #if defined(PETSC_USE_SINGLE_LIBRARY)
98   PetscCall(PetscDLLibraryRegister_petscvec());
99   PetscCall(PetscDLLibraryRegister_petscmat());
100   PetscCall(PetscDLLibraryRegister_petscdm());
101   PetscCall(PetscDLLibraryRegister_petscksp());
102   PetscCall(PetscDLLibraryRegister_petscsnes());
103   PetscCall(PetscDLLibraryRegister_petscts());
104   #endif
105   PetscFunctionReturn(PETSC_SUCCESS);
106 }
107 #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */
108