Actual source code: petscerror.h
1: /*
2: Contains all error handling interfaces for PETSc.
3: */
4: #if !defined(PETSCERROR_H)
5: #define PETSCERROR_H
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 src/sys/f90-mod/petscerror.h any CHANGES here
12: must be also made there.
14: */
15: #define PETSC_ERR_MIN_VALUE 54 /* should always be one less then the smallest value */
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 */
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 */
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 */
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 */
55: #define PETSC_ERR_INT_OVERFLOW 84
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_GPU_RESOURCE 96 /* unable to load a GPU resource, for example cuBLAS */
64: #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 */
65: #define PETSC_ERR_MPI 98 /* general MPI error */
66: #define PETSC_ERR_MAX_VALUE 99 /* this is always the one more than the largest error code */
68: #define PetscStringizeArg(a) #a
69: #define PetscStringize(a) PetscStringizeArg(a)
71: /*MC
72: SETERRQ - Macro to be called when an error has been detected,
74: Synopsis:
75: #include <petscsys.h>
76: PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message)
78: Collective
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
85: Level: beginner
87: Notes:
88: Once the error handler is called the calling function is then returned from with the given error code.
90: See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
92: Experienced users can set the error handler with PetscPushErrorHandler().
94: Fortran Notes:
95: SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the
96: Fortran main program.
98: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, 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)
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;
110: /*MC
111: SETERRMPI - Macro to be called when an error has been detected within an MPI callback function
113: Synopsis:
114: #include <petscsys.h>
115: PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message)
117: Collective
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
124: Level: developer
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.
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)
134: /*MC
135: SETERRQ1 - Macro that is called when an error has been detected,
137: Synopsis:
138: #include <petscsys.h>
139: PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)
141: Collective
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)
149: Level: beginner
151: Notes:
152: Once the error handler is called the calling function is then returned from with the given error code.
154: Experienced users can set the error handler with PetscPushErrorHandler().
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)
160: /*MC
161: SETERRQ2 - Macro that is called when an error has been detected,
163: Synopsis:
164: #include <petscsys.h>
165: PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)
167: Collective
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)
176: Level: beginner
178: Notes:
179: Once the error handler is called the calling function is then returned from with the given error code.
181: Experienced users can set the error handler with PetscPushErrorHandler().
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)
187: /*MC
188: SETERRQ3 - Macro that is called when an error has been detected,
190: Synopsis:
191: #include <petscsys.h>
192: PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
194: Collective
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)
204: Level: beginner
206: Notes:
207: Once the error handler is called the calling function is then returned from with the given error code.
209: There are also versions for 4, 5, 6 and 7 arguments.
211: Experienced users can set the error handler with PetscPushErrorHandler().
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)
217: /*MC
218: SETERRQ4 - Macro that is called when an error has been detected,
220: Synopsis:
221: #include <petscsys.h>
222: PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4)
224: Collective
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)
235: Level: beginner
237: Notes:
238: Once the error handler is called the calling function is then returned from with the given error code.
240: There are also versions for 4, 5, 6 and 7 arguments.
242: Experienced users can set the error handler with PetscPushErrorHandler().
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)
248: /*MC
249: SETERRQ5 - Macro that is called when an error has been detected,
251: Synopsis:
252: #include <petscsys.h>
253: PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5)
255: Collective
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)
267: Level: beginner
269: Notes:
270: Once the error handler is called the calling function is then returned from with the given error code.
272: There are also versions for 4, 5, 6 and 7 arguments.
274: Experienced users can set the error handler with PetscPushErrorHandler().
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)
280: /*MC
281: SETERRQ6 - Macro that is called when an error has been detected,
283: Synopsis:
284: #include <petscsys.h>
285: PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6)
287: Collective
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)
300: Level: beginner
302: Notes:
303: Once the error handler is called the calling function is then returned from with the given error code.
305: There are also versions for 4, 5, 6 and 7 arguments.
307: Experienced users can set the error handler with PetscPushErrorHandler().
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)
313: /*MC
314: SETERRQ7 - Macro that is called when an error has been detected,
316: Synopsis:
317: #include <petscsys.h>
318: PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
320: Collective
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)
334: Level: beginner
336: Notes:
337: Once the error handler is called the calling function is then returned from with the given error code.
339: There are also versions for 4, 5, 6 and 7 arguments.
341: Experienced users can set the error handler with PetscPushErrorHandler().
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)
347: /*MC
348: SETERRQ8 - Macro that is called when an error has been detected,
350: Synopsis:
351: #include <petscsys.h>
352: PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)
354: Collective
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)
369: Level: beginner
371: Notes:
372: Once the error handler is called the calling function is then returned from with the given error code.
374: There are also versions for 4, 5, 6 and 7 arguments.
376: Experienced users can set the error handler with PetscPushErrorHandler().
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)
382: /*MC
383: SETERRQ9 - Macro that is called when an error has been detected,
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)
389: Collective
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)
405: Level: beginner
407: Notes:
408: Once the error handler is called the calling function is then returned from with the given error code.
410: There are also versions for 0 to 9 arguments.
412: Experienced users can set the error handler with PetscPushErrorHandler().
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)
418: /*MC
419: SETERRABORT - Macro that can be called when an error has been detected,
421: Synopsis:
422: #include <petscsys.h>
423: PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)
425: Collective
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
432: Level: beginner
434: Notes:
435: This function just calls MPI_Abort().
437: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
438: M*/
439: #define SETERRABORT(comm,ierr,s) do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,ierr);} while (0)
441: /*MC
442: 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
444: Synopsis:
445: #include <petscsys.h>
446: PetscErrorCode CHKERRQ(PetscErrorCode ierr)
448: Not Collective
450: Input Parameters:
451: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
453: Level: beginner
455: Notes:
456: Once the error handler is called the calling function is then returned from with the given error code.
458: Experienced users can set the error handler with PetscPushErrorHandler().
460: CHKERRQ(ierr) is fundamentally a macro replacement for
461: if (ierr) return(PetscError(...,ierr,...));
463: Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
464: highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
465: it cannot be used in functions which return(void) or any other datatype. In these types of functions,
466: you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
467: if (ierr) {PetscError(....); return(YourReturnType);}
468: where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
469: MPI_Abort() returned immediately.
471: Fortran Notes:
472: CHKERRQ() may be called from Fortran subroutines but CHKERRA() must be called from the
473: Fortran main program.
475: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
476: M*/
477: #if !defined(PETSC_CLANG_STATIC_ANALYZER)
478: #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)
479: #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)
480: #else
481: #define CHKERRQ(ierr)
482: #define CHKERRV(ierr)
483: #endif
485: /*MC
486: CHKERRABORT - Checks error code returned from PETSc function. If non-zero it aborts immediately.
488: Synopsis:
489: #include <petscsys.h>
490: PetscErrorCode CHKERRABORT(MPI_Comm comm,PetscErrorCode ierr)
492: Not Collective
494: Input Parameters:
495: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
497: Level: intermediate
499: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2(), SETERRABORT(), CHKERRMPI()
500: M*/
501: #if !defined(PETSC_CLANG_STATIC_ANALYZER)
502: #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)
503: #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)
504: #else
505: #define CHKERRABORT(comm,ierr)
506: #define CHKERRCONTINUE(ierr)
507: #endif
509: PETSC_EXTERN PetscErrorCode PetscAbortFindSourceFile_Private(const char*,PetscInt*);
510: PETSC_EXTERN PetscBool petscwaitonerrorflg;
511: PETSC_EXTERN PetscBool petscindebugger;
513: /*MC
514: PETSCABORT - Call MPI_Abort with an informative error code
516: Synopsis:
517: #include <petscsys.h>
518: PETSCABORT(MPI_Comm comm, PetscErrorCode ierr)
520: Collective
522: Input Parameters:
523: + comm - A communicator, so that the error can be collective
524: - ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
526: Level: advanced
528: Notes:
529: We pass MPI_Abort() an error code of format XX_YYYY_ZZZ, where XX, YYYY are an index and line number of the file
530: where PETSCABORT is called, respectively. ZZZ is the PETSc error code.
532: If XX is zero, this means that the call was made in the routine main().
533: 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[]
534: is out of date. PETSc developers have to update it.
535: 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.
537: If the option -start_in_debugger was used then this calls abort() to stop the program in the debugger.
539: M*/
540: #define PETSCABORT(comm,ierr) \
541: do { \
542: PetscInt idx = 0; \
543: PetscMPIInt errcode; \
544: PetscAbortFindSourceFile_Private(__FILE__,&idx); \
545: errcode = (PetscMPIInt)(0*idx*10000000 + 0*__LINE__*1000 + ierr); \
546: if (petscwaitonerrorflg) PetscSleep(1000); \
547: if (petscindebugger) abort(); \
548: else MPI_Abort(comm,errcode); \
549: } while (0)
551: /*MC
552: CHKERRMPI - Checks error code returned from MPI calls, if non-zero it calls the error handler and then returns
554: Synopsis:
555: #include <petscsys.h>
556: PetscErrorCode CHKERRMPI(PetscErrorCode ierr)
558: Not Collective
560: Input Parameters:
561: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
563: Level: intermediate
565: Notes:
566: Always returns the error code PETSC_ERR_MPI; the MPI error code and string are embedded in the string error message
568: .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2(), SETERRMPI(), SETERRABORT(), CHKERRABORT()
569: M*/
570: #if !defined(PETSC_CLANG_STATIC_ANALYZER)
571: #define CHKERRMPI(ierr) \
572: do { \
573: PetscErrorCode _7_errorcode = (ierr); \
574: if (PetscUnlikely(_7_errorcode)) { \
575: char _7_errorstring[MPI_MAX_ERROR_STRING]; \
576: PETSC_UNUSED PetscMPIInt _7_resultlen; \
577: MPI_Error_string(_7_errorcode,(char*)_7_errorstring,&_7_resultlen); \
578: SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_MPI,"MPI error %d %s",(int)_7_errorcode,_7_errorstring); \
579: } \
580: } while (0)
581: #else
582: #define CHKERRMPI(ierr)
583: #endif
585: #ifdef PETSC_CLANGUAGE_CXX
587: /*MC
588: CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
590: Synopsis:
591: #include <petscsys.h>
592: void CHKERRXX(PetscErrorCode ierr)
594: Not Collective
596: Input Parameters:
597: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
599: Level: beginner
601: Notes:
602: Once the error handler throws a ??? exception.
604: You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
605: or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
607: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
608: M*/
609: #define CHKERRXX(ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_IN_CXX,0);}} while (0)
610: #endif
612: /*MC
613: CHKERRCXX - Checks C++ function calls and if they throw an exception, catch it and then return a PETSc error code
615: Synopsis:
616: #include <petscsys.h>
617: CHKERRCXX(func);
619: Not Collective
621: Input Parameters:
622: . func - C++ function calls
624: Level: beginner
626: Notes:
627: For example,
629: $ void foo(int x) {throw std::runtime_error("error");}
630: $ CHKERRCXX(foo(1));
632: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
633: M*/
634: #define CHKERRCXX(func) do {try {func;} catch (const std::exception& e) { SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"%s", e.what()); }} while (0)
636: /*MC
637: CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
639: Synopsis:
640: #include <petscsys.h>
641: CHKMEMQ;
643: Not Collective
645: Level: beginner
647: Notes:
648: We highly recommend using Valgrind https://petsc.org/release/faq/#valgrind or for NVIDIA CUDA systems
649: https://docs.nvidia.com/cuda/cuda-memcheck/index.html for finding memory problems. The ``CHKMEMQ`` macro is useful on systems that
650: do not have valgrind, but is not as good as valgrind or cuda-memcheck.
652: Must run with the option -malloc_debug (-malloc_test in debug mode; or if PetscMallocSetDebug() called) to enable this option
654: Once the error handler is called the calling function is then returned from with the given error code.
656: By defaults prints location where memory that is corrupted was allocated.
658: Use CHKMEMA for functions that return void
660: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
661: PetscMallocValidate()
662: M*/
663: #if !defined(PETSC_CLANG_STATIC_ANALYZER)
664: #define CHKMEMQ do {PetscErrorCode _7_PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while (0)
666: #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)
667: #else
668: #define CHKMEMQ
669: #define CHKMEMA
670: #endif
671: /*E
672: PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
674: Level: advanced
676: PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
678: Developer Notes:
679: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()
681: .seealso: PetscError(), SETERRXX()
682: E*/
683: typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
685: #if defined(__clang_analyzer__)
686: __attribute__((analyzer_noreturn))
687: #endif
688: PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);
690: PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
691: PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
692: PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
693: PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
694: PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
695: PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
696: PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
697: PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
698: PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
699: PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
700: PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
701: PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
702: PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
703: PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
705: PETSC_EXTERN void PetscSignalSegvCheckPointerOrMpi(void);
706: PETSC_DEPRECATED_FUNCTION("Use PetscSignalSegvCheckPointerOrMpi() (since version 3.13)") PETSC_STATIC_INLINE void PetscSignalSegvCheckPointer(void) {PetscSignalSegvCheckPointerOrMpi();}
708: /*MC
709: PetscErrorPrintf - Prints error messages.
711: Synopsis:
712: #include <petscsys.h>
713: PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
715: Not Collective
717: Input Parameter:
718: . format - the usual printf() format string
720: Options Database Keys:
721: + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr
722: - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)
724: Notes:
725: Use
726: $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
727: $ error is handled.) and
728: $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function
730: Use
731: PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
732: PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
734: Use
735: PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
737: Level: developer
739: Fortran Note:
740: This routine is not supported in Fortran.
742: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf()
743: M*/
744: PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);
746: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
747: PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
748: PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
749: PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);
750: PETSC_EXTERN PetscErrorCode PetscDetermineInitialFPTrap(void);
752: /*
753: Allows the code to build a stack frame as it runs
754: */
756: #if defined(PETSC_USE_DEBUG)
757: #define PETSCSTACKSIZE 64
758: typedef struct {
759: const char *function[PETSCSTACKSIZE];
760: const char *file[PETSCSTACKSIZE];
761: int line[PETSCSTACKSIZE];
762: int petscroutine[PETSCSTACKSIZE]; /* 0 external called from petsc, 1 petsc functions, 2 petsc user functions */
763: int currentsize;
764: int hotdepth;
765: PetscBool check; /* runtime option to check for correct Push/Pop semantics at runtime */
766: } PetscStack;
767: PETSC_EXTERN PetscStack petscstack;
768: #else
769: typedef struct {
770: char Silence_empty_struct_has_size_0_in_C_size_1_in_Cpp;
771: } PetscStack;
772: #endif
774: #if defined(PETSC_SERIALIZE_FUNCTIONS)
775: #include <petsc/private/petscfptimpl.h>
776: /*
777: Registers the current function into the global function pointer to function name table
779: Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
780: */
781: #define PetscRegister__FUNCT__() do { \
782: static PetscBool __chked = PETSC_FALSE; \
783: if (!__chked) {\
784: void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
785: __chked = PETSC_TRUE;\
786: }} while (0)
787: #else
788: #define PetscRegister__FUNCT__()
789: #endif
791: #if !defined(PETSC_CLANG_STATIC_ANALYZER)
792: #if defined(PETSC_USE_DEBUG)
794: /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error
795: * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at
796: * least more useful than "unknown" because it can distinguish multiple calls from the same function.
797: */
798: #define PetscStackPushNoCheck(funct,petsc_routine,hot) do { \
799: PetscStackSAWsTakeAccess(); \
800: if (petscstack.currentsize < PETSCSTACKSIZE) { \
801: petscstack.function[petscstack.currentsize] = funct; \
802: petscstack.file[petscstack.currentsize] = __FILE__; \
803: petscstack.line[petscstack.currentsize] = __LINE__; \
804: petscstack.petscroutine[petscstack.currentsize] = petsc_routine; \
805: } \
806: ++petscstack.currentsize; \
807: petscstack.hotdepth += (hot || petscstack.hotdepth); \
808: PetscStackSAWsGrantAccess(); \
809: } while (0)
811: #define PetscStackPopNoCheck(funct) do { \
812: PetscStackSAWsTakeAccess(); \
813: if (PetscUnlikely(petscstack.currentsize < 0) && \
814: petscstack.check) { \
815: printf("Invalid stack size %d, pop %s\n", \
816: petscstack.currentsize,funct); \
817: MPI_Abort(MPI_COMM_WORLD,1); \
818: } else { \
819: if (--petscstack.currentsize < PETSCSTACKSIZE) { \
820: if (PetscUnlikely( \
821: petscstack.check && \
822: petscstack.petscroutine[petscstack.currentsize] && \
823: (petscstack.function[petscstack.currentsize] != \
824: (const char*)funct))) { \
825: printf("Invalid stack: push from %s, pop from %s\n", \
826: petscstack.function[petscstack.currentsize],funct); \
827: } \
828: petscstack.function[petscstack.currentsize] = PETSC_NULLPTR; \
829: petscstack.file[petscstack.currentsize] = PETSC_NULLPTR; \
830: petscstack.line[petscstack.currentsize] = 0; \
831: petscstack.petscroutine[petscstack.currentsize] = 0; \
832: } \
833: petscstack.hotdepth = PetscMax(petscstack.hotdepth-1,0); \
834: } \
835: PetscStackSAWsGrantAccess(); \
836: } while (0)
838: #define PetscStackClearTop do { \
839: PetscStackSAWsTakeAccess(); \
840: if (petscstack.currentsize > 0) { \
841: --petscstack.currentsize; \
842: petscstack.function[petscstack.currentsize] = PETSC_NULLPTR; \
843: petscstack.file[petscstack.currentsize] = PETSC_NULLPTR; \
844: petscstack.line[petscstack.currentsize] = 0; \
845: petscstack.petscroutine[petscstack.currentsize] = 0; \
846: } \
847: petscstack.hotdepth = PetscMax(petscstack.hotdepth-1,0); \
848: PetscStackSAWsGrantAccess(); \
849: } while (0)
851: /*MC
853: line of PETSc functions should be return(0);
855: Synopsis:
856: #include <petscsys.h>
859: Not Collective
861: Usage:
862: .vb
863: int something;
866: .ve
868: Notes:
871: Not available in Fortran
873: Level: developer
877: M*/
879: PetscStackPushNoCheck(PETSC_FUNCTION_NAME,1,PETSC_FALSE); \
880: PetscRegister__FUNCT__(); \
881: } while (0)
883: /*MC
885: performance-critical circumstances. Use of this function allows for lighter profiling by default.
887: Synopsis:
888: #include <petscsys.h>
891: Not Collective
893: Usage:
894: .vb
895: int something;
898: .ve
900: Notes:
901: Not available in Fortran
903: Level: developer
907: M*/
909: PetscStackPushNoCheck(PETSC_FUNCTION_NAME,1,PETSC_TRUE); \
910: PetscRegister__FUNCT__(); \
911: } while (0)
913: /*MC
916: Synopsis:
917: #include <petscsys.h>
920: Not Collective
922: Usage:
923: .vb
924: int something;
927: .ve
929: Notes:
930: Final line of PETSc functions should be return(0) except for main().
932: Not available in Fortran
935: routine instead of as a PETSc library routine.
937: Level: intermediate
941: M*/
943: PetscStackPushNoCheck(PETSC_FUNCTION_NAME,2,PETSC_FALSE); \
944: PetscRegister__FUNCT__(); \
945: } while (0)
947: #define PetscStackPush(n) do { \
948: PetscStackPushNoCheck(n,0,PETSC_FALSE); \
949: CHKMEMQ; \
950: } while (0)
952: #define PetscStackPop do { \
953: CHKMEMQ; \
954: PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \
955: } while (0)
957: /*MC
958: PetscFunctionReturn - Last executable line of each PETSc function
959: used for error handling. Replaces return()
961: Synopsis:
962: #include <petscsys.h>
963: void return(0);
965: Not Collective
967: Usage:
968: .vb
969: ....
970: return(0);
971: }
972: .ve
974: Notes:
975: Not available in Fortran
977: Level: developer
981: M*/
982: #define PetscFunctionReturn(a) do { \
983: PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \
984: return a; \
985: } while (0)
987: #define PetscFunctionReturnVoid() do { \
988: PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \
989: return; \
990: } while (0)
991: #else /* PETSC_USE_DEBUG */
993: #define PetscStackPushNoCheck(funct,petsc_routine,hot)
994: #define PetscStackPopNoCheck
995: #define PetscStackClearTop
999: #define PetscFunctionReturn(a) return a
1000: #define PetscFunctionReturnVoid() return
1001: #define PetscStackPop CHKMEMQ
1002: #define PetscStackPush(f) CHKMEMQ
1004: #endif /* PETSC_USE_DEBUG */
1006: /*
1007: PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
1009: Input Parameters:
1010: + name - string that gives the name of the function being called
1011: - routine - actual call to the routine, including and
1013: Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes
1015: 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.
1017: */
1018: #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while (0)
1020: /*
1021: PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack.
1023: Input Parameters:
1024: + func- name of the routine
1025: - args - arguments to the routine surrounded by ()
1027: Notes:
1028: This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not.
1030: Developer Note: this is so that when an external packge routine results in a crash or corrupts memory, they get blamed instead of PETSc.
1032: */
1033: #define PetscStackCallStandard(func,args) do { \
1034: PetscErrorCode __ierr; \
1035: PetscStackPush(#func); \
1036: __func args; \
1037: PetscStackPop; \
1038: if (__ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)__ierr); \
1039: } while (0)
1041: #else /* !PETSC_CLANG_STATIC_ANALYZER */
1042: #define PetscStackPushNoCheck(funct,petsc_routine,hot)
1043: #define PetscStackPopNoCheck
1044: #define PetscStackClearTop
1048: #define PetscFunctionReturn(a) return a
1049: #define PetscFunctionReturnVoid() return
1050: #define PetscStackPop
1051: #define PetscStackPush(f)
1052: #define PetscStackCall(name,routine)
1053: #define PetscStackCallStandard(name,routine)
1054: #endif /* !PETSC_CLANG_STATIC_ANALYZER */
1056: #endif