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