Actual source code: petscerror.h
petsc-master 2020-08-25
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/Section 1.5 Writing Application Codes with PETSc 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 */
65: #define PetscStringizeArg(a) #a
66: #define PetscStringize(a) PetscStringizeArg(a)
69: /*MC
70: SETERRQ - Macro to be called when an error has been detected,
72: Synopsis:
73: #include <petscsys.h>
74: PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message)
76: Collective
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
83: Level: beginner
85: Notes:
86: Once the error handler is called the calling function is then returned from with the given error code.
88: See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
90: Experienced users can set the error handler with PetscPushErrorHandler().
92: Fortran Notes:
93: SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the
94: Fortran main program.
96: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
97: M*/
98: #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s)
100: /*MC
101: SETERRMPI - Macro to be called when an error has been detected within an MPI callback function
103: Synopsis:
104: #include <petscsys.h>
105: PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message)
107: Collective
109: Input Parameters:
110: + comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
111: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
112: - message - error message
114: Level: developer
116: Notes:
117: 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
118: which is registered with MPI_Add_error_code() when PETSc is initialized.
120: .seealso: SETERRQ(), CHKERRQ(), CHKERRMPI(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
121: M*/
122: #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE)
124: /*MC
125: SETERRQ1 - Macro that is called when an error has been detected,
127: Synopsis:
128: #include <petscsys.h>
129: PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)
131: Collective
133: Input Parameters:
134: + comm - A communicator, so that the error can be collective
135: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
136: . message - error message in the printf format
137: - arg - argument (for example an integer, string or double)
139: Level: beginner
141: Notes:
142: Once the error handler is called the calling function is then returned from with the given error code.
144: Experienced users can set the error handler with PetscPushErrorHandler().
146: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
147: M*/
148: #define SETERRQ1(comm,ierr,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1)
150: /*MC
151: SETERRQ2 - Macro that is called when an error has been detected,
153: Synopsis:
154: #include <petscsys.h>
155: PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)
157: Collective
159: Input Parameters:
160: + comm - A communicator, so that the error can be collective
161: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
162: . message - error message in the printf format
163: . arg1 - argument (for example an integer, string or double)
164: - arg2 - argument (for example an integer, string or double)
166: Level: beginner
168: Notes:
169: Once the error handler is called the calling function is then returned from with the given error code.
171: Experienced users can set the error handler with PetscPushErrorHandler().
173: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
174: M*/
175: #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2)
177: /*MC
178: SETERRQ3 - Macro that is called when an error has been detected,
180: Synopsis:
181: #include <petscsys.h>
182: PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
184: Collective
186: Input Parameters:
187: + comm - A communicator, so that the error can be collective
188: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
189: . message - error message in the printf format
190: . arg1 - argument (for example an integer, string or double)
191: . arg2 - argument (for example an integer, string or double)
192: - arg3 - argument (for example an integer, string or double)
194: Level: beginner
196: Notes:
197: Once the error handler is called the calling function is then returned from with the given error code.
199: There are also versions for 4, 5, 6 and 7 arguments.
201: Experienced users can set the error handler with PetscPushErrorHandler().
203: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
204: M*/
205: #define SETERRQ3(comm,ierr,s,a1,a2,a3) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3)
207: /*MC
208: SETERRQ4 - Macro that is called when an error has been detected,
210: Synopsis:
211: #include <petscsys.h>
212: PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4)
214: Collective
216: Input Parameters:
217: + comm - A communicator, so that the error can be collective
218: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
219: . message - error message in the printf format
220: . arg1 - argument (for example an integer, string or double)
221: . arg2 - argument (for example an integer, string or double)
222: . arg3 - argument (for example an integer, string or double)
223: - arg4 - argument (for example an integer, string or double)
225: Level: beginner
227: Notes:
228: Once the error handler is called the calling function is then returned from with the given error code.
230: There are also versions for 4, 5, 6 and 7 arguments.
232: Experienced users can set the error handler with PetscPushErrorHandler().
234: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
235: M*/
236: #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)
238: /*MC
239: SETERRQ5 - Macro that is called when an error has been detected,
241: Synopsis:
242: #include <petscsys.h>
243: PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5)
245: Collective
247: Input Parameters:
248: + comm - A communicator, so that the error can be collective
249: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
250: . message - error message in the printf format
251: . arg1 - argument (for example an integer, string or double)
252: . arg2 - argument (for example an integer, string or double)
253: . arg3 - argument (for example an integer, string or double)
254: . arg4 - argument (for example an integer, string or double)
255: - arg5 - argument (for example an integer, string or double)
257: Level: beginner
259: Notes:
260: Once the error handler is called the calling function is then returned from with the given error code.
262: There are also versions for 4, 5, 6 and 7 arguments.
264: Experienced users can set the error handler with PetscPushErrorHandler().
266: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
267: M*/
268: #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)
270: /*MC
271: SETERRQ6 - Macro that is called when an error has been detected,
273: Synopsis:
274: #include <petscsys.h>
275: PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6)
277: Collective
279: Input Parameters:
280: + comm - A communicator, so that the error can be collective
281: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
282: . message - error message in the printf format
283: . arg1 - argument (for example an integer, string or double)
284: . arg2 - argument (for example an integer, string or double)
285: . arg3 - argument (for example an integer, string or double)
286: . arg4 - argument (for example an integer, string or double)
287: . arg5 - argument (for example an integer, string or double)
288: - arg6 - argument (for example an integer, string or double)
290: Level: beginner
292: Notes:
293: Once the error handler is called the calling function is then returned from with the given error code.
295: There are also versions for 4, 5, 6 and 7 arguments.
297: Experienced users can set the error handler with PetscPushErrorHandler().
299: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
300: M*/
301: #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)
303: /*MC
304: SETERRQ7 - Macro that is called when an error has been detected,
306: Synopsis:
307: #include <petscsys.h>
308: PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
310: Collective
312: Input Parameters:
313: + comm - A communicator, so that the error can be collective
314: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
315: . message - error message in the printf format
316: . arg1 - argument (for example an integer, string or double)
317: . arg2 - argument (for example an integer, string or double)
318: . arg3 - argument (for example an integer, string or double)
319: . arg4 - argument (for example an integer, string or double)
320: . arg5 - argument (for example an integer, string or double)
321: . arg6 - argument (for example an integer, string or double)
322: - arg7 - argument (for example an integer, string or double)
324: Level: beginner
326: Notes:
327: Once the error handler is called the calling function is then returned from with the given error code.
329: There are also versions for 4, 5, 6 and 7 arguments.
331: Experienced users can set the error handler with PetscPushErrorHandler().
333: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
334: M*/
335: #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)
337: /*MC
338: SETERRQ8 - Macro that is called when an error has been detected,
340: Synopsis:
341: #include <petscsys.h>
342: PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)
344: Collective
346: Input Parameters:
347: + comm - A communicator, so that the error can be collective
348: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
349: . message - error message in the printf format
350: . arg1 - argument (for example an integer, string or double)
351: . arg2 - argument (for example an integer, string or double)
352: . arg3 - argument (for example an integer, string or double)
353: . arg4 - argument (for example an integer, string or double)
354: . arg5 - argument (for example an integer, string or double)
355: . arg6 - argument (for example an integer, string or double)
356: . arg7 - argument (for example an integer, string or double)
357: - arg8 - argument (for example an integer, string or double)
359: Level: beginner
361: Notes:
362: Once the error handler is called the calling function is then returned from with the given error code.
364: There are also versions for 4, 5, 6 and 7 arguments.
366: Experienced users can set the error handler with PetscPushErrorHandler().
368: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
369: M*/
370: #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)
372: /*MC
373: SETERRQ9 - Macro that is called when an error has been detected,
375: Synopsis:
376: #include <petscsys.h>
377: PetscErrorCode SETERRQ9(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
379: Collective
381: Input Parameters:
382: + comm - A communicator, so that the error can be collective
383: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
384: . message - error message in the printf format
385: . arg1 - argument (for example an integer, string or double)
386: . arg2 - argument (for example an integer, string or double)
387: . arg3 - argument (for example an integer, string or double)
388: . arg4 - argument (for example an integer, string or double)
389: . arg5 - argument (for example an integer, string or double)
390: . arg6 - argument (for example an integer, string or double)
391: . arg7 - argument (for example an integer, string or double)
392: . arg8 - argument (for example an integer, string or double)
393: - arg9 - argument (for example an integer, string or double)
395: Level: beginner
397: Notes:
398: Once the error handler is called the calling function is then returned from with the given error code.
400: There are also versions for 0 to 9 arguments.
402: Experienced users can set the error handler with PetscPushErrorHandler().
404: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
405: M*/
406: #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)
408: /*MC
409: SETERRABORT - Macro that can be called when an error has been detected,
411: Synopsis:
412: #include <petscsys.h>
413: PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)
415: Collective
417: Input Parameters:
418: + comm - A communicator, so that the error can be collective
419: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
420: - message - error message in the printf format
422: Level: beginner
424: Notes:
425: This function just calls MPI_Abort().
427: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
428: M*/
429: #define SETERRABORT(comm,ierr,s) do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,ierr);} while (0)
431: /*MC
432: CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns
434: Synopsis:
435: #include <petscsys.h>
436: PetscErrorCode CHKERRQ(PetscErrorCode ierr)
438: Not Collective
440: Input Parameters:
441: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
443: Level: beginner
445: Notes:
446: Once the error handler is called the calling function is then returned from with the given error code.
448: Experienced users can set the error handler with PetscPushErrorHandler().
450: CHKERRQ(ierr) is fundamentally a macro replacement for
451: if (ierr) return(PetscError(...,ierr,...));
453: Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
454: highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
455: it cannot be used in functions which return(void) or any other datatype. In these types of functions,
456: you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
457: if (ierr) {PetscError(....); return(YourReturnType);}
458: where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
459: MPI_Abort() returned immediately.
461: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
462: M*/
463: #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)
464: #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)
465: #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)
466: #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)
468: PETSC_EXTERN PetscErrorCode PetscAbortFindSourceFile_Private(const char*,PetscInt*);
470: /*MC
471: PETSCABORT - Call MPI_Abort with an informative error code
473: Synopsis:
474: #include <petscsys.h>
475: PETSCABORT(MPI_Comm comm, PetscErrorCode ierr)
477: Collective
479: Input Parameters:
480: + comm - A communicator, so that the error can be collective
481: - ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
483: Level: beginner
485: Notes: We pass MPI_Abort() an error code of format XX_YYYY_ZZZ, where XX, YYYY are an index and line number of the file
486: where PETSCABORT is called, respectively. ZZZ is the PETSc error code.
488: If XX is zero, this means that the call was made in the routine main().
489: 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[]
490: is out of date. PETSc developers have to update it.
491: 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.
493: M*/
494: #define PETSCABORT(comm,ierr) \
495: do { \
496: PetscInt idx = 0; \
497: PetscMPIInt errcode; \
498: PetscAbortFindSourceFile_Private(__FILE__,&idx); \
499: errcode = (PetscMPIInt)(idx*10000000 + __LINE__*1000 + ierr); \
500: MPI_Abort(comm,errcode); \
501: } while (0)
503: /*MC
504: CHKERRMPI - Checks error code, if non-zero it calls the error handler and then returns
506: Synopsis:
507: #include <petscsys.h>
508: PetscErrorCode CHKERRMPI(PetscErrorCode ierr)
510: Not Collective
512: Input Parameters:
513: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
515: Level: developer
517: Notes:
518: 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
519: which is registered with MPI_Add_error_code() when PETSc is initialized.
521: .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
522: M*/
523: #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)
525: #ifdef PETSC_CLANGUAGE_CXX
527: /*MC
528: CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
530: Synopsis:
531: #include <petscsys.h>
532: void CHKERRXX(PetscErrorCode ierr)
534: Not Collective
536: Input Parameters:
537: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
539: Level: beginner
541: Notes:
542: Once the error handler throws a ??? exception.
544: You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
545: or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
547: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
548: M*/
549: #define CHKERRXX(ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_IN_CXX,0);}} while (0)
551: #endif
553: #if defined(PETSC_HAVE_CUDA)
554: #define CHKERRCUSOLVER(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUSOLVER error %d",err);} while (0)
555: #endif
556: /*MC
557: CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
559: Synopsis:
560: #include <petscsys.h>
561: CHKMEMQ;
563: Not Collective
565: Level: beginner
567: Notes:
568: We highly recommend using valgrind https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful
569: on systems that do not have valgrind, but much much less useful.
571: Must run with the option -malloc_debug (-malloc_test in debug mode; or if PetscMallocSetDebug() called) to enable this option
573: Once the error handler is called the calling function is then returned from with the given error code.
575: By defaults prints location where memory that is corrupted was allocated.
577: Use CHKMEMA for functions that return void
579: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
580: PetscMallocValidate()
581: M*/
582: #define CHKMEMQ do {PetscErrorCode _7_PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while (0)
584: #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)
586: /*E
587: PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
589: Level: advanced
591: PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
593: Developer Notes:
594: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()
596: .seealso: PetscError(), SETERRXX()
597: E*/
598: typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
600: #if defined(__clang_analyzer__)
601: __attribute__((analyzer_noreturn))
602: #endif
603: PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);
605: PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
606: PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
607: PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
608: PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
609: PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
610: PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
611: PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
612: PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
613: PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
614: PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
615: PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
616: PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
617: PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
618: PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
620: PETSC_EXTERN void PetscSignalSegvCheckPointerOrMpi(void);
621: PETSC_DEPRECATED_FUNCTION("Use PetscSignalSegvCheckPointerOrMpi() (since version 3.13)") PETSC_STATIC_INLINE void PetscSignalSegvCheckPointer(void) {PetscSignalSegvCheckPointerOrMpi();}
623: /*MC
624: PetscErrorPrintf - Prints error messages.
626: Synopsis:
627: #include <petscsys.h>
628: PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
630: Not Collective
632: Input Parameters:
633: . format - the usual printf() format string
635: Options Database Keys:
636: + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr
637: - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)
639: Notes:
640: Use
641: $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
642: $ error is handled.) and
643: $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function
645: Use
646: PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
647: PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
649: Use
650: PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
652: Level: developer
654: Fortran Note:
655: This routine is not supported in Fortran.
658: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf()
659: M*/
660: PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);
662: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
663: PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
664: PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
665: PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);
666: PETSC_EXTERN PetscErrorCode PetscDetermineInitialFPTrap(void);
668: /*
669: Allows the code to build a stack frame as it runs
670: */
672: #define PETSCSTACKSIZE 64
674: typedef struct {
675: const char *function[PETSCSTACKSIZE];
676: const char *file[PETSCSTACKSIZE];
677: int line[PETSCSTACKSIZE];
678: PetscBool petscroutine[PETSCSTACKSIZE];
679: int currentsize;
680: int hotdepth;
681: } PetscStack;
683: PETSC_EXTERN PetscStack *petscstack;
685: PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*);
686: PetscErrorCode PetscStackPrint(PetscStack *,FILE*);
687: #if defined(PETSC_SERIALIZE_FUNCTIONS)
688: #include <petsc/private/petscfptimpl.h>
689: /*
690: Registers the current function into the global function pointer to function name table
692: Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
693: */
694: #define PetscRegister__FUNCT__() do { \
695: static PetscBool __chked = PETSC_FALSE; \
696: if (!__chked) {\
697: void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
698: __chked = PETSC_TRUE;\
699: }} while (0)
700: #else
701: #define PetscRegister__FUNCT__()
702: #endif
704: #if defined(PETSC_USE_DEBUG)
705: PETSC_STATIC_INLINE PetscBool PetscStackActive(void)
706: {
707: return(petscstack ? PETSC_TRUE : PETSC_FALSE);
708: }
710: /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error
711: * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at
712: * least more useful than "unknown" because it can distinguish multiple calls from the same function.
713: */
715: #define PetscStackPushNoCheck(funct,petsc_routine,hot) \
716: do { \
717: PetscStackSAWsTakeAccess(); \
718: if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \
719: petscstack->function[petscstack->currentsize] = funct; \
720: petscstack->file[petscstack->currentsize] = __FILE__; \
721: petscstack->line[petscstack->currentsize] = __LINE__; \
722: petscstack->petscroutine[petscstack->currentsize] = petsc_routine; \
723: petscstack->currentsize++; \
724: } \
725: if (petscstack) { \
726: petscstack->hotdepth += (hot || petscstack->hotdepth); \
727: } \
728: PetscStackSAWsGrantAccess(); \
729: } while (0)
731: #define PetscStackPopNoCheck \
732: do { \
733: PetscStackSAWsTakeAccess(); \
734: if (petscstack && petscstack->currentsize > 0) { \
735: petscstack->currentsize--; \
736: petscstack->function[petscstack->currentsize] = NULL; \
737: petscstack->file[petscstack->currentsize] = NULL; \
738: petscstack->line[petscstack->currentsize] = 0; \
739: petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\
740: } \
741: if (petscstack) { \
742: petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0); \
743: } \
744: PetscStackSAWsGrantAccess(); \
745: } while (0)
747: /*MC
749: line of PETSc functions should be return(0);
751: Synopsis:
752: #include <petscsys.h>
755: Not Collective
757: Usage:
758: .vb
759: int something;
762: .ve
764: Notes:
767: Not available in Fortran
769: Level: developer
773: M*/
775: PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \
776: PetscRegister__FUNCT__(); \
777: } while (0)
779: /*MC
781: performance-critical circumstances. Use of this function allows for lighter profiling by default.
783: Synopsis:
784: #include <petscsys.h>
787: Not Collective
789: Usage:
790: .vb
791: int something;
794: .ve
796: Notes:
797: Not available in Fortran
799: Level: developer
803: M*/
805: PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE); \
806: PetscRegister__FUNCT__(); \
807: } while (0)
809: /*MC
812: Synopsis:
813: #include <petscsys.h>
816: Not Collective
818: Usage:
819: .vb
820: int something;
823: .ve
825: Notes:
826: Final line of PETSc functions should be return(0) except for main().
828: Not available in Fortran
831: routine instead of as a PETSc library routine.
833: Level: intermediate
837: M*/
839: do { \
840: PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \
841: PetscRegister__FUNCT__(); \
842: } while (0)
845: #define PetscStackPush(n) \
846: do { \
847: PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE); \
848: CHKMEMQ; \
849: } while (0)
851: #define PetscStackPop \
852: do { \
853: CHKMEMQ; \
854: PetscStackPopNoCheck; \
855: } while (0)
857: /*MC
858: PetscFunctionReturn - Last executable line of each PETSc function
859: used for error handling. Replaces return()
861: Synopsis:
862: #include <petscsys.h>
863: void return(0);
865: Not Collective
867: Usage:
868: .vb
869: ....
870: return(0);
871: }
872: .ve
874: Notes:
875: Not available in Fortran
877: Level: developer
881: M*/
882: #define PetscFunctionReturn(a) \
883: do { \
884: PetscStackPopNoCheck; \
885: return(a);} while (0)
887: #define PetscFunctionReturnVoid() \
888: do { \
889: PetscStackPopNoCheck; \
890: return;} while (0)
892: #else
894: PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
895: #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
896: #define PetscStackPopNoCheck do {} while (0)
900: #define PetscFunctionReturn(a) return(a)
901: #define PetscFunctionReturnVoid() return
902: #define PetscStackPop CHKMEMQ
903: #define PetscStackPush(f) CHKMEMQ
905: #endif
907: /*
908: PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
910: Input Parameters:
911: + name - string that gives the name of the function being called
912: - routine - actual call to the routine, including and
914: Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes
916: 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.
920: */
921: #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while (0)
923: /*
924: PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack.
926: Input Parameters:
927: + func- name of the routine
928: - args - arguments to the routine surrounded by ()
930: Notes:
931: This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not.
933: Developer Note: this is so that when an external packge routine results in a crash or corrupts memory, they get blamed instead of PETSc.
935: */
936: #define PetscStackCallStandard(func,args) do { \
937: PetscErrorCode __ierr; \
938: PetscStackPush(#func); \
939: __func args; \
940: PetscStackPop; \
941: if (__ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)__ierr); \
942: } while (0)
944: PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
945: PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
946: PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);
948: #endif