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