Actual source code: petscerror.h
petsc-3.14.6 2021-03-30
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 /* missing or incorrect user input */
64: #define PETSC_ERR_MAX_VALUE 97 /* this is always the one more than the largest error code */
66: #define PetscStringizeArg(a) #a
67: #define PetscStringize(a) PetscStringizeArg(a)
70: /*MC
71: SETERRQ - Macro to be called when an error has been detected,
73: Synopsis:
74: #include <petscsys.h>
75: PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message)
77: Collective
79: Input Parameters:
80: + comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
81: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
82: - message - error message
84: Level: beginner
86: Notes:
87: Once the error handler is called the calling function is then returned from with the given error code.
89: See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
91: Experienced users can set the error handler with PetscPushErrorHandler().
93: Fortran Notes:
94: SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the
95: Fortran main program.
97: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
98: M*/
99: #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s)
101: /*MC
102: SETERRMPI - Macro to be called when an error has been detected within an MPI callback function
104: Synopsis:
105: #include <petscsys.h>
106: PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message)
108: Collective
110: Input Parameters:
111: + comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
112: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
113: - message - error message
115: Level: developer
117: Notes:
118: 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
119: which is registered with MPI_Add_error_code() when PETSc is initialized.
121: .seealso: SETERRQ(), CHKERRQ(), CHKERRMPI(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
122: M*/
123: #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE)
125: /*MC
126: SETERRQ1 - Macro that is called when an error has been detected,
128: Synopsis:
129: #include <petscsys.h>
130: PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)
132: Collective
134: Input Parameters:
135: + comm - A communicator, so that the error can be collective
136: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
137: . message - error message in the printf format
138: - arg - argument (for example an integer, string or double)
140: Level: beginner
142: Notes:
143: Once the error handler is called the calling function is then returned from with the given error code.
145: Experienced users can set the error handler with PetscPushErrorHandler().
147: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
148: M*/
149: #define SETERRQ1(comm,ierr,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1)
151: /*MC
152: SETERRQ2 - Macro that is called when an error has been detected,
154: Synopsis:
155: #include <petscsys.h>
156: PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)
158: Collective
160: Input Parameters:
161: + comm - A communicator, so that the error can be collective
162: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
163: . message - error message in the printf format
164: . arg1 - argument (for example an integer, string or double)
165: - arg2 - argument (for example an integer, string or double)
167: Level: beginner
169: Notes:
170: Once the error handler is called the calling function is then returned from with the given error code.
172: Experienced users can set the error handler with PetscPushErrorHandler().
174: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
175: M*/
176: #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2)
178: /*MC
179: SETERRQ3 - Macro that is called when an error has been detected,
181: Synopsis:
182: #include <petscsys.h>
183: PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
185: Collective
187: Input Parameters:
188: + comm - A communicator, so that the error can be collective
189: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
190: . message - error message in the printf format
191: . arg1 - argument (for example an integer, string or double)
192: . arg2 - argument (for example an integer, string or double)
193: - arg3 - argument (for example an integer, string or double)
195: Level: beginner
197: Notes:
198: Once the error handler is called the calling function is then returned from with the given error code.
200: There are also versions for 4, 5, 6 and 7 arguments.
202: Experienced users can set the error handler with PetscPushErrorHandler().
204: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
205: M*/
206: #define SETERRQ3(comm,ierr,s,a1,a2,a3) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3)
208: /*MC
209: SETERRQ4 - Macro that is called when an error has been detected,
211: Synopsis:
212: #include <petscsys.h>
213: PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4)
215: Collective
217: Input Parameters:
218: + comm - A communicator, so that the error can be collective
219: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
220: . message - error message in the printf format
221: . arg1 - argument (for example an integer, string or double)
222: . arg2 - argument (for example an integer, string or double)
223: . arg3 - argument (for example an integer, string or double)
224: - arg4 - argument (for example an integer, string or double)
226: Level: beginner
228: Notes:
229: Once the error handler is called the calling function is then returned from with the given error code.
231: There are also versions for 4, 5, 6 and 7 arguments.
233: Experienced users can set the error handler with PetscPushErrorHandler().
235: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
236: M*/
237: #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)
239: /*MC
240: SETERRQ5 - Macro that is called when an error has been detected,
242: Synopsis:
243: #include <petscsys.h>
244: PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5)
246: Collective
248: Input Parameters:
249: + comm - A communicator, so that the error can be collective
250: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
251: . message - error message in the printf format
252: . arg1 - argument (for example an integer, string or double)
253: . arg2 - argument (for example an integer, string or double)
254: . arg3 - argument (for example an integer, string or double)
255: . arg4 - argument (for example an integer, string or double)
256: - arg5 - argument (for example an integer, string or double)
258: Level: beginner
260: Notes:
261: Once the error handler is called the calling function is then returned from with the given error code.
263: There are also versions for 4, 5, 6 and 7 arguments.
265: Experienced users can set the error handler with PetscPushErrorHandler().
267: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
268: M*/
269: #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)
271: /*MC
272: SETERRQ6 - Macro that is called when an error has been detected,
274: Synopsis:
275: #include <petscsys.h>
276: PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6)
278: Collective
280: Input Parameters:
281: + comm - A communicator, so that the error can be collective
282: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
283: . message - error message in the printf format
284: . arg1 - argument (for example an integer, string or double)
285: . arg2 - argument (for example an integer, string or double)
286: . arg3 - argument (for example an integer, string or double)
287: . arg4 - argument (for example an integer, string or double)
288: . arg5 - argument (for example an integer, string or double)
289: - arg6 - argument (for example an integer, string or double)
291: Level: beginner
293: Notes:
294: Once the error handler is called the calling function is then returned from with the given error code.
296: There are also versions for 4, 5, 6 and 7 arguments.
298: Experienced users can set the error handler with PetscPushErrorHandler().
300: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
301: M*/
302: #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)
304: /*MC
305: SETERRQ7 - Macro that is called when an error has been detected,
307: Synopsis:
308: #include <petscsys.h>
309: PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
311: Collective
313: Input Parameters:
314: + comm - A communicator, so that the error can be collective
315: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
316: . message - error message in the printf format
317: . arg1 - argument (for example an integer, string or double)
318: . arg2 - argument (for example an integer, string or double)
319: . arg3 - argument (for example an integer, string or double)
320: . arg4 - argument (for example an integer, string or double)
321: . arg5 - argument (for example an integer, string or double)
322: . arg6 - argument (for example an integer, string or double)
323: - arg7 - argument (for example an integer, string or double)
325: Level: beginner
327: Notes:
328: Once the error handler is called the calling function is then returned from with the given error code.
330: There are also versions for 4, 5, 6 and 7 arguments.
332: Experienced users can set the error handler with PetscPushErrorHandler().
334: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
335: M*/
336: #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)
338: /*MC
339: SETERRQ8 - Macro that is called when an error has been detected,
341: Synopsis:
342: #include <petscsys.h>
343: PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)
345: Collective
347: Input Parameters:
348: + comm - A communicator, so that the error can be collective
349: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
350: . message - error message in the printf format
351: . arg1 - argument (for example an integer, string or double)
352: . arg2 - argument (for example an integer, string or double)
353: . arg3 - argument (for example an integer, string or double)
354: . arg4 - argument (for example an integer, string or double)
355: . arg5 - argument (for example an integer, string or double)
356: . arg6 - argument (for example an integer, string or double)
357: . arg7 - argument (for example an integer, string or double)
358: - arg8 - argument (for example an integer, string or double)
360: Level: beginner
362: Notes:
363: Once the error handler is called the calling function is then returned from with the given error code.
365: There are also versions for 4, 5, 6 and 7 arguments.
367: Experienced users can set the error handler with PetscPushErrorHandler().
369: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
370: M*/
371: #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)
373: /*MC
374: SETERRQ9 - Macro that is called when an error has been detected,
376: Synopsis:
377: #include <petscsys.h>
378: PetscErrorCode SETERRQ9(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
380: Collective
382: Input Parameters:
383: + comm - A communicator, so that the error can be collective
384: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
385: . message - error message in the printf format
386: . arg1 - argument (for example an integer, string or double)
387: . arg2 - argument (for example an integer, string or double)
388: . arg3 - argument (for example an integer, string or double)
389: . arg4 - argument (for example an integer, string or double)
390: . arg5 - argument (for example an integer, string or double)
391: . arg6 - argument (for example an integer, string or double)
392: . arg7 - argument (for example an integer, string or double)
393: . arg8 - argument (for example an integer, string or double)
394: - arg9 - argument (for example an integer, string or double)
396: Level: beginner
398: Notes:
399: Once the error handler is called the calling function is then returned from with the given error code.
401: There are also versions for 0 to 9 arguments.
403: Experienced users can set the error handler with PetscPushErrorHandler().
405: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
406: M*/
407: #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)
409: /*MC
410: SETERRABORT - Macro that can be called when an error has been detected,
412: Synopsis:
413: #include <petscsys.h>
414: PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)
416: Collective
418: Input Parameters:
419: + comm - A communicator, so that the error can be collective
420: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
421: - message - error message in the printf format
423: Level: beginner
425: Notes:
426: This function just calls MPI_Abort().
428: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
429: M*/
430: #define SETERRABORT(comm,ierr,s) do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,ierr);} while (0)
432: /*MC
433: CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns
435: Synopsis:
436: #include <petscsys.h>
437: PetscErrorCode CHKERRQ(PetscErrorCode ierr)
439: Not Collective
441: Input Parameters:
442: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
444: Level: beginner
446: Notes:
447: Once the error handler is called the calling function is then returned from with the given error code.
449: Experienced users can set the error handler with PetscPushErrorHandler().
451: CHKERRQ(ierr) is fundamentally a macro replacement for
452: if (ierr) return(PetscError(...,ierr,...));
454: Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
455: highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
456: it cannot be used in functions which return(void) or any other datatype. In these types of functions,
457: you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
458: if (ierr) {PetscError(....); return(YourReturnType);}
459: where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
460: MPI_Abort() returned immediately.
462: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
463: M*/
464: #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)
465: #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)
466: #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)
467: #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)
469: PETSC_EXTERN PetscErrorCode PetscAbortFindSourceFile_Private(const char*,PetscInt*);
470: PETSC_EXTERN PetscBool petscwaitonerrorflg,petscindebugger;
472: /*MC
473: PETSCABORT - Call MPI_Abort with an informative error code
475: Synopsis:
476: #include <petscsys.h>
477: PETSCABORT(MPI_Comm comm, PetscErrorCode ierr)
479: Collective
481: Input Parameters:
482: + comm - A communicator, so that the error can be collective
483: - ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
485: Level: advanced
487: Notes:
488: We pass MPI_Abort() an error code of format XX_YYYY_ZZZ, where XX, YYYY are an index and line number of the file
489: where PETSCABORT is called, respectively. ZZZ is the PETSc error code.
491: If XX is zero, this means that the call was made in the routine main().
492: 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[]
493: is out of date. PETSc developers have to update it.
494: 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.
496: If the option -start_in_debugger was used then this calls abort() to stop the program in the debugger.
498: M*/
499: #define PETSCABORT(comm,ierr) \
500: do { \
501: PetscInt idx = 0; \
502: PetscMPIInt errcode; \
503: PetscAbortFindSourceFile_Private(__FILE__,&idx); \
504: errcode = (PetscMPIInt)(idx*10000000 + __LINE__*1000 + ierr); \
505: if (petscwaitonerrorflg) PetscSleep(1000); \
506: if (petscindebugger) abort(); \
507: else MPI_Abort(comm,errcode); \
508: } while (0)
510: /*MC
511: CHKERRMPI - Checks error code, if non-zero it calls the error handler and then returns
513: Synopsis:
514: #include <petscsys.h>
515: PetscErrorCode CHKERRMPI(PetscErrorCode ierr)
517: Not Collective
519: Input Parameters:
520: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
522: Level: developer
524: Notes:
525: 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
526: which is registered with MPI_Add_error_code() when PETSc is initialized.
528: .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
529: M*/
530: #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)
532: #ifdef PETSC_CLANGUAGE_CXX
534: /*MC
535: CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
537: Synopsis:
538: #include <petscsys.h>
539: void CHKERRXX(PetscErrorCode ierr)
541: Not Collective
543: Input Parameters:
544: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
546: Level: beginner
548: Notes:
549: Once the error handler throws a ??? exception.
551: You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
552: or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
554: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
555: M*/
556: #define CHKERRXX(ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_IN_CXX,0);}} while (0)
558: #endif
560: #if defined(PETSC_HAVE_CUDA)
561: #define CHKERRCUSOLVER(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUSOLVER error %d",err);} while (0)
562: #endif
563: /*MC
564: CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
566: Synopsis:
567: #include <petscsys.h>
568: CHKMEMQ;
570: Not Collective
572: Level: beginner
574: Notes:
575: We highly recommend using valgrind https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful
576: on systems that do not have valgrind, but much much less useful.
578: Must run with the option -malloc_debug (-malloc_test in debug mode; or if PetscMallocSetDebug() called) to enable this option
580: Once the error handler is called the calling function is then returned from with the given error code.
582: By defaults prints location where memory that is corrupted was allocated.
584: Use CHKMEMA for functions that return void
586: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
587: PetscMallocValidate()
588: M*/
589: #define CHKMEMQ do {PetscErrorCode _7_PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while (0)
591: #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)
593: /*E
594: PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
596: Level: advanced
598: PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
600: Developer Notes:
601: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()
603: .seealso: PetscError(), SETERRXX()
604: E*/
605: typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
607: #if defined(__clang_analyzer__)
608: __attribute__((analyzer_noreturn))
609: #endif
610: PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);
612: PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
613: PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
614: PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
615: PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
616: PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
617: PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
618: PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
619: PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
620: PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
621: PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
622: PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
623: PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
624: PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
625: PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
627: PETSC_EXTERN void PetscSignalSegvCheckPointerOrMpi(void);
628: PETSC_DEPRECATED_FUNCTION("Use PetscSignalSegvCheckPointerOrMpi() (since version 3.13)") PETSC_STATIC_INLINE void PetscSignalSegvCheckPointer(void) {PetscSignalSegvCheckPointerOrMpi();}
630: /*MC
631: PetscErrorPrintf - Prints error messages.
633: Synopsis:
634: #include <petscsys.h>
635: PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
637: Not Collective
639: Input Parameters:
640: . format - the usual printf() format string
642: Options Database Keys:
643: + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr
644: - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)
646: Notes:
647: Use
648: $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
649: $ error is handled.) and
650: $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function
652: Use
653: PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
654: PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
656: Use
657: PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
659: Level: developer
661: Fortran Note:
662: This routine is not supported in Fortran.
665: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf()
666: M*/
667: PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);
669: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
670: PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
671: PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
672: PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);
673: PETSC_EXTERN PetscErrorCode PetscDetermineInitialFPTrap(void);
675: /*
676: Allows the code to build a stack frame as it runs
677: */
679: #define PETSCSTACKSIZE 64
681: typedef struct {
682: const char *function[PETSCSTACKSIZE];
683: const char *file[PETSCSTACKSIZE];
684: int line[PETSCSTACKSIZE];
685: PetscBool petscroutine[PETSCSTACKSIZE];
686: int currentsize;
687: int hotdepth;
688: } PetscStack;
690: PETSC_EXTERN PetscStack *petscstack;
692: PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*);
693: PetscErrorCode PetscStackPrint(PetscStack *,FILE*);
694: #if defined(PETSC_SERIALIZE_FUNCTIONS)
695: #include <petsc/private/petscfptimpl.h>
696: /*
697: Registers the current function into the global function pointer to function name table
699: Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
700: */
701: #define PetscRegister__FUNCT__() do { \
702: static PetscBool __chked = PETSC_FALSE; \
703: if (!__chked) {\
704: void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
705: __chked = PETSC_TRUE;\
706: }} while (0)
707: #else
708: #define PetscRegister__FUNCT__()
709: #endif
711: #if defined(PETSC_USE_DEBUG)
712: PETSC_STATIC_INLINE PetscBool PetscStackActive(void)
713: {
714: return(petscstack ? PETSC_TRUE : PETSC_FALSE);
715: }
717: /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error
718: * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at
719: * least more useful than "unknown" because it can distinguish multiple calls from the same function.
720: */
722: #define PetscStackPushNoCheck(funct,petsc_routine,hot) \
723: do { \
724: PetscStackSAWsTakeAccess(); \
725: if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \
726: petscstack->function[petscstack->currentsize] = funct; \
727: petscstack->file[petscstack->currentsize] = __FILE__; \
728: petscstack->line[petscstack->currentsize] = __LINE__; \
729: petscstack->petscroutine[petscstack->currentsize] = petsc_routine; \
730: petscstack->currentsize++; \
731: } \
732: if (petscstack) { \
733: petscstack->hotdepth += (hot || petscstack->hotdepth); \
734: } \
735: PetscStackSAWsGrantAccess(); \
736: } while (0)
738: #define PetscStackPopNoCheck \
739: do { \
740: PetscStackSAWsTakeAccess(); \
741: if (petscstack && petscstack->currentsize > 0) { \
742: petscstack->currentsize--; \
743: petscstack->function[petscstack->currentsize] = NULL; \
744: petscstack->file[petscstack->currentsize] = NULL; \
745: petscstack->line[petscstack->currentsize] = 0; \
746: petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\
747: } \
748: if (petscstack) { \
749: petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0); \
750: } \
751: PetscStackSAWsGrantAccess(); \
752: } while (0)
754: /*MC
756: line of PETSc functions should be return(0);
758: Synopsis:
759: #include <petscsys.h>
762: Not Collective
764: Usage:
765: .vb
766: int something;
769: .ve
771: Notes:
774: Not available in Fortran
776: Level: developer
780: M*/
782: PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \
783: PetscRegister__FUNCT__(); \
784: } while (0)
786: /*MC
788: performance-critical circumstances. Use of this function allows for lighter profiling by default.
790: Synopsis:
791: #include <petscsys.h>
794: Not Collective
796: Usage:
797: .vb
798: int something;
801: .ve
803: Notes:
804: Not available in Fortran
806: Level: developer
810: M*/
812: PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE); \
813: PetscRegister__FUNCT__(); \
814: } while (0)
816: /*MC
819: Synopsis:
820: #include <petscsys.h>
823: Not Collective
825: Usage:
826: .vb
827: int something;
830: .ve
832: Notes:
833: Final line of PETSc functions should be return(0) except for main().
835: Not available in Fortran
838: routine instead of as a PETSc library routine.
840: Level: intermediate
844: M*/
846: do { \
847: PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \
848: PetscRegister__FUNCT__(); \
849: } while (0)
852: #define PetscStackPush(n) \
853: do { \
854: PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE); \
855: CHKMEMQ; \
856: } while (0)
858: #define PetscStackPop \
859: do { \
860: CHKMEMQ; \
861: PetscStackPopNoCheck; \
862: } while (0)
864: /*MC
865: PetscFunctionReturn - Last executable line of each PETSc function
866: used for error handling. Replaces return()
868: Synopsis:
869: #include <petscsys.h>
870: void return(0);
872: Not Collective
874: Usage:
875: .vb
876: ....
877: return(0);
878: }
879: .ve
881: Notes:
882: Not available in Fortran
884: Level: developer
888: M*/
889: #define PetscFunctionReturn(a) \
890: do { \
891: PetscStackPopNoCheck; \
892: return(a);} while (0)
894: #define PetscFunctionReturnVoid() \
895: do { \
896: PetscStackPopNoCheck; \
897: return;} while (0)
899: #else
901: PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
902: #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
903: #define PetscStackPopNoCheck do {} while (0)
907: #define PetscFunctionReturn(a) return(a)
908: #define PetscFunctionReturnVoid() return
909: #define PetscStackPop CHKMEMQ
910: #define PetscStackPush(f) CHKMEMQ
912: #endif
914: /*
915: PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
917: Input Parameters:
918: + name - string that gives the name of the function being called
919: - routine - actual call to the routine, including and
921: Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes
923: 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.
927: */
928: #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while (0)
930: /*
931: PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack.
933: Input Parameters:
934: + func- name of the routine
935: - args - arguments to the routine surrounded by ()
937: Notes:
938: This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not.
940: Developer Note: this is so that when an external packge routine results in a crash or corrupts memory, they get blamed instead of PETSc.
942: */
943: #define PetscStackCallStandard(func,args) do { \
944: PetscErrorCode __ierr; \
945: PetscStackPush(#func); \
946: __func args; \
947: PetscStackPop; \
948: if (__ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)__ierr); \
949: } while (0)
951: PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
952: PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
953: PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);
955: #endif