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