xref: /petsc/include/petscerror.h (revision 90c9181efdd47e647627741a026b29a12dfd3064)
1 /*
2     Contains all error handling interfaces for PETSc.
3 */
4 #ifndef PETSCERROR_H
5 #define PETSCERROR_H
6 
7 #include <petscmacros.h>
8 #include <petscsystypes.h>
9 
10 /* SUBMANSEC = Sys */
11 
12 /*
13      These are the generic error codes. These error codes are used
14      many different places in the PETSc source code. The string versions are
15      at src/sys/error/err.c any changes here must also be made there
16      These are also define in src/sys/f90-mod/petscerror.h any CHANGES here
17      must be also made there.
18 
19 */
20 #define PETSC_ERR_MIN_VALUE 54 /* should always be one less then the smallest value */
21 
22 #define PETSC_ERR_MEM            55 /* unable to allocate requested memory */
23 #define PETSC_ERR_SUP            56 /* no support for requested operation */
24 #define PETSC_ERR_SUP_SYS        57 /* no support for requested operation on this computer system */
25 #define PETSC_ERR_ORDER          58 /* operation done in wrong order */
26 #define PETSC_ERR_SIG            59 /* signal received */
27 #define PETSC_ERR_FP             72 /* floating point exception */
28 #define PETSC_ERR_COR            74 /* corrupted PETSc object */
29 #define PETSC_ERR_LIB            76 /* error in library called by PETSc */
30 #define PETSC_ERR_PLIB           77 /* PETSc library generated inconsistent data */
31 #define PETSC_ERR_MEMC           78 /* memory corruption */
32 #define PETSC_ERR_CONV_FAILED    82 /* iterative method (KSP or SNES) failed */
33 #define PETSC_ERR_USER           83 /* user has not provided needed function */
34 #define PETSC_ERR_SYS            88 /* error in system call */
35 #define PETSC_ERR_POINTER        70 /* pointer does not point to valid address */
36 #define PETSC_ERR_MPI_LIB_INCOMP 87 /* MPI library at runtime is not compatible with MPI user compiled with */
37 
38 #define PETSC_ERR_ARG_SIZ          60 /* nonconforming object sizes used in operation */
39 #define PETSC_ERR_ARG_IDN          61 /* two arguments not allowed to be the same */
40 #define PETSC_ERR_ARG_WRONG        62 /* wrong argument (but object probably ok) */
41 #define PETSC_ERR_ARG_CORRUPT      64 /* null or corrupted PETSc object as argument */
42 #define PETSC_ERR_ARG_OUTOFRANGE   63 /* input argument, out of range */
43 #define PETSC_ERR_ARG_BADPTR       68 /* invalid pointer argument */
44 #define PETSC_ERR_ARG_NOTSAMETYPE  69 /* two args must be same object type */
45 #define PETSC_ERR_ARG_NOTSAMECOMM  80 /* two args must be same communicators */
46 #define PETSC_ERR_ARG_WRONGSTATE   73 /* object in argument is in wrong state, e.g. unassembled mat */
47 #define PETSC_ERR_ARG_TYPENOTSET   89 /* the type of the object has not yet been set */
48 #define PETSC_ERR_ARG_INCOMP       75 /* two arguments are incompatible */
49 #define PETSC_ERR_ARG_NULL         85 /* argument is null that should not be */
50 #define PETSC_ERR_ARG_UNKNOWN_TYPE 86 /* type name doesn't match any registered type */
51 
52 #define PETSC_ERR_FILE_OPEN       65 /* unable to open file */
53 #define PETSC_ERR_FILE_READ       66 /* unable to read from file */
54 #define PETSC_ERR_FILE_WRITE      67 /* unable to write to file */
55 #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */
56 
57 #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */
58 #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */
59 
60 #define PETSC_ERR_INT_OVERFLOW 84
61 
62 #define PETSC_ERR_FLOP_COUNT     90
63 #define PETSC_ERR_NOT_CONVERGED  91  /* solver did not converge */
64 #define PETSC_ERR_MISSING_FACTOR 92  /* MatGetFactor() failed */
65 #define PETSC_ERR_OPT_OVERWRITE  93  /* attempted to over write options which should not be changed */
66 #define PETSC_ERR_WRONG_MPI_SIZE 94  /* example/application run with number of MPI ranks it does not support */
67 #define PETSC_ERR_USER_INPUT     95  /* missing or incorrect user input */
68 #define PETSC_ERR_GPU_RESOURCE   96  /* unable to load a GPU resource, for example cuBLAS */
69 #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 */
70 #define PETSC_ERR_MPI            98  /* general MPI error */
71 #define PETSC_ERR_RETURN         99  /* PetscError() incorrectly returned an error code of 0 */
72 #define PETSC_ERR_MAX_VALUE      100 /* this is always the one more than the largest error code */
73 
74 #define SETERRQ1(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__)
75 #define SETERRQ2(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__)
76 #define SETERRQ3(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__)
77 #define SETERRQ4(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__)
78 #define SETERRQ5(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__)
79 #define SETERRQ6(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__)
80 #define SETERRQ7(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__)
81 #define SETERRQ8(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__)
82 #define SETERRQ9(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__)
83 
84 /*MC
85    SETERRQ - Macro to be called when an error has been detected,
86 
87    Synopsis:
88    #include <petscsys.h>
89    PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message,...)
90 
91    Collective
92 
93    Input Parameters:
94 +  comm - A communicator, use `PETSC_COMM_SELF` unless you know all ranks of another communicator will detect the error
95 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
96 -  message - error message
97 
98   Level: beginner
99 
100    Notes:
101     This is rarely needed, one should use `PetscCheck()` and `PetscCall()` and friends to automatically handle error conditions.
102     Once the error handler is called the calling function is then returned from with the given error code.
103 
104     Experienced users can set the error handler with `PetscPushErrorHandler()`.
105 
106    Fortran Notes:
107       SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the
108       Fortran main program.
109 
110 .seealso: `PetscCheck()`, `PetscAssert()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`,
111           `PetscError()`, `PetscCall()`, `CHKMEMQ`, `CHKERRA()`, `PetscCallMPI()`
112 M*/
113 #define SETERRQ(comm, ierr, ...) \
114   do { \
115     PetscErrorCode ierr_seterrq_petsc_ = PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr, PETSC_ERROR_INITIAL, __VA_ARGS__); \
116     return ierr_seterrq_petsc_ ? ierr_seterrq_petsc_ : PETSC_ERR_RETURN; \
117   } while (0)
118 
119 /*
120     Returned from PETSc functions that are called from MPI, such as related to attributes
121       Do not confuse PETSC_MPI_ERROR_CODE and PETSC_ERR_MPI, the first is registered with MPI and returned to MPI as
122       an error code, the latter is a regular PETSc error code passed within PETSc code indicating an error was detected in an MPI call.
123 */
124 PETSC_EXTERN PetscMPIInt PETSC_MPI_ERROR_CLASS;
125 PETSC_EXTERN PetscMPIInt PETSC_MPI_ERROR_CODE;
126 
127 /*MC
128    SETERRMPI - Macro to be called when an error has been detected within an MPI callback function
129 
130    Synopsis:
131    #include <petscsys.h>
132    PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message,...)
133 
134    Collective
135 
136    Input Parameters:
137 +  comm - A communicator, use `PETSC_COMM_SELF` unless you know all ranks of another communicator will detect the error
138 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
139 -  message - error message
140 
141   Level: developer
142 
143    Notes:
144     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`
145     which is registered with `MPI_Add_error_code()` when PETSc is initialized.
146 
147 .seealso: `SETERRQ()`, `PetscCall()`, `PetscCallMPI()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, `PetscError()`, `CHKMEMQ`
148 M*/
149 #define SETERRMPI(comm, ierr, ...) return (PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr, PETSC_ERROR_INITIAL, __VA_ARGS__), PETSC_MPI_ERROR_CODE)
150 
151 /*MC
152    SETERRA - Fortran-only macro that can be called when an error has been detected from the main program
153 
154    Synopsis:
155    #include <petscsys.h>
156    PetscErrorCode SETERRA(MPI_Comm comm,PetscErrorCode ierr,char *message)
157 
158    Collective
159 
160    Input Parameters:
161 +  comm - A communicator, so that the error can be collective
162 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
163 -  message - error message in the printf format
164 
165   Level: beginner
166 
167    Notes:
168     This should only be used with Fortran. With C/C++, use `SETERRQ()`.
169 
170    Fortran Notes:
171       `SETERRQ()` may be called from Fortran subroutines but `SETERRA()` must be called from the
172       Fortran main program.
173 
174 .seealso: `SETERRQ()`, `SETERRABORT()`, `PetscCall()`, `CHKERRA()`, `PetscCallAbort()`
175 M*/
176 
177 /*MC
178    SETERRABORT - Macro that can be called when an error has been detected,
179 
180    Synopsis:
181    #include <petscsys.h>
182    PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message,...)
183 
184    Collective
185 
186    Input Parameters:
187 +  comm - A communicator, so that the error can be collective
188 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
189 -  message - error message in the printf format
190 
191   Level: beginner
192 
193    Notes:
194     This function just calls `MPI_Abort()`.
195 
196     This should only be called in routines that cannot return an error code, such as in C++ constructors.
197 
198 .seealso: `SETERRQ()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, `PetscError()`, `PetscCall()`, `CHKMEMQ`
199 M*/
200 #define SETERRABORT(comm, ierr, ...) \
201   do { \
202     PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr, PETSC_ERROR_INITIAL, __VA_ARGS__); \
203     MPI_Abort(comm, ierr); \
204   } while (0)
205 
206 /*MC
207   PetscCheck - Check that a particular condition is true
208 
209   Synopsis:
210   #include <petscerror.h>
211   void PetscCheck(bool cond, MPI_Comm comm, PetscErrorCode ierr, const char *message, ...)
212 
213   Collective
214 
215   Input Parameters:
216 + cond    - The boolean condition
217 . comm    - The communicator on which the check can be collective on
218 . ierr    - A nonzero error code, see include/petscerror.h for the complete list
219 - message - Error message in printf format
220 
221   Notes:
222   Enabled in both optimized and debug builds.
223 
224   Calls `SETERRQ()` if the assertion fails, so can only be called from functions returning a
225   `PetscErrorCode` (or equivalent type after conversion).
226 
227   Level: beginner
228 
229 .seealso: `PetscAssert()`, `SETERRQ()`, `PetscError()`, `PetscCall()`, `PetscCheckAbort()`
230 M*/
231 #define PetscCheck(cond, comm, ierr, ...) \
232   do { \
233     if (PetscUnlikely(!(cond))) SETERRQ(comm, ierr, __VA_ARGS__); \
234   } while (0)
235 
236 /*MC
237   PetscCheckAbort - Check that a particular condition is true, otherwise prints error and aborts
238 
239   Synopsis:
240   #include <petscerror.h>
241   void PetscCheckAbort(bool cond, MPI_Comm comm, PetscErrorCode ierr, const char *message, ...)
242 
243   Collective
244 
245   Input Parameters:
246 + cond    - The boolean condition
247 . comm    - The communicator on which the check can be collective on
248 . ierr    - A nonzero error code, see include/petscerror.h for the complete list
249 - message - Error message in printf format
250 
251   Notes:
252   Enabled in both optimized and debug builds.
253 
254   Calls `SETERRABORT()` if the assertion fails, can be called from a function that does not return an
255   error code, such as a C++ constructor. usually `PetscCheck()` should be used.
256 
257   Level: developer
258 
259 .seealso: `PetscAssertAbort()`, `PetscAssert()`, `SETERRQ()`, `PetscError()`, `PetscCall()`, `PetscCheck()`, `SETTERRABORT()`
260 M*/
261 #define PetscCheckAbort(cond, comm, ierr, ...) \
262   do { \
263     if (PetscUnlikely(!(cond))) SETERRABORT(comm, ierr, __VA_ARGS__); \
264   } while (0)
265 
266 /*MC
267   PetscAssert - Assert that a particular condition is true
268 
269   Synopsis:
270   #include <petscerror.h>
271   void PetscAssert(bool cond, MPI_Comm comm, PetscErrorCode ierr, const char *message, ...)
272 
273   Collective
274 
275   Input Parameters:
276 + cond    - The boolean condition
277 . comm    - The communicator on which the check can be collective on
278 . ierr    - A nonzero error code, see include/petscerror.h for the complete list
279 - message - Error message in printf format
280 
281   Notes:
282   Equivalent to `PetscCheck()` if debugging is enabled, and `PetscAssume(cond)` otherwise.
283 
284   See `PetscCheck()` for usage and behaviour.
285 
286   This is needed instead of simply using `assert()` because this correctly handles the collective nature of errors under MPI
287 
288   Level: beginner
289 
290 .seealso: `PetscCheck()`, `SETERRQ()`, `PetscError()`, `PetscAssertAbort()`
291 M*/
292 #if PetscDefined(USE_DEBUG)
293   #define PetscAssert(cond, comm, ierr, ...) PetscCheck(cond, comm, ierr, __VA_ARGS__)
294 #else
295   #define PetscAssert(cond, ...) PetscAssume(cond)
296 #endif
297 
298 /*MC
299   PetscAssertAbort - Assert that a particular condition is true, otherwise prints error and aborts
300 
301   Synopsis:
302   #include <petscerror.h>
303   void PetscAssertAbort(bool cond, MPI_Comm comm, PetscErrorCode ierr, const char *message, ...)
304 
305   Collective
306 
307   Input Parameters:
308 + cond    - The boolean condition
309 . comm    - The communicator on which the check can be collective on
310 . ierr    - A nonzero error code, see include/petscerror.h for the complete list
311 - message - Error message in printf format
312 
313   Notes:
314   Enabled only in debug builds. See `PetscCheckAbort()` for usage.
315 
316   Level: beginner
317 
318 .seealso: `PetscCheckAbort()`, `PetscAssert()`, `PetscCheck()`, `SETERRABORT()`, `PetscError()`
319 M*/
320 #define PetscAssertAbort(cond, comm, ierr, ...) \
321   do { \
322     if (PetscUnlikelyDebug(!(cond))) SETERRABORT(comm, ierr, __VA_ARGS__); \
323   } while (0)
324 
325 /*MC
326   PetscCall - Calls a PETSc function and then checks the resulting error code, if it is non-zero it calls the error
327   handler and returns from the current function with the error code.
328 
329   Synopsis:
330   #include <petscerror.h>
331   void PetscCall(PetscFunction(args))
332 
333   Not Collective
334 
335   Input Parameter:
336 . PetscFunction - any PETSc function that returns an error code
337 
338   Notes:
339   Once the error handler is called the calling function is then returned from with the given
340   error code. Experienced users can set the error handler with `PetscPushErrorHandler()`.
341 
342   `PetscCall()` cannot be used in functions returning a datatype not convertible to
343   `PetscErrorCode`. For example, `PetscCall()` may not be used in functions returning void, use
344   `PetscCallVoid()` in this case.
345 
346   Example Usage:
347 .vb
348   PetscCall(PetscInitiailize(...)); // OK to call even when PETSc is not yet initialized!
349 
350   struct my_struct
351   {
352     void *data;
353   } my_complex_type;
354 
355   struct my_struct bar(void)
356   {
357     PetscCall(foo(15)); // ERROR PetscErrorCode not convertible to struct my_struct!
358   }
359 
360   PetscCall(bar()) // ERROR input not convertible to PetscErrorCode
361 .ve
362 
363   It is also possible to call this directly on a `PetscErrorCode` variable
364 .vb
365   PetscCall(ierr);  // check if ierr is nonzero
366 .ve
367 
368   Should not be used to call callback functions provided by users, `PetscCallBack()` should be used in that situation.
369 
370   `PetscUseTypeMethod()` or `PetscTryTypeMethod()` should be used when calling functions pointers contained in a PETSc object's `ops` array
371 
372   Fortran Notes:
373     The Fortran function from which this is used must declare a variable PetscErrorCode ierr and ierr must be
374     the final argument to the PETSc function being called.
375 
376     In the main program and in Fortran subroutines that do not have ierr as the final return parameter one
377     should use `PetscCallA()`
378 
379   Example Fortran Usage:
380 .vb
381   PetscErrorCode ierr
382   Vec v
383 
384   ...
385   PetscCall(VecShift(v,1.0,ierr))
386   PetscCallA(VecShift(v,1.0,ierr))
387 .ve
388 
389   Level: beginner
390 
391 .seealso: `SETERRQ()`, `PetscCheck()`, `PetscAssert()`, `PetscTraceBackErrorHandler()`, `PetscCallMPI()`
392           `PetscPushErrorHandler()`, `PetscError()`, `CHKMEMQ`, `CHKERRA()`, `CHKERRMPI()`, `PetscCallBack()`
393 M*/
394 
395 /*MC
396   PetscCallBack - Calls a user provided PETSc callback function and then checks the resulting error code, if it is non-zero it calls the error
397   handler and returns from the current function with the error code.
398 
399   Synopsis:
400   #include <petscerror.h>
401   void PetscCallBack(const char *functionname,PetscFunction(args))
402 
403   Not Collective
404 
405   Input Parameters:
406 + functionname - the name of the function being called, this can be a string with spaces that describes the meaning of the callback
407 - PetscFunction - user provided callback function that returns an error code
408 
409   Notes:
410   Once the error handler is called the calling function is then returned from with the given
411   error code. Experienced users can set the error handler with `PetscPushErrorHandler()`.
412 
413   `PetscCallBack()` should only be called in PETSc when a call is being made to a user provided call-back routine.
414 
415   Example Usage:
416 .vb
417   PetscCallBack("XXX callback to do something",a->callback(...));
418 .ve
419 
420   Level: developer
421 
422 .seealso: `SETERRQ()`, `PetscCheck()`, `PetscCall()`, `PetscAssert()`, `PetscTraceBackErrorHandler()`, `PetscCallMPI()`
423           `PetscPushErrorHandler()`, `PetscError()`, `CHKMEMQ`, `CHKERRA()`, `CHKERRMPI()`, `PetscCall()`
424 M*/
425 
426 #if defined(PETSC_CLANG_STATIC_ANALYZER)
427 void PetscCall(PetscErrorCode);
428 void PetscCallBack(const char *, PetscErrorCode);
429 void PetscCallVoid(PetscErrorCode);
430 #else
431   #define PetscCall(...) \
432     do { \
433       PetscErrorCode ierr_q_; \
434       PetscStackUpdateLine; \
435       ierr_q_ = __VA_ARGS__; \
436       if (PetscUnlikely(ierr_q_)) return PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_q_, PETSC_ERROR_REPEAT, " "); \
437     } while (0)
438   #define PetscCallBack(function, ...) \
439     do { \
440       PetscErrorCode ierr_q_; \
441       PetscStackUpdateLine; \
442       PetscStackPushExternal(function); \
443       ierr_q_ = __VA_ARGS__; \
444       PetscStackPop; \
445       if (PetscUnlikely(ierr_q_)) return PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_q_, PETSC_ERROR_REPEAT, " "); \
446     } while (0)
447   #define PetscCallVoid(...) \
448     do { \
449       PetscErrorCode ierr_void_; \
450       PetscStackUpdateLine; \
451       ierr_void_ = __VA_ARGS__; \
452       if (PetscUnlikely(ierr_void_)) { \
453         (void)PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_void_, PETSC_ERROR_REPEAT, " "); \
454         return; \
455       } \
456     } while (0)
457 #endif
458 
459 /*MC
460   CHKERRQ - Checks error code returned from PETSc function
461 
462   Synopsis:
463   #include <petscsys.h>
464   void CHKERRQ(PetscErrorCode ierr)
465 
466   Not Collective
467 
468   Input Parameters:
469 . ierr - nonzero error code
470 
471   Notes:
472   Deprecated in favor of `PetscCall()`. This routine behaves identically to it.
473 
474   Level: deprecated
475 
476 .seealso: `PetscCall()`
477 M*/
478 #define CHKERRQ(...) PetscCall(__VA_ARGS__)
479 #define CHKERRV(...) PetscCallVoid(__VA_ARGS__)
480 
481 PETSC_EXTERN void PetscMPIErrorString(PetscMPIInt, char *);
482 
483 /*MC
484   PetscCallMPI - Checks error code returned from MPI calls, if non-zero it calls the error
485   handler and then returns
486 
487   Synopsis:
488   #include <petscerror.h>
489   void PetscCallMPI(MPI_Function(args))
490 
491   Not Collective
492 
493   Input Parameters:
494 . MPI_Function - an MPI function that returns an MPI error code
495 
496   Notes:
497   Always returns the error code `PETSC_ERR_MPI`; the MPI error code and string are embedded in
498   the string error message. Do not use this to call any other routines (for example PETSc
499   routines), it should only be used for direct MPI calls. Due to limitations of the
500   preprocessor this can unfortunately not easily be enforced, so the user should take care to
501   check this themselves.
502 
503   Example Usage:
504 .vb
505   PetscCallMPI(MPI_Comm_size(...)); // OK, calling MPI function
506 
507   PetscCallMPI(PetscFunction(...)); // ERROR, use PetscCall() instead!
508 .ve
509 
510   Fortran Notes:
511     The Fortran function from which this is used must declare a variable `PetscErrorCode` ierr and ierr must be
512     the final argument to the MPI function being called.
513 
514     In the main program and in Fortran subroutines that do not have ierr as the final return parameter one
515     should use `PetscCallMPIA()`
516 
517   Fortran Usage:
518 .vb
519   PetscErrorCode ierr or integer ierr
520   ...
521   PetscCallMPI(MPI_Comm_size(...,ierr))
522   PetscCallMPIA(MPI_Comm_size(...,ierr)) ! Will abort after calling error handler
523 
524   PetscCallMPI(MPI_Comm_size(...,eflag)) ! ERROR, final argument must be ierr
525 .ve
526 
527   Level: beginner
528 
529 .seealso: `SETERRMPI()`, `PetscCall()`, `SETERRQ()`, `SETERRABORT()`, `PetscCallAbort()`,
530           `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, `PetscError()`, `CHKMEMQ`
531 M*/
532 #if defined(PETSC_CLANG_STATIC_ANALYZER)
533 void PetscCallMPI(PetscMPIInt);
534 #else
535   #define PetscCallMPI(...) \
536     do { \
537       PetscMPIInt _7_errorcode; \
538       char        _7_errorstring[2 * MPI_MAX_ERROR_STRING]; \
539       PetscStackUpdateLine; \
540       PetscStackPushExternal("MPI function"); \
541       { \
542         _7_errorcode = __VA_ARGS__; \
543       } \
544       PetscStackPop; \
545       if (PetscUnlikely(_7_errorcode)) { \
546         PetscMPIErrorString(_7_errorcode, (char *)_7_errorstring); \
547         SETERRQ(PETSC_COMM_SELF, PETSC_ERR_MPI, "MPI error %d %s", (int)_7_errorcode, _7_errorstring); \
548       } \
549     } while (0)
550 #endif
551 
552 /*MC
553   CHKERRMPI - Checks error code returned from MPI calls, if non-zero it calls the error
554   handler and then returns
555 
556   Synopsis:
557   #include <petscerror.h>
558   void CHKERRMPI(PetscErrorCode ierr)
559 
560   Not Collective
561 
562   Input Parameter:
563 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
564 
565   Notes:
566   Deprecated in favor of `PetscCallMPI()`. This routine behaves identically to it.
567 
568   Level: deprecated
569 
570 .seealso: `PetscCallMPI()`
571 M*/
572 #define CHKERRMPI(...) PetscCallMPI(__VA_ARGS__)
573 
574 /*MC
575   PetscCallAbort - Checks error code returned from PETSc function, if non-zero it aborts immediately
576 
577   Synopsis:
578   #include <petscerror.h>
579   void PetscCallAbort(MPI_Comm comm, PetscErrorCode ierr)
580 
581   Collective on comm
582 
583   Input Parameters:
584 + comm - the MPI communicator on which to abort
585 - ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
586 
587   Notes:
588   This macro has identical type and usage semantics to `PetscCall()` with the important caveat
589   that this macro does not return. Instead, if ierr is nonzero it calls the PETSc error handler
590   and then immediately calls `MPI_Abort()`. It can therefore be used anywhere.
591 
592   As per `MPI_Abort()` semantics the communicator passed must be valid, although there is currently
593   no attempt made at handling any potential errors from `MPI_Abort()`. Note that while
594   `MPI_Abort()` is required to terminate only those processes which reside on comm, it is often
595   the case that `MPI_Abort()` terminates *all* processes.
596 
597   Example Usage:
598 .vb
599   PetscErrorCode boom(void) { return PETSC_ERR_MEM; }
600 
601   void foo(void)
602   {
603     PetscCallAbort(PETSC_COMM_WORLD,boom()); // OK, does not return a type
604   }
605 
606   double bar(void)
607   {
608     PetscCallAbort(PETSC_COMM_WORLD,boom()); // OK, does not return a type
609   }
610 
611   PetscCallAbort(MPI_COMM_NULL,boom()); // ERROR, communicator should be valid
612 
613   struct baz
614   {
615     baz()
616     {
617       PetscCallAbort(PETSC_COMM_SELF,boom()); // OK
618     }
619 
620     ~baz()
621     {
622       PetscCallAbort(PETSC_COMM_SELF,boom()); // OK (in fact the only way to handle PETSc errors)
623     }
624   };
625 .ve
626 
627   Level: intermediate
628 
629 .seealso: `SETERRABORT()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, `PetscError()`,
630           `SETERRQ()`, `CHKMEMQ`, `PetscCallMPI()`, `PetscCallCXXAbort()`
631 M*/
632 #if defined(PETSC_CLANG_STATIC_ANALYZER)
633 void PetscCallAbort(MPI_Comm, PetscErrorCode);
634 void PetscCallContinue(PetscErrorCode);
635 #else
636   #define PetscCallAbort(comm, ...) \
637     do { \
638       PetscErrorCode ierr_abort_ = __VA_ARGS__; \
639       if (PetscUnlikely(ierr_abort_)) { \
640         PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_abort_, PETSC_ERROR_REPEAT, " "); \
641         MPI_Abort(comm, ierr_abort_); \
642       } \
643     } while (0)
644   #define PetscCallContinue(...) \
645     do { \
646       PetscErrorCode ierr_continue_ = __VA_ARGS__; \
647       if (PetscUnlikely(ierr_continue_)) PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_continue_, PETSC_ERROR_REPEAT, " "); \
648     } while (0)
649 #endif
650 
651 /*MC
652   CHKERRABORT - Checks error code returned from PETSc function. If non-zero it aborts immediately.
653 
654   Synopsis:
655   #include <petscerror.h>
656   void CHKERRABORT(MPI_Comm comm, PetscErrorCode ierr)
657 
658   Not Collective
659 
660   Input Parameters:
661 + comm - the MPI communicator
662 - ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
663 
664   Notes:
665   Deprecated in favor of `PetscCallAbort()`. This routine behaves identically to it.
666 
667   Level: deprecated
668 
669 .seealso: `PetscCallAbort()`
670 M*/
671 #define CHKERRABORT(comm, ...) PetscCallAbort(comm, __VA_ARGS__)
672 #define CHKERRCONTINUE(...)    PetscCallContinue(__VA_ARGS__)
673 
674 /*MC
675    CHKERRA - Fortran-only replacement for use of `CHKERRQ()` in the main program, which aborts immediately
676 
677    Synopsis:
678    #include <petscsys.h>
679    PetscErrorCode CHKERRA(PetscErrorCode ierr)
680 
681    Not Collective
682 
683    Input Parameters:
684 .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
685 
686   Level: deprecated
687 
688    Note:
689    This macro is rarely needed, normal usage is `PetscCallA()` in the main Fortran program.
690 
691 .seealso: `PetscCall()`, `PetscCallA()`, `PetscCallAbort()`, `CHKERRQ()`, `SETERRA()`, `SETERRQ()`, `SETERRABORT()`
692 M*/
693 
694 PETSC_EXTERN PetscBool petscwaitonerrorflg;
695 PETSC_EXTERN PetscBool petscindebugger;
696 
697 /*MC
698    PETSCABORT - Call MPI_Abort with an informative error code
699 
700    Synopsis:
701    #include <petscsys.h>
702    PETSCABORT(MPI_Comm comm, PetscErrorCode ierr)
703 
704    Collective
705 
706    Input Parameters:
707 +  comm - A communicator, so that the error can be collective
708 -  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
709 
710    Level: advanced
711 
712    Notes:
713    If the option -start_in_debugger was used then this calls abort() to stop the program in the debugger.
714 
715    if `PetscCIEnabledPortableErrorOutput` is set it strives to exit cleanly without call `MPI_Abort()`
716 
717  M*/
718 #define PETSCABORT(comm, ...) \
719   do { \
720     if (petscwaitonerrorflg) PetscSleep(1000); \
721     if (petscindebugger) abort(); \
722     else { \
723       PetscErrorCode ierr_petsc_abort_ = __VA_ARGS__; \
724       PetscMPIInt    size; \
725       MPI_Comm_size(comm, &size); \
726       if (PetscCIEnabledPortableErrorOutput && size == PetscGlobalSize && ierr_petsc_abort_ != PETSC_ERR_SIG) { \
727         MPI_Finalize(); \
728         exit(0); \
729       } else if (PetscCIEnabledPortableErrorOutput && PetscGlobalSize == 1) { \
730         exit(0); \
731       } else { \
732         MPI_Abort(comm, (PetscMPIInt)ierr_petsc_abort_); \
733       } \
734     } \
735   } while (0)
736 
737 #ifdef PETSC_CLANGUAGE_CXX
738   /*MC
739   PetscCallThrow - Checks error code, if non-zero it calls the C++ error handler which throws
740   an exception
741 
742   Synopsis:
743   #include <petscerror.h>
744   void PetscCallThrow(PetscErrorCode ierr)
745 
746   Not Collective
747 
748   Input Parameter:
749 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
750 
751   Notes:
752   Requires PETSc to be configured with clanguage = c++. Throws a std::runtime_error() on error.
753 
754   Once the error handler throws the exception you can use `PetscCallVoid()` which returns without
755   an error code (bad idea since the error is ignored) or `PetscCallAbort()` to have `MPI_Abort()`
756   called immediately.
757 
758   Level: beginner
759 
760 .seealso: `SETERRQ()`, `PetscCall()`, `SETERRABORT()`, `PetscCallAbort()`, `PetscTraceBackErrorHandler()`,
761           `PetscPushErrorHandler()`, `PetscError()`, `CHKMEMQ`
762 M*/
763   #define PetscCallThrow(...) \
764     do { \
765       PetscErrorCode ierr_cxx_ = __VA_ARGS__; \
766       if (PetscUnlikely(ierr_cxx_)) PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_cxx_, PETSC_ERROR_IN_CXX, PETSC_NULLPTR); \
767     } while (0)
768 
769   /*MC
770   CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
771 
772   Synopsis:
773   #include <petscerror.h>
774   void CHKERRXX(PetscErrorCode ierr)
775 
776   Not Collective
777 
778   Input Parameter:
779 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
780 
781   Notes:
782   Deprecated in favor of `PetscCallThrow()`. This routine behaves identically to it.
783 
784   Level: deprecated
785 
786 .seealso: `PetscCallThrow()`
787 M*/
788   #define CHKERRXX(...) PetscCallThrow(__VA_ARGS__)
789 #endif
790 
791 /*MC
792   PetscCallCXX - Checks C++ function calls and if they throw an exception, catch it and then
793   return a PETSc error code
794 
795   Synopsis:
796   #include <petscerror.h>
797   void PetscCallCXX(...) noexcept;
798 
799   Not Collective
800 
801   Input Parameter:
802 . __VA_ARGS__ - An arbitrary expression
803 
804   Level: beginner
805 
806   Notes:
807   `PetscCallCXX(...)` is a macro replacement for
808 .vb
809   try {
810     __VA_ARGS__;
811   } catch (const std::exception& e) {
812     return ConvertToPetscErrorCode(e);
813   }
814 .ve
815   Due to the fact that it catches any (reasonable) exception, it is essentially noexcept.
816 
817   If you cannot return a `PetscErrorCode` use `PetscCallCXXAbort()` instead.
818 
819   Example Usage:
820 .vb
821   void foo(void) { throw std::runtime_error("error"); }
822 
823   void bar()
824   {
825     PetscCallCXX(foo()); // ERROR bar() does not return PetscErrorCode
826   }
827 
828   PetscErrorCode baz()
829   {
830     PetscCallCXX(foo()); // OK
831 
832     PetscCallCXX(
833       bar();
834       foo(); // OK multiple statements allowed
835     );
836   }
837 
838   struct bop
839   {
840     bop()
841     {
842       PetscCallCXX(foo()); // ERROR returns PetscErrorCode, cannot be used in constructors
843     }
844   };
845 
846   // ERROR contains do-while, cannot be used as function-try block
847   PetscErrorCode qux() PetscCallCXX(
848     bar();
849     baz();
850     foo();
851     return 0;
852   )
853 .ve
854 
855 .seealso: `PetscCallCXXAbort()`, `PetscCallThrow()`, `SETERRQ()`, `PetscCall()`,
856 `SETERRABORT()`, `PetscCallAbort()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`,
857 `PetscError()`, `CHKMEMQ`
858 M*/
859 #if defined(PETSC_CLANG_STATIC_ANALYZER)
860 void PetscCallCXX(PetscErrorCode);
861 #else
862   #define PetscCallCXX(...) \
863     do { \
864       PetscStackUpdateLine; \
865       try { \
866         __VA_ARGS__; \
867       } catch (const std::exception &e) { \
868         SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "%s", e.what()); \
869       } \
870     } while (0)
871 #endif
872 
873 /*MC
874   PetscCallCXXAbort - Like `PetscCallCXX()` but calls `MPI_Abort()` instead of returning an
875   error-code
876 
877   Synopsis:
878   #include <petscerror.h>
879   void PetscCallCXXAbort(MPI_Comm comm, ...) noexcept;
880 
881   Collective on `comm`
882 
883   Input Parameters:
884 + comm        - The MPI communicator to abort on
885 - __VA_ARGS__ - An arbitrary expression
886 
887   Level: beginner
888 
889   Notes:
890   This macro may be used to check C++ expressions for exceptions in cases where you cannot
891   return an error code. This includes constructors, destructors, copy/move assignment functions
892   or constructors among others.
893 
894   If an exception is caught, the macro calls `SETERRABORT()` on `comm`. The exception must
895   derive from `std::exception` in order to be caught.
896 
897   If the routine _can_ return an error-code it is highly advised to use `PetscCallCXX()`
898   instead.
899 
900   See `PetscCallCXX()` for additional discussion.
901 
902   Fortran Note:
903   Not available from Fortran.
904 
905   Example Usage:
906 .vb
907   class Foo
908   {
909     std::vector<int> data_;
910 
911   public:
912     // normally std::vector::reserve() may raise an exception, but since we handle it with
913     // PetscCallCXXAbort() we may mark this routine as noexcept!
914     Foo() noexcept
915     {
916       PetscCallCXXAbort(PETSC_COMM_SELF, data_.reserve(10));
917     }
918   };
919 
920   std::vector<int> bar()
921   {
922     std::vector<int> v;
923 
924     PetscFunctionBegin;
925     // OK!
926     PetscCallCXXAbort(PETSC_COMM_SELF, v.emplace_back(1));
927     PetscFunctionReturn(v);
928   }
929 
930   PetscErrorCode baz()
931   {
932     std::vector<int> v;
933 
934     PetscFunctionBegin;
935     // WRONG! baz() returns a PetscErrorCode, prefer PetscCallCXX() instead
936     PetscCallCXXAbort(PETSC_COMM_SELF, v.emplace_back(1));
937     PetscFunctionReturn(0);
938   }
939 .ve
940 
941 .seealso: `PetscCallCXX()`, `SETERRABORT()`, `PetscCallAbort()`
942 M*/
943 #define PetscCallCXXAbort(comm, ...) \
944   do { \
945     PetscStackUpdateLine; \
946     try { \
947       __VA_ARGS__; \
948     } catch (const std::exception &e) { \
949       SETERRABORT(comm, PETSC_ERR_LIB, "%s", e.what()); \
950     } \
951   } while (0)
952 
953 #define PetscCallCXXAbort(comm, ...) \
954   do { \
955     PetscStackUpdateLine; \
956     try { \
957       __VA_ARGS__; \
958     } catch (const std::exception &e) { \
959       SETERRABORT(comm, PETSC_ERR_LIB, "%s", e.what()); \
960     } \
961   } while (0)
962 
963 /*MC
964   CHKERRCXX - Checks C++ function calls and if they throw an exception, catch it and then
965   return a PETSc error code
966 
967   Synopsis:
968   #include <petscerror.h>
969   void CHKERRCXX(func) noexcept;
970 
971   Not Collective
972 
973   Input Parameter:
974 . func - C++ function calls
975 
976   Notes:
977   Deprecated in favor of `PetscCallCXX()`. This routine behaves identically to it.
978 
979   Level: deprecated
980 
981 .seealso: `PetscCallCXX()`
982 M*/
983 #define CHKERRCXX(...) PetscCallCXX(__VA_ARGS__)
984 
985 /*MC
986    CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
987 
988    Synopsis:
989    #include <petscsys.h>
990    CHKMEMQ;
991 
992    Not Collective
993 
994   Level: beginner
995 
996    Notes:
997     We highly recommend using Valgrind https://petsc.org/release/faq/#valgrind or for NVIDIA CUDA systems
998     https://docs.nvidia.com/cuda/cuda-memcheck/index.html for finding memory problems. The ``CHKMEMQ`` macro is useful on systems that
999     do not have valgrind, but is not as good as valgrind or cuda-memcheck.
1000 
1001     Must run with the option -malloc_debug (-malloc_test in debug mode; or if `PetscMallocSetDebug()` called) to enable this option
1002 
1003     Once the error handler is called the calling function is then returned from with the given error code.
1004 
1005     By defaults prints location where memory that is corrupted was allocated.
1006 
1007     Use `CHKMEMA` for functions that return void
1008 
1009 .seealso: `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, `PetscError()`, `SETERRQ()`, `PetscMallocValidate()`
1010 M*/
1011 #if defined(PETSC_CLANG_STATIC_ANALYZER)
1012   #define CHKMEMQ
1013   #define CHKMEMA
1014 #else
1015   #define CHKMEMQ \
1016     do { \
1017       PetscErrorCode ierr_memq_ = PetscMallocValidate(__LINE__, PETSC_FUNCTION_NAME, __FILE__); \
1018       if (PetscUnlikely(ierr_memq_)) return PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_memq_, PETSC_ERROR_REPEAT, " "); \
1019     } while (0)
1020   #define CHKMEMA PetscMallocValidate(__LINE__, PETSC_FUNCTION_NAME, __FILE__)
1021 #endif
1022 
1023 /*E
1024   PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
1025 
1026   Level: advanced
1027 
1028   `PETSC_ERROR_IN_CXX` indicates the error was detected in C++ and an exception should be generated
1029 
1030   Developer Notes:
1031     This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()
1032 
1033 .seealso: `PetscError()`, `SETERRQ()`
1034 E*/
1035 typedef enum {
1036   PETSC_ERROR_INITIAL = 0,
1037   PETSC_ERROR_REPEAT  = 1,
1038   PETSC_ERROR_IN_CXX  = 2
1039 } PetscErrorType;
1040 
1041 #if defined(__clang_analyzer__)
1042 __attribute__((analyzer_noreturn))
1043 #endif
1044 PETSC_EXTERN PetscErrorCode
1045 PetscError(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, ...) PETSC_ATTRIBUTE_COLD PETSC_ATTRIBUTE_FORMAT(7, 8);
1046 
1047 PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
1048 PETSC_EXTERN PetscErrorCode PetscErrorMessage(int, const char *[], char **);
1049 PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD;
1050 PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD;
1051 PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD;
1052 PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD;
1053 PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD;
1054 PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD;
1055 PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD;
1056 PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *), void *);
1057 PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
1058 PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int, void *);
1059 PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int, void *), void *);
1060 PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
1061 PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt);
1062 PETSC_EXTERN void           PetscSignalSegvCheckPointerOrMpi(void);
1063 PETSC_DEPRECATED_FUNCTION("Use PetscSignalSegvCheckPointerOrMpi() (since version 3.13)") static inline void PetscSignalSegvCheckPointer(void)
1064 {
1065   PetscSignalSegvCheckPointerOrMpi();
1066 }
1067 
1068 /*MC
1069     PetscErrorPrintf - Prints error messages.
1070 
1071    Synopsis:
1072     #include <petscsys.h>
1073      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
1074 
1075     Not Collective
1076 
1077     Input Parameter:
1078 .   format - the usual printf() format string
1079 
1080    Options Database Keys:
1081 +    -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr
1082 -    -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)
1083 
1084    Notes:
1085     Use
1086 $     PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
1087 $                        error is handled.) and
1088 $     PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function
1089 
1090           Use
1091      `PETSC_STDERR` = FILE* obtained from a file open etc. to have stderr printed to the file.
1092      `PETSC_STDOUT` = FILE* obtained from a file open etc. to have stdout printed to the file.
1093 
1094           Use
1095       `PetscPushErrorHandler()` to provide your own error handler that determines what kind of messages to print
1096 
1097    Level: developer
1098 
1099     Fortran Note:
1100     This routine is not supported in Fortran.
1101 
1102 .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscHelpPrintf()`, `PetscPrintf()`, `PetscPushErrorHandler()`, `PetscVFPrintf()`, `PetscHelpPrintf()`
1103 M*/
1104 PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2);
1105 
1106 /*E
1107      PetscFPTrap - types of floating point exceptions that may be trapped
1108 
1109      Currently only `PETSC_FP_TRAP_OFF` and `PETSC_FP_TRAP_ON` are handled. All others are treated as `PETSC_FP_TRAP_ON`.
1110 
1111      Level: intermediate
1112 
1113 .seealso: `PetscSetFPTrap()`, `PetscPushFPTrap()`
1114  E*/
1115 typedef enum {
1116   PETSC_FP_TRAP_OFF      = 0,
1117   PETSC_FP_TRAP_INDIV    = 1,
1118   PETSC_FP_TRAP_FLTOPERR = 2,
1119   PETSC_FP_TRAP_FLTOVF   = 4,
1120   PETSC_FP_TRAP_FLTUND   = 8,
1121   PETSC_FP_TRAP_FLTDIV   = 16,
1122   PETSC_FP_TRAP_FLTINEX  = 32
1123 } PetscFPTrap;
1124 #define PETSC_FP_TRAP_ON (PetscFPTrap)(PETSC_FP_TRAP_INDIV | PETSC_FP_TRAP_FLTOPERR | PETSC_FP_TRAP_FLTOVF | PETSC_FP_TRAP_FLTDIV | PETSC_FP_TRAP_FLTINEX)
1125 PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
1126 PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
1127 PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);
1128 PETSC_EXTERN PetscErrorCode PetscDetermineInitialFPTrap(void);
1129 
1130 /*
1131       Allows the code to build a stack frame as it runs
1132 */
1133 
1134 #if defined(PETSC_USE_DEBUG)
1135   #define PETSCSTACKSIZE 64
1136 typedef struct {
1137   const char *function[PETSCSTACKSIZE];
1138   const char *file[PETSCSTACKSIZE];
1139   int         line[PETSCSTACKSIZE];
1140   int         petscroutine[PETSCSTACKSIZE]; /* 0 external called from petsc, 1 petsc functions, 2 petsc user functions */
1141   int         currentsize;
1142   int         hotdepth;
1143   PetscBool   check; /* option to check for correct Push/Pop semantics, true for default petscstack but not other stacks */
1144 } PetscStack;
1145 PETSC_EXTERN PetscStack petscstack;
1146 #else
1147 typedef struct {
1148   char Silence_empty_struct_has_size_0_in_C_size_1_in_Cpp;
1149 } PetscStack;
1150 #endif
1151 
1152 #if defined(PETSC_SERIALIZE_FUNCTIONS)
1153   #include <petsc/private/petscfptimpl.h>
1154   /*
1155    Registers the current function into the global function pointer to function name table
1156 
1157    Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
1158 */
1159   #define PetscRegister__FUNCT__() \
1160     do { \
1161       static PetscBool __chked = PETSC_FALSE; \
1162       if (!__chked) { \
1163         void *ptr; \
1164         PetscDLSym(NULL, PETSC_FUNCTION_NAME, &ptr); \
1165         __chked = PETSC_TRUE; \
1166       } \
1167     } while (0)
1168 #else
1169   #define PetscRegister__FUNCT__()
1170 #endif
1171 
1172 #if defined(PETSC_CLANG_STATIC_ANALYZER)
1173   #define PetscStackPushNoCheck(funct, petsc_routine, hot)
1174   #define PetscStackUpdateLine
1175   #define PetscStackPushExternal(funct)
1176   #define PetscStackPopNoCheck
1177   #define PetscStackClearTop
1178   #define PetscFunctionBegin
1179   #define PetscFunctionBeginUser
1180   #define PetscFunctionBeginHot
1181   #define PetscFunctionReturn(...)  return __VA_ARGS__
1182   #define PetscFunctionReturnVoid() return
1183   #define PetscStackPop
1184   #define PetscStackPush(f)
1185 #elif defined(PETSC_USE_DEBUG)
1186 
1187   #define PetscStackPush_Private(stack__, file__, func__, line__, petsc_routine__, hot__) \
1188     do { \
1189       if (stack__.currentsize < PETSCSTACKSIZE) { \
1190         stack__.function[stack__.currentsize] = func__; \
1191         if (petsc_routine__) { \
1192           stack__.file[stack__.currentsize] = file__; \
1193           stack__.line[stack__.currentsize] = line__; \
1194         } else { \
1195           stack__.file[stack__.currentsize] = PETSC_NULLPTR; \
1196           stack__.line[stack__.currentsize] = 0; \
1197         } \
1198         stack__.petscroutine[stack__.currentsize] = petsc_routine__; \
1199       } \
1200       ++stack__.currentsize; \
1201       stack__.hotdepth += (hot__ || stack__.hotdepth); \
1202     } while (0)
1203 
1204   /* uses PetscCheckAbort() because may be used in a function that does not return an error code */
1205   #define PetscStackPop_Private(stack__, func__) \
1206     do { \
1207       PetscCheckAbort(!stack__.check || stack__.currentsize > 0, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid stack size %d, pop %s %s:%d.\n", stack__.currentsize, func__, __FILE__, __LINE__); \
1208       if (--stack__.currentsize < PETSCSTACKSIZE) { \
1209         PetscCheckAbort(!stack__.check || stack__.petscroutine[stack__.currentsize] != 1 || stack__.function[stack__.currentsize] == (const char *)(func__), PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid stack: push from %s %s:%d. Pop from %s %s:%d.\n", \
1210                         stack__.function[stack__.currentsize], stack__.file[stack__.currentsize], stack__.line[stack__.currentsize], func__, __FILE__, __LINE__); \
1211         stack__.function[stack__.currentsize]     = PETSC_NULLPTR; \
1212         stack__.file[stack__.currentsize]         = PETSC_NULLPTR; \
1213         stack__.line[stack__.currentsize]         = 0; \
1214         stack__.petscroutine[stack__.currentsize] = 0; \
1215       } \
1216       stack__.hotdepth = PetscMax(stack__.hotdepth - 1, 0); \
1217     } while (0)
1218 
1219   /*MC
1220    PetscStackPushNoCheck - Pushes a new function name and line number onto the PETSc default stack that tracks where the running program is
1221    currently in the source code.
1222 
1223    Not Collective
1224 
1225    Synopsis:
1226    #include <petscsys.h>
1227    void PetscStackPushNoCheck(char *funct,int petsc_routine,PetscBool hot);
1228 
1229    Input Parameters:
1230 +  funct - the function name
1231 .  petsc_routine - 2 user function, 1 PETSc function, 0 some other function
1232 -  hot - indicates that the function may be called often so expensive error checking should be turned off inside the function
1233 
1234    Level: developer
1235 
1236    Notes:
1237    In debug mode PETSc maintains a stack of the current function calls that can be used to help to quickly see where a problem has
1238    occurred, for example, when a signal is received without running in the debugger. It is recommended to use the debugger if extensive information is needed to
1239    help debug the problem.
1240 
1241    This version does not check the memory corruption (an expensive operation), use `PetscStackPush()` to check the memory.
1242 
1243    Use `PetscStackPushExternal()` for a function call that is about to be made to a non-PETSc or user function (such as BLAS etc).
1244 
1245    The default stack is a global variable called `petscstack`.
1246 
1247 .seealso: `PetscAttachDebugger()`, `PetscStackCopy()`, `PetscStackView()`, `PetscStackPopNoCheck()`, `PetscCall()`, `PetscFunctionBegin()`,
1248           `PetscFunctionReturn()`, `PetscFunctionBeginHot()`, `PetscFunctionBeginUser()`, `PetscStackPush()`, `PetscStackPop`,
1249           `PetscStackPushExternal()`
1250 M*/
1251   #define PetscStackPushNoCheck(funct, petsc_routine, hot) \
1252     do { \
1253       PetscStackSAWsTakeAccess(); \
1254       PetscStackPush_Private(petscstack, __FILE__, funct, __LINE__, petsc_routine, hot); \
1255       PetscStackSAWsGrantAccess(); \
1256     } while (0)
1257 
1258   /*MC
1259    PetscStackUpdateLine - in a function that has a `PetscFunctionBegin` or `PetscFunctionBeginUser` updates the stack line number to the
1260    current line number.
1261 
1262    Not Collective
1263 
1264    Synopsis:
1265    #include <petscsys.h>
1266    void PetscStackUpdateLine
1267 
1268    Level: developer
1269 
1270    Notes:
1271    Using `PetscCall()` and friends automatically handles this process
1272 
1273    In debug mode PETSc maintains a stack of the current function calls that can be used to help to quickly see where a problem has
1274    occurred, for example, when a signal is received. It is recommended to use the debugger if extensive information is needed to
1275    help debug the problem.
1276 
1277    The default stack is a global variable called petscstack.
1278 
1279    This is used by `PetscCall()` and is otherwise not like to be needed
1280 
1281 .seealso: `PetscAttachDebugger()`, `PetscStackCopy()`, `PetscStackView()`, `PetscStackPushNoCheck()`, `PetscStackPop`, `PetscCall()`
1282 M*/
1283   #define PetscStackUpdateLine \
1284     if (petscstack.currentsize > 0 && petscstack.function[petscstack.currentsize - 1] == PETSC_FUNCTION_NAME) { petscstack.line[petscstack.currentsize - 1] = __LINE__; }
1285 
1286   /*MC
1287    PetscStackPushExternal - Pushes a new function name onto the PETSc default stack that tracks where the running program is
1288    currently in the source code. Does not include the filename or line number since this is called by the calling routine
1289    for non-PETSc or user functions.
1290 
1291    Not Collective
1292 
1293    Synopsis:
1294    #include <petscsys.h>
1295    void PetscStackPushExternal(char *funct);
1296 
1297    Input Parameters:
1298 .  funct - the function name
1299 
1300    Level: developer
1301 
1302    Notes:
1303    Using `PetscCallExternal()` and friends automatically handles this process
1304 
1305    In debug mode PETSc maintains a stack of the current function calls that can be used to help to quickly see where a problem has
1306    occurred, for example, when a signal is received. It is recommended to use the debugger if extensive information is needed to
1307    help debug the problem.
1308 
1309    The default stack is a global variable called `petscstack`.
1310 
1311    This is to be used when calling an external package function such as a BLAS function.
1312 
1313    This also updates the stack line number for the current stack function.
1314 
1315 .seealso: `PetscAttachDebugger()`, `PetscStackCopy()`, `PetscStackView()`, `PetscStackPopNoCheck()`, `PetscCall()`, `PetscFunctionBegin()`,
1316           `PetscFunctionReturn()`, `PetscFunctionBeginHot()`, `PetscFunctionBeginUser()`, `PetscStackPushNoCheck()`, `PetscStackPop`
1317 M*/
1318   #define PetscStackPushExternal(funct) \
1319     do { \
1320       PetscStackUpdateLine; \
1321       PetscStackPushNoCheck(funct, 0, PETSC_TRUE); \
1322     } while (0);
1323 
1324   /*MC
1325    PetscStackPopNoCheck - Pops a function name from the PETSc default stack that tracks where the running program is
1326    currently in the source code.
1327 
1328    Not Collective
1329 
1330    Synopsis:
1331    #include <petscsys.h>
1332    void PetscStackPopNoCheck(char *funct);
1333 
1334    Input Parameter:
1335 .   funct - the function name
1336 
1337    Level: developer
1338 
1339    Notes:
1340    Using `PetscCall()`, `PetscCallExternal()`, `PetscCallBack()` and friends negates the need to call this
1341 
1342    In debug mode PETSc maintains a stack of the current function calls that can be used to help to quickly see where a problem has
1343    occurred, for example, when a signal is received. It is recommended to use the debugger if extensive information is needed to
1344    help debug the problem.
1345 
1346    The default stack is a global variable called petscstack.
1347 
1348    Developer Note:
1349    `PetscStackPopNoCheck()` takes a function argument while  `PetscStackPop` does not, this difference is likely just historical.
1350 
1351 .seealso: `PetscAttachDebugger()`, `PetscStackCopy()`, `PetscStackView()`, `PetscStackPushNoCheck()`, `PetscStackPop`
1352 M*/
1353   #define PetscStackPopNoCheck(funct) \
1354     do { \
1355       PetscStackSAWsTakeAccess(); \
1356       PetscStackPop_Private(petscstack, funct); \
1357       PetscStackSAWsGrantAccess(); \
1358     } while (0)
1359 
1360   #define PetscStackClearTop \
1361     do { \
1362       PetscStackSAWsTakeAccess(); \
1363       if (petscstack.currentsize > 0 && --petscstack.currentsize < PETSCSTACKSIZE) { \
1364         petscstack.function[petscstack.currentsize]     = PETSC_NULLPTR; \
1365         petscstack.file[petscstack.currentsize]         = PETSC_NULLPTR; \
1366         petscstack.line[petscstack.currentsize]         = 0; \
1367         petscstack.petscroutine[petscstack.currentsize] = 0; \
1368       } \
1369       petscstack.hotdepth = PetscMax(petscstack.hotdepth - 1, 0); \
1370       PetscStackSAWsGrantAccess(); \
1371     } while (0)
1372 
1373   /*MC
1374    PetscFunctionBegin - First executable line of each PETSc function,  used for error handling. Final
1375       line of PETSc functions should be `PetscFunctionReturn`(0);
1376 
1377    Synopsis:
1378    #include <petscsys.h>
1379    void PetscFunctionBegin;
1380 
1381    Not Collective
1382 
1383    Usage:
1384 .vb
1385      int something;
1386 
1387      PetscFunctionBegin;
1388 .ve
1389 
1390    Notes:
1391      Use `PetscFunctionBeginUser` for application codes.
1392 
1393      Not available in Fortran
1394 
1395    Level: developer
1396 
1397 .seealso: `PetscFunctionReturn()`, `PetscFunctionBeginHot()`, `PetscFunctionBeginUser()`, `PetscStackPushNoCheck()`
1398 
1399 M*/
1400   #define PetscFunctionBegin \
1401     do { \
1402       PetscStackPushNoCheck(PETSC_FUNCTION_NAME, 1, PETSC_FALSE); \
1403       PetscRegister__FUNCT__(); \
1404     } while (0)
1405 
1406   /*MC
1407    PetscFunctionBeginHot - Substitute for `PetscFunctionBegin` to be used in functions that are called in
1408    performance-critical circumstances.  Use of this function allows for lighter profiling by default.
1409 
1410    Synopsis:
1411    #include <petscsys.h>
1412    void PetscFunctionBeginHot;
1413 
1414    Not Collective
1415 
1416    Usage:
1417 .vb
1418      int something;
1419 
1420      PetscFunctionBeginHot;
1421 .ve
1422 
1423    Notes:
1424      Not available in Fortran
1425 
1426    Level: developer
1427 
1428 .seealso: `PetscFunctionBegin`, `PetscFunctionReturn()`, `PetscStackPushNoCheck()`
1429 
1430 M*/
1431   #define PetscFunctionBeginHot \
1432     do { \
1433       PetscStackPushNoCheck(PETSC_FUNCTION_NAME, 1, PETSC_TRUE); \
1434       PetscRegister__FUNCT__(); \
1435     } while (0)
1436 
1437   /*MC
1438    PetscFunctionBeginUser - First executable line of user provided routines
1439 
1440    Synopsis:
1441    #include <petscsys.h>
1442    void PetscFunctionBeginUser;
1443 
1444    Not Collective
1445 
1446    Usage:
1447 .vb
1448      int something;
1449 
1450      PetscFunctionBeginUser;
1451 .ve
1452 
1453    Notes:
1454       Functions that incorporate this must call `PetscFunctionReturn()` instead of return except for main().
1455 
1456       May be used before `PetscInitialize()`
1457 
1458       Not available in Fortran
1459 
1460       This is identical to `PetscFunctionBegin` except it labels the routine as a user
1461       routine instead of as a PETSc library routine.
1462 
1463    Level: intermediate
1464 
1465 .seealso: `PetscFunctionReturn()`, `PetscFunctionBegin`, `PetscFunctionBeginHot`, `PetscStackPushNoCheck()`
1466 
1467 M*/
1468   #define PetscFunctionBeginUser \
1469     do { \
1470       PetscStackPushNoCheck(PETSC_FUNCTION_NAME, 2, PETSC_FALSE); \
1471       PetscRegister__FUNCT__(); \
1472     } while (0)
1473 
1474   /*MC
1475    PetscStackPush - Pushes a new function name and line number onto the PETSc default stack that tracks where the running program is
1476    currently in the source code and verifies the memory is not corrupted.
1477 
1478    Not Collective
1479 
1480    Synopsis:
1481    #include <petscsys.h>
1482    void PetscStackPush(char *funct)
1483 
1484    Input Parameter:
1485 .  funct - the function name
1486 
1487    Level: developer
1488 
1489    Notes:
1490    In debug mode PETSc maintains a stack of the current function calls that can be used to help to quickly see where a problem has
1491    occurred, for example, when a signal is received. It is recommended to use the debugger if extensive information is needed to
1492    help debug the problem.
1493 
1494    The default stack is a global variable called petscstack.
1495 
1496 .seealso: `PetscAttachDebugger()`, `PetscStackCopy()`, `PetscStackView()`, `PetscStackPopNoCheck()`, `PetscCall()`, `PetscFunctionBegin()`,
1497           `PetscFunctionReturn()`, `PetscFunctionBeginHot()`, `PetscFunctionBeginUser()`, `PetscStackPushNoCheck()`, `PetscStackPop`
1498 M*/
1499   #define PetscStackPush(n) \
1500     do { \
1501       PetscStackPushNoCheck(n, 0, PETSC_FALSE); \
1502       CHKMEMQ; \
1503     } while (0)
1504 
1505   /*MC
1506    PetscStackPop - Pops a function name from the PETSc default stack that tracks where the running program is
1507    currently in the source code and verifies the memory is not corrupted.
1508 
1509    Not Collective
1510 
1511    Synopsis:
1512    #include <petscsys.h>
1513    void PetscStackPop
1514 
1515    Level: developer
1516 
1517    Notes:
1518    In debug mode PETSc maintains a stack of the current function calls that can be used to help to quickly see where a problem has
1519    occurred, for example, when a signal is received. It is recommended to use the debugger if extensive information is needed to
1520    help debug the problem.
1521 
1522    The default stack is a global variable called petscstack.
1523 
1524 .seealso: `PetscAttachDebugger()`, `PetscStackCopy()`, `PetscStackView()`, `PetscStackPushNoCheck()`, `PetscStackPopNoCheck()`, `PetscStackPush()`
1525 M*/
1526   #define PetscStackPop \
1527     do { \
1528       CHKMEMQ; \
1529       PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \
1530     } while (0)
1531 
1532   /*MC
1533    PetscFunctionReturn - Last executable line of each PETSc function used for error
1534    handling. Replaces `return()`.
1535 
1536    Synopsis:
1537    #include <petscerror.h>
1538    void PetscFunctionReturn(...)
1539 
1540    Not Collective
1541 
1542    Level: beginner
1543 
1544    Notes:
1545    This routine is a macro, so while it does not "return" anything itself, it does return from
1546    the function in the literal sense.
1547 
1548    Usually the return value is the integer literal `0` (for example in any function returning
1549    `PetscErrorCode`), however it is possible to return any arbitrary type. The arguments of
1550    this macro are placed before the `return` statement as-is.
1551 
1552    Any routine which returns via `PetscFunctionReturn()` must begin with a corresponding
1553    `PetscFunctionBegin`.
1554 
1555    For routines which return `void` use `PetscFunctionReturnVoid()` instead.
1556 
1557    Example Usage:
1558 .vb
1559    PetscErrorCode foo(int *x)
1560    {
1561      PetscFunctionBegin; // don't forget the begin!
1562      *x = 10;
1563      PetscFunctionReturn(0);
1564    }
1565 .ve
1566 
1567    May return any arbitrary type\:
1568 .vb
1569   struct Foo
1570   {
1571     int x;
1572   };
1573 
1574   struct Foo make_foo(int value)
1575   {
1576     struct Foo f;
1577 
1578     PetscFunctionBegin;
1579     f.x = value;
1580     PetscFunctionReturn(f);
1581   }
1582 .ve
1583 
1584    Fortran Note:
1585    Not available in Fortran
1586 
1587 .seealso: `PetscFunctionBegin`, `PetscFunctionBeginUser`, `PetscFunctionReturnVoid()`,
1588 `PetscStackPopNoCheck()`
1589 M*/
1590   #define PetscFunctionReturn(...) \
1591     do { \
1592       PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \
1593       return __VA_ARGS__; \
1594     } while (0)
1595 
1596   /*MC
1597   PetscFunctionReturnVoid - Like `PetscFunctionReturn()` but returns `void`
1598 
1599   Synopsis:
1600   #include <petscerror.h>
1601   void PetscFunctionReturnVoid()
1602 
1603   Not Collective
1604 
1605   Level: beginner
1606 
1607   Note:
1608   Behaves identically to `PetscFunctionReturn()` except that it returns `void`. That is, this
1609   macro culminates with `return`.
1610 
1611   Example Usage:
1612 .vb
1613   void foo()
1614   {
1615     PetscFunctionBegin; // must start with PetscFunctionBegin!
1616     bar();
1617     baz();
1618     PetscFunctionReturnVoid();
1619   }
1620 .ve
1621 
1622 .seealso: `PetscFunctionReturn()`, `PetscFunctionBegin`, PetscFunctionBeginUser`
1623 M*/
1624   #define PetscFunctionReturnVoid() \
1625     do { \
1626       PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \
1627       return; \
1628     } while (0)
1629 #else /* PETSC_USE_DEBUG */
1630   #define PetscStackPushNoCheck(funct, petsc_routine, hot)
1631   #define PetscStackUpdateLine
1632   #define PetscStackPushExternal(funct)
1633   #define PetscStackPopNoCheck
1634   #define PetscStackClearTop
1635   #define PetscFunctionBegin
1636   #define PetscFunctionBeginUser
1637   #define PetscFunctionBeginHot
1638   #define PetscFunctionReturn(...)  return __VA_ARGS__
1639   #define PetscFunctionReturnVoid() return
1640   #define PetscStackPop             CHKMEMQ
1641   #define PetscStackPush(f)         CHKMEMQ
1642 #endif /* PETSC_USE_DEBUG */
1643 
1644 #if defined(PETSC_CLANG_STATIC_ANALYZER)
1645   #define PetscStackCallExternalVoid(name, routine)
1646   #define PetscCallExternal(func, ...)
1647 #else
1648   /*MC
1649     PetscStackCallExternalVoid - Calls an external library routine or user function after pushing the name of the routine on the stack.
1650 
1651    Input Parameters:
1652 +   name - string that gives the name of the function being called
1653 -   routine - actual call to the routine, for example, functionname(a,b)
1654 
1655    Level: developer
1656 
1657    Note:
1658    Often one should use `PetscCallExternal()` instead. This routine is intended for external library routines that DO NOT return error codes
1659 
1660    In debug mode this also checks the memory for corruption at the end of the function call.
1661 
1662    Certain external packages, such as BLAS/LAPACK may have their own macros for managing the call, error checking, etc.
1663 
1664    Developer Note:
1665    This is so that when a user or external library routine results in a crash or corrupts memory, they get blamed instead of PETSc.
1666 
1667 .seealso: `PetscCall()`, `PetscStackPushNoCheck()`, `PetscStackPush()`, `PetscCallExternal()`, `PetscCallBLAS()`
1668 @*/
1669   #define PetscStackCallExternalVoid(name, routine) \
1670     do { \
1671       PetscStackPush(name); \
1672       routine; \
1673       PetscStackPop; \
1674     } while (0)
1675 
1676   /*MC
1677     PetscCallExternal - Calls an external library routine that returns an error code after pushing the name of the routine on the stack.
1678 
1679    Input Parameters:
1680 +   func-  name of the routine
1681 -   args - arguments to the routine
1682 
1683    Level: developer
1684 
1685    Notes:
1686    This is intended for external package routines that return error codes. Use `PetscStackCallExternalVoid()` for those that do not.
1687 
1688    In debug mode this also checks the memory for corruption at the end of the function call.
1689 
1690    Assumes the error return code of the function is an integer and that a value of 0 indicates success
1691 
1692    Developer Note:
1693    This is so that when an external package routine results in a crash or corrupts memory, they get blamed instead of PETSc.
1694 
1695 .seealso: `PetscCall()`, `PetscStackPushNoCheck()`, `PetscStackPush()`, `PetscStackCallExternalVoid()`
1696 M*/
1697   #define PetscCallExternal(func, ...) \
1698     do { \
1699       PetscStackPush(PetscStringize(func)); \
1700       PetscErrorCode __ierr = func(__VA_ARGS__); \
1701       PetscStackPop; \
1702       PetscCheck(!__ierr, PETSC_COMM_SELF, PETSC_ERR_LIB, "Error in %s(): error code %d", PetscStringize(func), __ierr); \
1703     } while (0)
1704 #endif /* PETSC_CLANG_STATIC_ANALYZER */
1705 
1706 #endif
1707