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