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