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