xref: /petsc/include/petscerror.h (revision 5e81a9049f99b3e299d3dfd50df0d9eed5e5e59b)
1 /*
2     Contains all error handling interfaces for PETSc.
3 */
4 #if !defined(PETSCERROR_H)
5 #define PETSCERROR_H
6 
7 /*
8      These are the generic error codes. These error codes are used
9      many different places in the PETSc source code. The string versions are
10      at src/sys/error/err.c any changes here must also be made there
11      These are also define in src/sys/f90-mod/petscerror.h any CHANGES here
12      must be also made there.
13 
14 */
15 #define PETSC_ERR_MIN_VALUE        54   /* should always be one less then the smallest value */
16 
17 #define PETSC_ERR_MEM              55   /* unable to allocate requested memory */
18 #define PETSC_ERR_SUP              56   /* no support for requested operation */
19 #define PETSC_ERR_SUP_SYS          57   /* no support for requested operation on this computer system */
20 #define PETSC_ERR_ORDER            58   /* operation done in wrong order */
21 #define PETSC_ERR_SIG              59   /* signal received */
22 #define PETSC_ERR_FP               72   /* floating point exception */
23 #define PETSC_ERR_COR              74   /* corrupted PETSc object */
24 #define PETSC_ERR_LIB              76   /* error in library called by PETSc */
25 #define PETSC_ERR_PLIB             77   /* PETSc library generated inconsistent data */
26 #define PETSC_ERR_MEMC             78   /* memory corruption */
27 #define PETSC_ERR_CONV_FAILED      82   /* iterative method (KSP or SNES) failed */
28 #define PETSC_ERR_USER             83   /* user has not provided needed function */
29 #define PETSC_ERR_SYS              88   /* error in system call */
30 #define PETSC_ERR_POINTER          70   /* pointer does not point to valid address */
31 #define PETSC_ERR_MPI_LIB_INCOMP   87   /* MPI library at runtime is not compatible with MPI user compiled with */
32 
33 #define PETSC_ERR_ARG_SIZ          60   /* nonconforming object sizes used in operation */
34 #define PETSC_ERR_ARG_IDN          61   /* two arguments not allowed to be the same */
35 #define PETSC_ERR_ARG_WRONG        62   /* wrong argument (but object probably ok) */
36 #define PETSC_ERR_ARG_CORRUPT      64   /* null or corrupted PETSc object as argument */
37 #define PETSC_ERR_ARG_OUTOFRANGE   63   /* input argument, out of range */
38 #define PETSC_ERR_ARG_BADPTR       68   /* invalid pointer argument */
39 #define PETSC_ERR_ARG_NOTSAMETYPE  69   /* two args must be same object type */
40 #define PETSC_ERR_ARG_NOTSAMECOMM  80   /* two args must be same communicators */
41 #define PETSC_ERR_ARG_WRONGSTATE   73   /* object in argument is in wrong state, e.g. unassembled mat */
42 #define PETSC_ERR_ARG_TYPENOTSET   89   /* the type of the object has not yet been set */
43 #define PETSC_ERR_ARG_INCOMP       75   /* two arguments are incompatible */
44 #define PETSC_ERR_ARG_NULL         85   /* argument is null that should not be */
45 #define PETSC_ERR_ARG_UNKNOWN_TYPE 86   /* type name doesn't match any registered type */
46 
47 #define PETSC_ERR_FILE_OPEN        65   /* unable to open file */
48 #define PETSC_ERR_FILE_READ        66   /* unable to read from file */
49 #define PETSC_ERR_FILE_WRITE       67   /* unable to write to file */
50 #define PETSC_ERR_FILE_UNEXPECTED  79   /* unexpected data in file */
51 
52 #define PETSC_ERR_MAT_LU_ZRPVT     71   /* detected a zero pivot during LU factorization */
53 #define PETSC_ERR_MAT_CH_ZRPVT     81   /* detected a zero pivot during Cholesky factorization */
54 
55 #define PETSC_ERR_INT_OVERFLOW     84
56 
57 #define PETSC_ERR_FLOP_COUNT       90
58 #define PETSC_ERR_NOT_CONVERGED    91  /* solver did not converge */
59 #define PETSC_ERR_MISSING_FACTOR   92  /* MatGetFactor() failed */
60 #define PETSC_ERR_OPT_OVERWRITE    93  /* attempted to over write options which should not be changed */
61 #define PETSC_ERR_WRONG_MPI_SIZE   94  /* example/application run with number of MPI ranks it does not support */
62 #define PETSC_ERR_USER_INPUT       95  /* missing or incorrect user input */
63 #define PETSC_ERR_GPU_RESOURCE     96  /* unable to load a GPU resource, for example cuBLAS */
64 #define PETSC_ERR_GPU              97  /* An error from a GPU call, this may be due to lack of resources on the GPU or a true error in the call */
65 #define PETSC_ERR_MPI              98  /* general MPI error */
66 #define PETSC_ERR_MAX_VALUE        99  /* this is always the one more than the largest error code */
67 
68 /*MC
69    SETERRQ - Macro to be called when an error has been detected,
70 
71    Synopsis:
72    #include <petscsys.h>
73    PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message)
74 
75    Collective
76 
77    Input Parameters:
78 +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
79 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
80 -  message - error message
81 
82   Level: beginner
83 
84    Notes:
85     Once the error handler is called the calling function is then returned from with the given error code.
86 
87     See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
88 
89     Experienced users can set the error handler with PetscPushErrorHandler().
90 
91    Fortran Notes:
92       SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the
93       Fortran main program.
94 
95 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), CHKERRMPI()
96 M*/
97 #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s)
98 
99 /*
100     Returned from PETSc functions that are called from MPI, such as related to attributes
101       Do not confuse PETSC_MPI_ERROR_CODE and PETSC_ERR_MPI, the first is registered with MPI and returned to MPI as
102       an error code, the latter is a regular PETSc error code passed within PETSc code indicating an error was detected in an MPI call.
103 */
104 PETSC_EXTERN PetscMPIInt PETSC_MPI_ERROR_CLASS;
105 PETSC_EXTERN PetscMPIInt PETSC_MPI_ERROR_CODE;
106 
107 /*MC
108    SETERRMPI - Macro to be called when an error has been detected within an MPI callback function
109 
110    Synopsis:
111    #include <petscsys.h>
112    PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message)
113 
114    Collective
115 
116    Input Parameters:
117 +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
118 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
119 -  message - error message
120 
121   Level: developer
122 
123    Notes:
124     This macro is FOR USE IN MPI CALLBACK FUNCTIONS ONLY, such as those passed to MPI_Comm_create_keyval(). It always returns the error code PETSC_MPI_ERROR_CODE
125     which is registered with MPI_Add_error_code() when PETSc is initialized.
126 
127 .seealso: SETERRQ(), CHKERRQ(), CHKERRMPI(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
128 M*/
129 #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE)
130 
131 /*MC
132    SETERRQ1 - Macro that is called when an error has been detected,
133 
134    Synopsis:
135    #include <petscsys.h>
136    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)
137 
138    Collective
139 
140    Input Parameters:
141 +  comm - A communicator, so that the error can be collective
142 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
143 .  message - error message in the printf format
144 -  arg - argument (for example an integer, string or double)
145 
146   Level: beginner
147 
148    Notes:
149     Once the error handler is called the calling function is then returned from with the given error code.
150 
151    Experienced users can set the error handler with PetscPushErrorHandler().
152 
153 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
154 M*/
155 #define SETERRQ1(comm,ierr,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1)
156 
157 /*MC
158    SETERRQ2 - Macro that is called when an error has been detected,
159 
160    Synopsis:
161    #include <petscsys.h>
162    PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)
163 
164    Collective
165 
166    Input Parameters:
167 +  comm - A communicator, so that the error can be collective
168 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
169 .  message - error message in the printf format
170 .  arg1 - argument (for example an integer, string or double)
171 -  arg2 - argument (for example an integer, string or double)
172 
173   Level: beginner
174 
175    Notes:
176     Once the error handler is called the calling function is then returned from with the given error code.
177 
178    Experienced users can set the error handler with PetscPushErrorHandler().
179 
180 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
181 M*/
182 #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2)
183 
184 /*MC
185    SETERRQ3 - Macro that is called when an error has been detected,
186 
187    Synopsis:
188    #include <petscsys.h>
189    PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
190 
191    Collective
192 
193    Input Parameters:
194 +  comm - A communicator, so that the error can be collective
195 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
196 .  message - error message in the printf format
197 .  arg1 - argument (for example an integer, string or double)
198 .  arg2 - argument (for example an integer, string or double)
199 -  arg3 - argument (for example an integer, string or double)
200 
201   Level: beginner
202 
203    Notes:
204     Once the error handler is called the calling function is then returned from with the given error code.
205 
206     There are also versions for 4, 5, 6 and 7 arguments.
207 
208    Experienced users can set the error handler with PetscPushErrorHandler().
209 
210 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
211 M*/
212 #define SETERRQ3(comm,ierr,s,a1,a2,a3) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3)
213 
214 /*MC
215    SETERRQ4 - Macro that is called when an error has been detected,
216 
217    Synopsis:
218    #include <petscsys.h>
219    PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4)
220 
221    Collective
222 
223    Input Parameters:
224 +  comm - A communicator, so that the error can be collective
225 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
226 .  message - error message in the printf format
227 .  arg1 - argument (for example an integer, string or double)
228 .  arg2 - argument (for example an integer, string or double)
229 .  arg3 - argument (for example an integer, string or double)
230 -  arg4 - argument (for example an integer, string or double)
231 
232   Level: beginner
233 
234    Notes:
235     Once the error handler is called the calling function is then returned from with the given error code.
236 
237     There are also versions for 4, 5, 6 and 7 arguments.
238 
239    Experienced users can set the error handler with PetscPushErrorHandler().
240 
241 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
242 M*/
243 #define SETERRQ4(comm,ierr,s,a1,a2,a3,a4) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4)
244 
245 /*MC
246    SETERRQ5 - Macro that is called when an error has been detected,
247 
248    Synopsis:
249    #include <petscsys.h>
250    PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5)
251 
252    Collective
253 
254    Input Parameters:
255 +  comm - A communicator, so that the error can be collective
256 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
257 .  message - error message in the printf format
258 .  arg1 - argument (for example an integer, string or double)
259 .  arg2 - argument (for example an integer, string or double)
260 .  arg3 - argument (for example an integer, string or double)
261 .  arg4 - argument (for example an integer, string or double)
262 -  arg5 - argument (for example an integer, string or double)
263 
264   Level: beginner
265 
266    Notes:
267     Once the error handler is called the calling function is then returned from with the given error code.
268 
269     There are also versions for 4, 5, 6 and 7 arguments.
270 
271    Experienced users can set the error handler with PetscPushErrorHandler().
272 
273 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
274 M*/
275 #define SETERRQ5(comm,ierr,s,a1,a2,a3,a4,a5) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5)
276 
277 /*MC
278    SETERRQ6 - Macro that is called when an error has been detected,
279 
280    Synopsis:
281    #include <petscsys.h>
282    PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6)
283 
284    Collective
285 
286    Input Parameters:
287 +  comm - A communicator, so that the error can be collective
288 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
289 .  message - error message in the printf format
290 .  arg1 - argument (for example an integer, string or double)
291 .  arg2 - argument (for example an integer, string or double)
292 .  arg3 - argument (for example an integer, string or double)
293 .  arg4 - argument (for example an integer, string or double)
294 .  arg5 - argument (for example an integer, string or double)
295 -  arg6 - argument (for example an integer, string or double)
296 
297   Level: beginner
298 
299    Notes:
300     Once the error handler is called the calling function is then returned from with the given error code.
301 
302     There are also versions for 4, 5, 6 and 7 arguments.
303 
304    Experienced users can set the error handler with PetscPushErrorHandler().
305 
306 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
307 M*/
308 #define SETERRQ6(comm,ierr,s,a1,a2,a3,a4,a5,a6) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6)
309 
310 /*MC
311    SETERRQ7 - Macro that is called when an error has been detected,
312 
313    Synopsis:
314    #include <petscsys.h>
315    PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
316 
317    Collective
318 
319    Input Parameters:
320 +  comm - A communicator, so that the error can be collective
321 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
322 .  message - error message in the printf format
323 .  arg1 - argument (for example an integer, string or double)
324 .  arg2 - argument (for example an integer, string or double)
325 .  arg3 - argument (for example an integer, string or double)
326 .  arg4 - argument (for example an integer, string or double)
327 .  arg5 - argument (for example an integer, string or double)
328 .  arg6 - argument (for example an integer, string or double)
329 -  arg7 - argument (for example an integer, string or double)
330 
331   Level: beginner
332 
333    Notes:
334     Once the error handler is called the calling function is then returned from with the given error code.
335 
336     There are also versions for 4, 5, 6 and 7 arguments.
337 
338    Experienced users can set the error handler with PetscPushErrorHandler().
339 
340 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
341 M*/
342 #define SETERRQ7(comm,ierr,s,a1,a2,a3,a4,a5,a6,a7) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7)
343 
344 /*MC
345    SETERRQ8 - Macro that is called when an error has been detected,
346 
347    Synopsis:
348    #include <petscsys.h>
349    PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)
350 
351    Collective
352 
353    Input Parameters:
354 +  comm - A communicator, so that the error can be collective
355 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
356 .  message - error message in the printf format
357 .  arg1 - argument (for example an integer, string or double)
358 .  arg2 - argument (for example an integer, string or double)
359 .  arg3 - argument (for example an integer, string or double)
360 .  arg4 - argument (for example an integer, string or double)
361 .  arg5 - argument (for example an integer, string or double)
362 .  arg6 - argument (for example an integer, string or double)
363 .  arg7 - argument (for example an integer, string or double)
364 -  arg8 - argument (for example an integer, string or double)
365 
366   Level: beginner
367 
368    Notes:
369     Once the error handler is called the calling function is then returned from with the given error code.
370 
371     There are also versions for 4, 5, 6 and 7 arguments.
372 
373    Experienced users can set the error handler with PetscPushErrorHandler().
374 
375 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
376 M*/
377 #define SETERRQ8(comm,ierr,s,a1,a2,a3,a4,a5,a6,a7,a8) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7,a8)
378 
379 /*MC
380    SETERRQ9 - Macro that is called when an error has been detected,
381 
382    Synopsis:
383    #include <petscsys.h>
384    PetscErrorCode SETERRQ9(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
385 
386    Collective
387 
388    Input Parameters:
389 +  comm - A communicator, so that the error can be collective
390 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
391 .  message - error message in the printf format
392 .  arg1 - argument (for example an integer, string or double)
393 .  arg2 - argument (for example an integer, string or double)
394 .  arg3 - argument (for example an integer, string or double)
395 .  arg4 - argument (for example an integer, string or double)
396 .  arg5 - argument (for example an integer, string or double)
397 .  arg6 - argument (for example an integer, string or double)
398 .  arg7 - argument (for example an integer, string or double)
399 .  arg8 - argument (for example an integer, string or double)
400 -  arg9 - argument (for example an integer, string or double)
401 
402   Level: beginner
403 
404    Notes:
405     Once the error handler is called the calling function is then returned from with the given error code.
406 
407     There are also versions for 0 to 9 arguments.
408 
409    Experienced users can set the error handler with PetscPushErrorHandler().
410 
411 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
412 M*/
413 #define SETERRQ9(comm,ierr,s,a1,a2,a3,a4,a5,a6,a7,a8,a9) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7,a8,a9)
414 
415 /*MC
416    SETERRABORT - Macro that can be called when an error has been detected,
417 
418    Synopsis:
419    #include <petscsys.h>
420    PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)
421 
422    Collective
423 
424    Input Parameters:
425 +  comm - A communicator, so that the error can be collective
426 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
427 -  message - error message in the printf format
428 
429   Level: beginner
430 
431    Notes:
432     This function just calls MPI_Abort().
433 
434 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
435 M*/
436 #define SETERRABORT(comm,ierr,s) do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,ierr);} while (0)
437 
438 /*MC
439    CHKERRQ - Checks error code returned from PETSc function, if non-zero it calls the error handler and then returns. Use CHKERRMPI() for checking errors from MPI calls
440 
441    Synopsis:
442    #include <petscsys.h>
443    PetscErrorCode CHKERRQ(PetscErrorCode ierr)
444 
445    Not Collective
446 
447    Input Parameters:
448 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
449 
450   Level: beginner
451 
452    Notes:
453     Once the error handler is called the calling function is then returned from with the given error code.
454 
455     Experienced users can set the error handler with PetscPushErrorHandler().
456 
457     CHKERRQ(ierr) is fundamentally a macro replacement for
458          if (ierr) return(PetscError(...,ierr,...));
459 
460     Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
461     highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
462     it cannot be used in functions which return(void) or any other datatype.  In these types of functions,
463     you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
464          if (ierr) {PetscError(....); return(YourReturnType);}
465     where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
466     MPI_Abort() returned immediately.
467 
468    Fortran Notes:
469       CHKERRQ() may be called from Fortran subroutines but CHKERRA() must be called from the
470       Fortran main program.
471 
472 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
473 M*/
474 #if !defined(PETSC_CLANG_STATIC_ANALYZER)
475 #define CHKERRQ(ierr)          do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");} while (0)
476 #define CHKERRV(ierr)          do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");return;}} while (0)
477 #else
478 #define CHKERRQ(ierr)
479 #define CHKERRV(ierr)
480 #endif
481 
482 /*MC
483    CHKERRABORT - Checks error code returned from PETSc function. If non-zero it aborts immediately.
484 
485    Synopsis:
486    #include <petscsys.h>
487    PetscErrorCode CHKERRABORT(MPI_Comm comm,PetscErrorCode ierr)
488 
489    Not Collective
490 
491    Input Parameters:
492 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
493 
494   Level: intermediate
495 
496 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2(), SETERRABORT(), CHKERRMPI()
497 M*/
498 #if !defined(PETSC_CLANG_STATIC_ANALYZER)
499 #define CHKERRABORT(comm,ierr) do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");MPI_Abort(comm,ierr);}} while (0)
500 #define CHKERRCONTINUE(ierr)   do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");}} while (0)
501 #else
502 #define CHKERRABORT(comm,ierr)
503 #define CHKERRCONTINUE(ierr)
504 #endif
505 
506 PETSC_EXTERN PetscErrorCode PetscAbortFindSourceFile_Private(const char*,PetscInt*);
507 PETSC_EXTERN PetscBool petscwaitonerrorflg;
508 PETSC_EXTERN PetscBool petscindebugger;
509 
510 /*MC
511    PETSCABORT - Call MPI_Abort with an informative error code
512 
513    Synopsis:
514    #include <petscsys.h>
515    PETSCABORT(MPI_Comm comm, PetscErrorCode ierr)
516 
517    Collective
518 
519    Input Parameters:
520 +  comm - A communicator, so that the error can be collective
521 -  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
522 
523    Level: advanced
524 
525    Notes:
526    We pass MPI_Abort() an error code of format XX_YYYY_ZZZ, where XX, YYYY are an index and line number of the file
527    where PETSCABORT is called, respectively. ZZZ is the PETSc error code.
528 
529    If XX is zero, this means that the call was made in the routine main().
530    If XX is one, that means 1) the file is not in PETSc (it may be in users code); OR 2) the file is in PETSc but PetscAbortSourceFiles[]
531      is out of date. PETSc developers have to update it.
532    Otherwise, look up the value of XX in the table PetscAbortSourceFiles[] in src/sys/error/err.c to map XX back to the source file where the PETSCABORT() was called.
533 
534    If the option -start_in_debugger was used then this calls abort() to stop the program in the debugger.
535 
536 M*/
537 #define PETSCABORT(comm,ierr)  \
538    do {                                                               \
539       PetscInt       idx = 0;                                         \
540       PetscMPIInt    errcode;                                         \
541       PetscAbortFindSourceFile_Private(__FILE__,&idx);                \
542       errcode = (PetscMPIInt)(0*idx*10000000 + 0*__LINE__*1000 + ierr);   \
543       if (petscwaitonerrorflg) PetscSleep(1000);                      \
544       if (petscindebugger) abort();                                   \
545       else MPI_Abort(comm,errcode);                                   \
546    } while (0)
547 
548 /*MC
549    CHKERRMPI - Checks error code returned from MPI calls, if non-zero it calls the error handler and then returns
550 
551    Synopsis:
552    #include <petscsys.h>
553    PetscErrorCode CHKERRMPI(PetscErrorCode ierr)
554 
555    Not Collective
556 
557    Input Parameters:
558 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
559 
560   Level: intermediate
561 
562    Notes:
563     Always returns the error code PETSC_ERR_MPI; the MPI error code and string are embedded in the string error message
564 
565 .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2(), SETERRMPI(), SETERRABORT(), CHKERRABORT()
566 M*/
567 #if !defined(PETSC_CLANG_STATIC_ANALYZER)
568 #define CHKERRMPI(ierr) \
569 do { \
570   PetscErrorCode _7_errorcode = (ierr); \
571   if (PetscUnlikely(_7_errorcode)) { \
572     char _7_errorstring[MPI_MAX_ERROR_STRING]; \
573     PetscMPIInt _7_resultlen; \
574     MPI_Error_string(_7_errorcode,(char*)_7_errorstring,&_7_resultlen); (void)_7_resultlen; \
575     SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_MPI,"MPI error %d %s",(int)_7_errorcode,_7_errorstring); \
576   } \
577 } while (0)
578 #else
579 #define CHKERRMPI(ierr)
580 #endif
581 
582 #ifdef PETSC_CLANGUAGE_CXX
583 
584 /*MC
585    CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
586 
587    Synopsis:
588    #include <petscsys.h>
589    void CHKERRXX(PetscErrorCode ierr)
590 
591    Not Collective
592 
593    Input Parameters:
594 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
595 
596   Level: beginner
597 
598    Notes:
599     Once the error handler throws a ??? exception.
600 
601     You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
602     or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
603 
604 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
605 M*/
606 #define CHKERRXX(ierr)  do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_IN_CXX,0);}} while (0)
607 #endif
608 
609 /*MC
610    CHKERRCXX - Checks C++ function calls and if they throw an exception, catch it and then return a PETSc error code
611 
612    Synopsis:
613    #include <petscsys.h>
614    CHKERRCXX(func);
615 
616    Not Collective
617 
618    Input Parameters:
619 .  func - C++ function calls
620 
621   Level: beginner
622 
623   Notes:
624    For example,
625 
626 $     void foo(int x) {throw std::runtime_error("error");}
627 $     CHKERRCXX(foo(1));
628 
629 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
630 M*/
631 #define CHKERRCXX(func) do {try {func;} catch (const std::exception& e) { SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"%s", e.what()); }} while (0)
632 
633 /*MC
634    CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
635 
636    Synopsis:
637    #include <petscsys.h>
638    CHKMEMQ;
639 
640    Not Collective
641 
642   Level: beginner
643 
644    Notes:
645     We highly recommend using Valgrind https://petsc.org/release/faq/#valgrind or for NVIDIA CUDA systems
646     https://docs.nvidia.com/cuda/cuda-memcheck/index.html for finding memory problems. The ``CHKMEMQ`` macro is useful on systems that
647     do not have valgrind, but is not as good as valgrind or cuda-memcheck.
648 
649     Must run with the option -malloc_debug (-malloc_test in debug mode; or if PetscMallocSetDebug() called) to enable this option
650 
651     Once the error handler is called the calling function is then returned from with the given error code.
652 
653     By defaults prints location where memory that is corrupted was allocated.
654 
655     Use CHKMEMA for functions that return void
656 
657 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
658           PetscMallocValidate()
659 M*/
660 #if !defined(PETSC_CLANG_STATIC_ANALYZER)
661 #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while (0)
662 
663 #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)
664 #else
665 #define CHKMEMQ
666 #define CHKMEMA
667 #endif
668 /*E
669   PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
670 
671   Level: advanced
672 
673   PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
674 
675   Developer Notes:
676     This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()
677 
678 .seealso: PetscError(), SETERRXX()
679 E*/
680 typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
681 
682 #if defined(__clang_analyzer__)
683 __attribute__((analyzer_noreturn))
684 #endif
685 PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...) PETSC_ATTRIBUTE_FORMAT(7,8);
686 
687 PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
688 PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
689 PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
690 PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
691 PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
692 PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
693 PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
694 PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
695 PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
696 PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
697 PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
698 PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
699 PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
700 PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
701 PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt);
702 PETSC_EXTERN void PetscSignalSegvCheckPointerOrMpi(void);
703 PETSC_DEPRECATED_FUNCTION("Use PetscSignalSegvCheckPointerOrMpi() (since version 3.13)") PETSC_STATIC_INLINE void PetscSignalSegvCheckPointer(void) {PetscSignalSegvCheckPointerOrMpi();}
704 
705 /*MC
706     PetscErrorPrintf - Prints error messages.
707 
708    Synopsis:
709     #include <petscsys.h>
710      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
711 
712     Not Collective
713 
714     Input Parameter:
715 .   format - the usual printf() format string
716 
717    Options Database Keys:
718 +    -error_output_stdout - cause error messages to be printed to stdout instead of the  (default) stderr
719 -    -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)
720 
721    Notes:
722     Use
723 $     PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
724 $                        error is handled.) and
725 $     PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function
726 
727           Use
728      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
729      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
730 
731           Use
732       PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
733 
734    Level: developer
735 
736     Fortran Note:
737     This routine is not supported in Fortran.
738 
739 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf()
740 M*/
741 PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...) PETSC_ATTRIBUTE_FORMAT(1,2);
742 
743 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
744 PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
745 PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
746 PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);
747 PETSC_EXTERN PetscErrorCode PetscDetermineInitialFPTrap(void);
748 
749 /*
750       Allows the code to build a stack frame as it runs
751 */
752 
753 #if defined(PETSC_USE_DEBUG)
754 #define PETSCSTACKSIZE 64
755 typedef struct  {
756   const char *function[PETSCSTACKSIZE];
757   const char *file[PETSCSTACKSIZE];
758         int  line[PETSCSTACKSIZE];
759         int  petscroutine[PETSCSTACKSIZE]; /* 0 external called from petsc, 1 petsc functions, 2 petsc user functions */
760         int  currentsize;
761         int  hotdepth;
762   PetscBool  check; /* runtime option to check for correct Push/Pop semantics at runtime */
763 } PetscStack;
764 PETSC_EXTERN PetscStack petscstack;
765 #else
766 typedef struct {
767   char Silence_empty_struct_has_size_0_in_C_size_1_in_Cpp;
768 } PetscStack;
769 #endif
770 
771 #if defined(PETSC_SERIALIZE_FUNCTIONS)
772 #include <petsc/private/petscfptimpl.h>
773 /*
774    Registers the current function into the global function pointer to function name table
775 
776    Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
777 */
778 #define PetscRegister__FUNCT__() do { \
779   static PetscBool __chked = PETSC_FALSE; \
780   if (!__chked) {\
781   void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
782   __chked = PETSC_TRUE;\
783   }} while (0)
784 #else
785 #define PetscRegister__FUNCT__()
786 #endif
787 
788 #if !defined(PETSC_CLANG_STATIC_ANALYZER)
789 #if defined(PETSC_USE_DEBUG)
790 
791 /* Stack handling is based on the following two "NoCheck" macros.  These should only be called directly by other error
792  * handling macros.  We record the line of the call, which may or may not be the location of the definition.  But is at
793  * least more useful than "unknown" because it can distinguish multiple calls from the same function.
794  */
795 #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {             \
796     PetscStackSAWsTakeAccess();                                         \
797     if (petscstack.currentsize < PETSCSTACKSIZE) {                      \
798       petscstack.function[petscstack.currentsize]     = funct;          \
799       petscstack.file[petscstack.currentsize]         = __FILE__;       \
800       petscstack.line[petscstack.currentsize]         = __LINE__;       \
801       petscstack.petscroutine[petscstack.currentsize] = petsc_routine;  \
802     }                                                                   \
803     ++petscstack.currentsize;                                           \
804     petscstack.hotdepth += (hot || petscstack.hotdepth);                \
805     PetscStackSAWsGrantAccess();                                        \
806   } while (0)
807 
808 #define PetscStackPopNoCheck(funct)                    do {             \
809     PetscStackSAWsTakeAccess();                                         \
810     if (PetscUnlikely(petscstack.currentsize <= 0)) {                   \
811       if (PetscUnlikely(petscstack.check)) {                            \
812         printf("Invalid stack size %d, pop %s\n",                       \
813                petscstack.currentsize,funct);                           \
814       }                                                                 \
815     } else {                                                            \
816       if (--petscstack.currentsize < PETSCSTACKSIZE) {                  \
817         if (PetscUnlikely(                                              \
818               petscstack.check                                &&        \
819               petscstack.petscroutine[petscstack.currentsize] &&        \
820               (petscstack.function[petscstack.currentsize]    !=        \
821                (const char*)funct))) {                                  \
822           /* We need this string comparison because "unknown" can be defined in different static strings: */ \
823           PetscBool _cmpflg;                                            \
824           const char *_funct = petscstack.function[petscstack.currentsize]; \
825           PetscStrcmp(_funct,funct,&_cmpflg);                           \
826           if (!_cmpflg)                                                 \
827             printf("Invalid stack: push from %s, pop from %s\n", _funct,funct); \
828         }                                                               \
829         petscstack.function[petscstack.currentsize] = PETSC_NULLPTR;    \
830         petscstack.file[petscstack.currentsize]     = PETSC_NULLPTR;    \
831         petscstack.line[petscstack.currentsize]     = 0;                \
832         petscstack.petscroutine[petscstack.currentsize] = 0;            \
833       }                                                                 \
834       petscstack.hotdepth = PetscMax(petscstack.hotdepth-1,0);          \
835     }                                                                   \
836     PetscStackSAWsGrantAccess();                                        \
837   } while (0)
838 
839 #define PetscStackClearTop                             do {             \
840     PetscStackSAWsTakeAccess();                                         \
841     if (petscstack.currentsize > 0 &&                                   \
842         --petscstack.currentsize < PETSCSTACKSIZE) {                    \
843       petscstack.function[petscstack.currentsize]     = PETSC_NULLPTR;  \
844       petscstack.file[petscstack.currentsize]         = PETSC_NULLPTR;  \
845       petscstack.line[petscstack.currentsize]         = 0;              \
846       petscstack.petscroutine[petscstack.currentsize] = 0;              \
847     }                                                                   \
848     petscstack.hotdepth = PetscMax(petscstack.hotdepth-1,0);            \
849     PetscStackSAWsGrantAccess();                                        \
850   } while (0)
851 
852 /*MC
853    PetscFunctionBegin - First executable line of each PETSc function,  used for error handling. Final
854       line of PETSc functions should be PetscFunctionReturn(0);
855 
856    Synopsis:
857    #include <petscsys.h>
858    void PetscFunctionBegin;
859 
860    Not Collective
861 
862    Usage:
863 .vb
864      int something;
865 
866      PetscFunctionBegin;
867 .ve
868 
869    Notes:
870      Use PetscFunctionBeginUser for application codes.
871 
872      Not available in Fortran
873 
874    Level: developer
875 
876 .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser()
877 
878 M*/
879 #define PetscFunctionBegin do {                               \
880     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,1,PETSC_FALSE); \
881     PetscRegister__FUNCT__();                                 \
882   } while (0)
883 
884 /*MC
885    PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in
886    performance-critical circumstances.  Use of this function allows for lighter profiling by default.
887 
888    Synopsis:
889    #include <petscsys.h>
890    void PetscFunctionBeginHot;
891 
892    Not Collective
893 
894    Usage:
895 .vb
896      int something;
897 
898      PetscFunctionBeginHot;
899 .ve
900 
901    Notes:
902      Not available in Fortran
903 
904    Level: developer
905 
906 .seealso: PetscFunctionBegin, PetscFunctionReturn()
907 
908 M*/
909 #define PetscFunctionBeginHot do {                           \
910     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,1,PETSC_TRUE); \
911     PetscRegister__FUNCT__();                                \
912   } while (0)
913 
914 /*MC
915    PetscFunctionBeginUser - First executable line of user provided PETSc routine
916 
917    Synopsis:
918    #include <petscsys.h>
919    void PetscFunctionBeginUser;
920 
921    Not Collective
922 
923    Usage:
924 .vb
925      int something;
926 
927      PetscFunctionBeginUser;
928 .ve
929 
930    Notes:
931       Final line of PETSc functions should be PetscFunctionReturn(0) except for main().
932 
933       Not available in Fortran
934 
935       This is identical to PetscFunctionBegin except it labels the routine as a user
936       routine instead of as a PETSc library routine.
937 
938    Level: intermediate
939 
940 .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot
941 
942 M*/
943 #define PetscFunctionBeginUser do {                           \
944     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,2,PETSC_FALSE); \
945     PetscRegister__FUNCT__();                                 \
946   } while (0)
947 
948 #define PetscStackPush(n)       do {        \
949     PetscStackPushNoCheck(n,0,PETSC_FALSE); \
950     CHKMEMQ;                                \
951   } while (0)
952 
953 #define PetscStackPop           do {             \
954       CHKMEMQ;                                   \
955       PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \
956     } while (0)
957 
958 /*MC
959    PetscFunctionReturn - Last executable line of each PETSc function
960         used for error handling. Replaces return()
961 
962    Synopsis:
963    #include <petscsys.h>
964    void PetscFunctionReturn(0);
965 
966    Not Collective
967 
968    Usage:
969 .vb
970     ....
971      PetscFunctionReturn(0);
972    }
973 .ve
974 
975    Notes:
976      Not available in Fortran
977 
978    Level: developer
979 
980 .seealso: PetscFunctionBegin()
981 
982 M*/
983 #define PetscFunctionReturn(a)    do {          \
984     PetscStackPopNoCheck(PETSC_FUNCTION_NAME);  \
985     return a;                                   \
986   } while (0)
987 
988 #define PetscFunctionReturnVoid() do {          \
989     PetscStackPopNoCheck(PETSC_FUNCTION_NAME);  \
990     return;                                     \
991   } while (0)
992 #else /* PETSC_USE_DEBUG */
993 
994 #define PetscStackPushNoCheck(funct,petsc_routine,hot)
995 #define PetscStackPopNoCheck
996 #define PetscStackClearTop
997 #define PetscFunctionBegin
998 #define PetscFunctionBeginUser
999 #define PetscFunctionBeginHot
1000 #define PetscFunctionReturn(a)    return a
1001 #define PetscFunctionReturnVoid() return
1002 #define PetscStackPop             CHKMEMQ
1003 #define PetscStackPush(f)         CHKMEMQ
1004 
1005 #endif /* PETSC_USE_DEBUG */
1006 
1007 /*
1008     PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
1009 
1010    Input Parameters:
1011 +   name - string that gives the name of the function being called
1012 -   routine - actual call to the routine, including ierr = and CHKERRQ(ierr);
1013 
1014    Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes
1015 
1016    Developer Note: this is so that when a user or external library routine results in a crash or corrupts memory, they get blamed instead of PETSc.
1017 
1018 */
1019 #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while (0)
1020 
1021 /*
1022     PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack.
1023 
1024    Input Parameters:
1025 +   func-  name of the routine
1026 -   args - arguments to the routine surrounded by ()
1027 
1028    Notes:
1029     This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not.
1030 
1031    Developer Note: this is so that when an external packge routine results in a crash or corrupts memory, they get blamed instead of PETSc.
1032 
1033 */
1034 #define PetscStackCallStandard(func,args) do {                                                            \
1035     PetscErrorCode __ierr;                                                                                \
1036     PetscStackPush(#func);                                                                                \
1037     __ierr = func args;                                                                                   \
1038     PetscStackPop;                                                                                        \
1039     if (__ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)__ierr); \
1040   } while (0)
1041 
1042 #else /* !PETSC_CLANG_STATIC_ANALYZER */
1043 #define PetscStackPushNoCheck(funct,petsc_routine,hot)
1044 #define PetscStackPopNoCheck
1045 #define PetscStackClearTop
1046 #define PetscFunctionBegin
1047 #define PetscFunctionBeginUser
1048 #define PetscFunctionBeginHot
1049 #define PetscFunctionReturn(a)    return a
1050 #define PetscFunctionReturnVoid() return
1051 #define PetscStackPop
1052 #define PetscStackPush(f)
1053 #define PetscStackCall(name,routine)
1054 #define PetscStackCallStandard(name,routine)
1055 #endif /* !PETSC_CLANG_STATIC_ANALYZER */
1056 
1057 #endif
1058