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