xref: /petsc/src/sys/classes/viewer/interface/dlregispetsc.c (revision 974a8051c82bafb558ffc9eeb19dcecc2a464fa7)
1 
2 #include <petscdraw.h>
3 #include <petscviewer.h>
4 #include <petsc/private/viewerimpl.h>
5 
6 extern PetscLogEvent PETSC_Barrier,PETSC_BuildTwoSided,PETSC_BuildTwoSidedF;
7 static PetscBool PetscSysPackageInitialized = PETSC_FALSE;
8 
9 /*@C
10   PetscSysFinalizePackage - This function destroys everything in the PETSc created internally in the system library portion of PETSc.
11   It is called from PetscFinalize().
12 
13   Level: developer
14 
15 .keywords: Petsc, destroy, package
16 .seealso: PetscFinalize()
17 @*/
18 PetscErrorCode  PetscSysFinalizePackage(void)
19 {
20   PetscErrorCode ierr;
21 
22   PetscFunctionBegin;
23   if (Petsc_Viewer_keyval != MPI_KEYVAL_INVALID) {
24     ierr = MPI_Keyval_free(&Petsc_Viewer_keyval);CHKERRQ(ierr);
25   }
26   if (Petsc_Viewer_Stdout_keyval != MPI_KEYVAL_INVALID) {
27     ierr = MPI_Keyval_free(&Petsc_Viewer_Stdout_keyval);CHKERRQ(ierr);
28   }
29   if (Petsc_Viewer_Stderr_keyval != MPI_KEYVAL_INVALID) {
30     ierr = MPI_Keyval_free(&Petsc_Viewer_Stderr_keyval);CHKERRQ(ierr);
31   }
32   if (Petsc_Viewer_Binary_keyval != MPI_KEYVAL_INVALID) {
33     ierr = MPI_Keyval_free(&Petsc_Viewer_Binary_keyval);CHKERRQ(ierr);
34   }
35   if (Petsc_Viewer_Draw_keyval != MPI_KEYVAL_INVALID) {
36     ierr = MPI_Keyval_free(&Petsc_Viewer_Draw_keyval);CHKERRQ(ierr);
37   }
38 #if defined(PETSC_HAVE_HDF5)
39   if (Petsc_Viewer_HDF5_keyval != MPI_KEYVAL_INVALID) {
40     ierr = MPI_Keyval_free(&Petsc_Viewer_HDF5_keyval);CHKERRQ(ierr);
41   }
42 #endif
43 #if defined(PETSC_USE_SOCKETVIEWER)
44   if (Petsc_Viewer_Socket_keyval != MPI_KEYVAL_INVALID) {
45     ierr = MPI_Keyval_free(&Petsc_Viewer_Socket_keyval);CHKERRQ(ierr);
46   }
47 #endif
48   PetscSysPackageInitialized = PETSC_FALSE;
49   PetscFunctionReturn(0);
50 }
51 
52 /*@C
53   PetscSysInitializePackage - This function initializes everything in the main Petsc package. It is called
54   from PetscDLLibraryRegister() when using dynamic libraries, and on the call to PetscInitialize()
55   when using static libraries.
56 
57   Level: developer
58 
59 .keywords: Petsc, initialize, package
60 .seealso: PetscInitialize()
61 @*/
62 PetscErrorCode  PetscSysInitializePackage(void)
63 {
64   char           logList[256];
65   char           *className;
66   PetscBool      opt;
67   PetscErrorCode ierr;
68 
69   PetscFunctionBegin;
70   if (PetscSysPackageInitialized) PetscFunctionReturn(0);
71   PetscSysPackageInitialized = PETSC_TRUE;
72   /* Register Classes */
73   ierr = PetscClassIdRegister("Object",&PETSC_OBJECT_CLASSID);CHKERRQ(ierr);
74   ierr = PetscClassIdRegister("Container",&PETSC_CONTAINER_CLASSID);CHKERRQ(ierr);
75 
76   /* Register Events */
77   ierr = PetscLogEventRegister("PetscBarrier", PETSC_SMALLEST_CLASSID,&PETSC_Barrier);CHKERRQ(ierr);
78   ierr = PetscLogEventRegister("BuildTwoSided",PETSC_SMALLEST_CLASSID,&PETSC_BuildTwoSided);CHKERRQ(ierr);
79   ierr = PetscLogEventRegister("BuildTwoSidedF",PETSC_SMALLEST_CLASSID,&PETSC_BuildTwoSidedF);CHKERRQ(ierr);
80   /* Process info exclusions */
81   ierr = PetscOptionsGetString(NULL,NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr);
82   if (opt) {
83     ierr = PetscStrstr(logList, "null", &className);CHKERRQ(ierr);
84     if (className) {
85       ierr = PetscInfoDeactivateClass(0);CHKERRQ(ierr);
86     }
87   }
88   /* Process summary exclusions */
89   ierr = PetscOptionsGetString(NULL,NULL, "-log_exclude", logList, 256, &opt);CHKERRQ(ierr);
90   if (opt) {
91     ierr = PetscStrstr(logList, "null", &className);CHKERRQ(ierr);
92     if (className) {
93       ierr = PetscLogEventDeactivateClass(0);CHKERRQ(ierr);
94     }
95   }
96   ierr = PetscRegisterFinalize(PetscSysFinalizePackage);CHKERRQ(ierr);
97   PetscFunctionReturn(0);
98 }
99 
100 #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
101 
102 #if defined(PETSC_USE_SINGLE_LIBRARY)
103 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscvec(void);
104 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscmat(void);
105 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscdm(void);
106 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscksp(void);
107 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscsnes(void);
108 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscts(void);
109 #endif
110 
111 #if defined(PETSC_USE_SINGLE_LIBRARY)
112 #else
113 #endif
114 /*
115   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.
116 
117   This one registers all the draw and PetscViewer objects.
118 
119  */
120 #if defined(PETSC_USE_SINGLE_LIBRARY)
121 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petsc(void)
122 #else
123 PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscsys(void)
124 #endif
125 {
126   PetscErrorCode ierr;
127 
128   PetscFunctionBegin;
129   /*
130       If we got here then PETSc was properly loaded
131   */
132   ierr = PetscSysInitializePackage();CHKERRQ(ierr);
133   ierr = PetscDrawInitializePackage();CHKERRQ(ierr);
134   ierr = PetscViewerInitializePackage();CHKERRQ(ierr);
135   ierr = PetscRandomInitializePackage();CHKERRQ(ierr);
136 
137 #if defined(PETSC_USE_SINGLE_LIBRARY)
138   ierr = PetscDLLibraryRegister_petscvec();CHKERRQ(ierr);
139   ierr = PetscDLLibraryRegister_petscmat();CHKERRQ(ierr);
140   ierr = PetscDLLibraryRegister_petscdm();CHKERRQ(ierr);
141   ierr = PetscDLLibraryRegister_petscksp();CHKERRQ(ierr);
142   ierr = PetscDLLibraryRegister_petscsnes();CHKERRQ(ierr);
143   ierr = PetscDLLibraryRegister_petscts();CHKERRQ(ierr);
144 #endif
145   PetscFunctionReturn(0);
146 }
147 #endif  /* PETSC_HAVE_DYNAMIC_LIBRARIES */
148