1: /*
2: Contains all error handling interfaces for PETSc.
3: */
7: /*
8: These are the generic error codes. These error codes are used
9: many different places in the PETSc source code. The string versions are
10: at src/sys/error/err.c any changes here must also be made there
11: These are also define in include/petsc/finclude/petscerror.h any CHANGES here
12: must be also made there.
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 wrote options which should not be changed */ 62: #define PETSC_ERR_MAX_VALUE 94 /* this is always the one more than the largest error code */ 64: #define PetscStringizeArg(a) #a 65: #define PetscStringize(a) PetscStringizeArg(a) 68: /*MC
69: SETERRQ - Macro to be called when an error has been detected,
71: Synopsis:
72: #include <petscsys.h>
73: PetscErrorCodeSETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message)
75: Collective on MPI_Comm 77: Input Parameters:
78: + comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
79: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
80: - message - error message
82: Level: beginner
84: Notes:
85: Once the error handler is called the calling function is then returned from with the given error code.
87: See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
89: Experienced users can set the error handler with PetscPushErrorHandler().
91: Concepts: error^setting condition
93: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
94: M*/
95: #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s) 97: /*MC
98: SETERRMPI - Macro to be called when an error has been detected within an MPI callback function
100: Synopsis:
101: #include <petscsys.h>
102: PetscErrorCodeSETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message)
104: Collective on MPI_Comm106: Input Parameters:
107: + comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
108: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
109: - message - error message
111: Level: developer
113: Notes:
114: 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
115: which is registered with MPI_Add_error_code() when PETSc is initialized.
117: Concepts: error^setting condition
119: .seealso: SETERRQ(), CHKERRQ(), CHKERRMPI(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
120: M*/
121: #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE)123: /*MC
124: SETERRQ1 - Macro that is called when an error has been detected,
126: Synopsis:
127: #include <petscsys.h>
128: PetscErrorCodeSETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)
130: Collective on MPI_Comm132: Input Parameters:
133: + comm - A communicator, so that the error can be collective
134: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
135: . message - error message in the printf format
136: - arg - argument (for example an integer, string or double)
138: Level: beginner
140: Notes:
141: Once the error handler is called the calling function is then returned from with the given error code.
143: Experienced users can set the error handler with PetscPushErrorHandler().
145: Concepts: error^setting condition
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: PetscErrorCodeSETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)
158: Collective on MPI_Comm160: 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: Concepts: error^setting condition
176: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
177: M*/
178: #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2)180: /*MC
181: SETERRQ3 - Macro that is called when an error has been detected,
183: Synopsis:
184: #include <petscsys.h>
185: PetscErrorCodeSETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
187: Collective on MPI_Comm189: Input Parameters:
190: + comm - A communicator, so that the error can be collective
191: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
192: . message - error message in the printf format
193: . arg1 - argument (for example an integer, string or double)
194: . arg2 - argument (for example an integer, string or double)
195: - arg3 - argument (for example an integer, string or double)
197: Level: beginner
199: Notes:
200: Once the error handler is called the calling function is then returned from with the given error code.
202: There are also versions for 4, 5, 6 and 7 arguments.
204: Experienced users can set the error handler with PetscPushErrorHandler().
206: Concepts: error^setting condition
208: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
209: M*/
210: #define SETERRQ3(comm,ierr,s,a1,a2,a3) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3)212: /*MC
213: SETERRQ4 - Macro that is called when an error has been detected,
215: Synopsis:
216: #include <petscsys.h>
217: PetscErrorCodeSETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
219: Collective on MPI_Comm221: Input Parameters:
222: + comm - A communicator, so that the error can be collective
223: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
224: . message - error message in the printf format
225: . arg1 - argument (for example an integer, string or double)
226: . arg2 - argument (for example an integer, string or double)
227: . arg3 - argument (for example an integer, string or double)
228: - arg4 - argument (for example an integer, string or double)
230: Level: beginner
232: Notes:
233: Once the error handler is called the calling function is then returned from with the given error code.
235: There are also versions for 4, 5, 6 and 7 arguments.
237: Experienced users can set the error handler with PetscPushErrorHandler().
239: Concepts: error^setting condition
241: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
242: M*/
243: #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)245: /*MC
246: SETERRQ5 - Macro that is called when an error has been detected,
248: Synopsis:
249: #include <petscsys.h>
250: PetscErrorCodeSETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
252: Collective on MPI_COmm
254: Input Parameters:
255: + comm - A communicator, so that the error can be collective
256: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
257: . message - error message in the printf format
258: . arg1 - argument (for example an integer, string or double)
259: . arg2 - argument (for example an integer, string or double)
260: . arg3 - argument (for example an integer, string or double)
261: . arg4 - argument (for example an integer, string or double)
262: - arg5 - argument (for example an integer, string or double)
264: Level: beginner
266: Notes:
267: Once the error handler is called the calling function is then returned from with the given error code.
269: There are also versions for 4, 5, 6 and 7 arguments.
271: Experienced users can set the error handler with PetscPushErrorHandler().
273: Concepts: error^setting condition
275: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
276: M*/
277: #define SETERRQ5(comm,ierr,s,a1,a2,a3,a4,a5) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5)279: /*MC
280: SETERRQ6 - Macro that is called when an error has been detected,
282: Synopsis:
283: #include <petscsys.h>
284: PetscErrorCodeSETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
286: Collective on MPI_Comm288: Input Parameters:
289: + comm - A communicator, so that the error can be collective
290: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
291: . message - error message in the printf format
292: . arg1 - argument (for example an integer, string or double)
293: . arg2 - argument (for example an integer, string or double)
294: . arg3 - argument (for example an integer, string or double)
295: . arg4 - argument (for example an integer, string or double)
296: . arg5 - argument (for example an integer, string or double)
297: - arg6 - argument (for example an integer, string or double)
299: Level: beginner
301: Notes:
302: Once the error handler is called the calling function is then returned from with the given error code.
304: There are also versions for 4, 5, 6 and 7 arguments.
306: Experienced users can set the error handler with PetscPushErrorHandler().
308: Concepts: error^setting condition
310: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
311: M*/
312: #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)314: /*MC
315: SETERRQ7 - Macro that is called when an error has been detected,
317: Synopsis:
318: #include <petscsys.h>
319: PetscErrorCodeSETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
321: Collective on MPI_Comm323: Input Parameters:
324: + comm - A communicator, so that the error can be collective
325: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
326: . message - error message in the printf format
327: . arg1 - argument (for example an integer, string or double)
328: . arg2 - argument (for example an integer, string or double)
329: . arg3 - argument (for example an integer, string or double)
330: . arg4 - argument (for example an integer, string or double)
331: . arg5 - argument (for example an integer, string or double)
332: . arg6 - argument (for example an integer, string or double)
333: - arg7 - argument (for example an integer, string or double)
335: Level: beginner
337: Notes:
338: Once the error handler is called the calling function is then returned from with the given error code.
340: There are also versions for 4, 5, 6 and 7 arguments.
342: Experienced users can set the error handler with PetscPushErrorHandler().
344: Concepts: error^setting condition
346: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
347: M*/
348: #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)350: /*MC
351: SETERRQ8 - Macro that is called when an error has been detected,
353: Synopsis:
354: #include <petscsys.h>
355: PetscErrorCodeSETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
357: Collective on MPI_Comm359: Input Parameters:
360: + comm - A communicator, so that the error can be collective
361: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
362: . message - error message in the printf format
363: . arg1 - argument (for example an integer, string or double)
364: . arg2 - argument (for example an integer, string or double)
365: . arg3 - argument (for example an integer, string or double)
366: . arg4 - argument (for example an integer, string or double)
367: . arg5 - argument (for example an integer, string or double)
368: . arg6 - argument (for example an integer, string or double)
369: . arg7 - argument (for example an integer, string or double)
370: - arg8 - argument (for example an integer, string or double)
372: Level: beginner
374: Notes:
375: Once the error handler is called the calling function is then returned from with the given error code.
377: There are also versions for 4, 5, 6 and 7 arguments.
379: Experienced users can set the error handler with PetscPushErrorHandler().
381: Concepts: error^setting condition
383: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
384: M*/
385: #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)387: /*MC
388: SETERRQ9 - Macro that is called when an error has been detected,
390: Synopsis:
391: #include <petscsys.h>
392: PetscErrorCodeSETERRQ9(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
394: Collective on MPI_Comm396: Input Parameters:
397: + comm - A communicator, so that the error can be collective
398: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
399: . message - error message in the printf format
400: . arg1 - argument (for example an integer, string or double)
401: . arg2 - argument (for example an integer, string or double)
402: . arg3 - argument (for example an integer, string or double)
403: . arg4 - argument (for example an integer, string or double)
404: . arg5 - argument (for example an integer, string or double)
405: . arg6 - argument (for example an integer, string or double)
406: . arg7 - argument (for example an integer, string or double)
407: . arg8 - argument (for example an integer, string or double)
408: - arg9 - argument (for example an integer, string or double)
410: Level: beginner
412: Notes:
413: Once the error handler is called the calling function is then returned from with the given error code.
415: There are also versions for 0 to 9 arguments.
417: Experienced users can set the error handler with PetscPushErrorHandler().
419: Concepts: error^setting condition
421: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
422: M*/
423: #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)425: /*MC
426: SETERRABORT - Macro that can be called when an error has been detected,
428: Synopsis:
429: #include <petscsys.h>
430: PetscErrorCodeSETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)
432: Collective on MPI_Comm434: Input Parameters:
435: + comm - A communicator, so that the error can be collective
436: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
437: - message - error message in the printf format
439: Level: beginner
441: Notes:
442: This function just calls MPI_Abort().
444: Concepts: error^setting condition
446: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
447: M*/
448: #define SETERRABORT(comm,ierr,s) do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,ierr);} while (0)450: /*MC
451: CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns
453: Synopsis:
454: #include <petscsys.h>
455: PetscErrorCodeCHKERRQ(PetscErrorCode ierr)
457: Not Collective
459: Input Parameters:
460: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
462: Level: beginner
464: Notes:
465: Once the error handler is called the calling function is then returned from with the given error code.
467: Experienced users can set the error handler with PetscPushErrorHandler().
469: CHKERRQ(ierr) is fundamentally a macro replacement for
470: if (ierr) return(PetscError(...,ierr,...));
472: Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
473: highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
474: it cannot be used in functions which return(void) or any other datatype. In these types of functions,
475: you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
476: if (ierr) {PetscError(....); return(YourReturnType);}
477: where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
478: MPI_Abort() returned immediately.
480: Concepts: error^setting condition
482: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
483: M*/
484: #define CHKERRQ(ierr) do {if (PetscUnlikely(ierr)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");} while (0)485: #define CHKERRV(ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");return;}} while(0)486: #define CHKERRABORT(comm,ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");MPI_Abort(comm,ierr);}} while (0)487: #define CHKERRCONTINUE(ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");}} while (0)490: /*MC
491: CHKERRMPI - Checks error code, if non-zero it calls the error handler and then returns
493: Synopsis:
494: #include <petscsys.h>
495: PetscErrorCodeCHKERRMPI(PetscErrorCode ierr)
497: Not Collective
499: Input Parameters:
500: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
502: Level: developer
504: Notes:
505: 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
506: which is registered with MPI_Add_error_code() when PETSc is initialized.
508: Concepts: error^setting condition
510: .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
511: M*/
512: #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)514: #ifdef PETSC_CLANGUAGE_CXX
516: /*MC
517: CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
519: Synopsis:
520: #include <petscsys.h>
521: void CHKERRXX(PetscErrorCode ierr)
523: Not Collective
525: Input Parameters:
526: . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
528: Level: beginner
530: Notes:
531: Once the error handler throws a ??? exception.
533: You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
534: or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
536: Concepts: error^setting condition
538: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ539: M*/
540: #define CHKERRXX(ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_IN_CXX,0);}} while(0)542: #endif
544: #define CHKERRCUDA(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUDA error %d",err);} while(0)545: #define CHKERRCUBLAS(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUBLAS error %d",err);} while(0)547: /*MC
548: CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
550: Synopsis:
551: #include <petscsys.h>
552: CHKMEMQ;
554: Not Collective
556: Level: beginner
558: Notes:
559: We highly recommend using valgrind http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful
560: on systems that do not have valgrind, but much much less useful.
562: Must run with the option -malloc_debug to enable this option
564: Once the error handler is called the calling function is then returned from with the given error code.
566: By defaults prints location where memory that is corrupted was allocated.
568: Use CHKMEMA for functions that return void
570: Concepts: memory corruption
572: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
573: PetscMallocValidate()
574: M*/
575: #define CHKMEMQ do {PetscErrorCode _7_PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while(0)577: #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)579: /*E
580: PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
582: Level: advanced
584: PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
586: Developer Notes:
587: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()
589: .seealso: PetscError(), SETERRXX()
590: E*/
591: typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
593: #if defined(__clang_analyzer__)
594: __attribute__((analyzer_noreturn))595: #endif
596: PETSC_EXTERN PetscErrorCodePetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);
598: PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
599: PETSC_EXTERN PetscErrorCodePetscErrorMessage(int,const char*[],char **);
600: PETSC_EXTERN PetscErrorCodePetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
601: PETSC_EXTERN PetscErrorCodePetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
602: PETSC_EXTERN PetscErrorCodePetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
603: PETSC_EXTERN PetscErrorCodePetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
604: PETSC_EXTERN PetscErrorCodePetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
605: PETSC_EXTERN PetscErrorCodePetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
606: PETSC_EXTERN PetscErrorCodePetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
607: PETSC_EXTERN PetscErrorCodePetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
608: PETSC_EXTERN PetscErrorCodePetscPopErrorHandler(void);
609: PETSC_EXTERN PetscErrorCodePetscSignalHandlerDefault(int,void*);
610: PETSC_EXTERN PetscErrorCodePetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
611: PETSC_EXTERN PetscErrorCodePetscPopSignalHandler(void);
614: /*MC
615: PetscErrorPrintf - Prints error messages.
617: Synopsis:
618: #include <petscsys.h>
619: PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
621: Not Collective
623: Input Parameters:
624: . format - the usual printf() format string
626: Options Database Keys:
627: + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr
628: - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)
630: Notes:
631: Use
632: $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
633: $ error is handled.) and
634: $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function
636: Use
637: PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
638: PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
640: Use
641: PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
643: Level: developer
645: Fortran Note:
646: This routine is not supported in Fortran.
648: Concepts: error messages^printing
649: Concepts: printing^error messages
651: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf()
652: M*/
653: PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);
655: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
656: PETSC_EXTERN PetscErrorCodePetscSetFPTrap(PetscFPTrap);
657: PETSC_EXTERN PetscErrorCodePetscFPTrapPush(PetscFPTrap);
658: PETSC_EXTERN PetscErrorCodePetscFPTrapPop(void);
660: /*
661: Allows the code to build a stack frame as it runs
662: */
664: #define PETSCSTACKSIZE 64666: typedef struct {
667: const char *function[PETSCSTACKSIZE];
668: const char *file[PETSCSTACKSIZE];
669: int line[PETSCSTACKSIZE];
670: PetscBool petscroutine[PETSCSTACKSIZE];
671: int currentsize;
672: int hotdepth;
673: } PetscStack;
675: PETSC_EXTERN PetscStack *petscstack;
677: PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*);
678: PetscErrorCode PetscStackPrint(PetscStack *,FILE*);
679: #if defined(PETSC_SERIALIZE_FUNCTIONS)
680: #include <petsc/private/petscfptimpl.h>681: /*
682: Registers the current function into the global function pointer to function name table
684: Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
685: */
686: #define PetscRegister__FUNCT__() do { \687: static PetscBool __chked = PETSC_FALSE; \688: if (!__chked) {\689: void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\690: __chked = PETSC_TRUE;\691: }} while (0)692: #else
693: #define PetscRegister__FUNCT__()694: #endif
696: #if defined(PETSC_USE_DEBUG)
697: PETSC_STATIC_INLINE PetscBool PetscStackActive(void)698: {
699: return(petscstack ? PETSC_TRUE : PETSC_FALSE);
700: }
702: /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error
703: * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at
704: * least more useful than "unknown" because it can distinguish multiple calls from the same function.
705: */
707: #define PetscStackPushNoCheck(funct,petsc_routine,hot) \708: do { \709: PetscStackSAWsTakeAccess(); \710: if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \711: petscstack->function[petscstack->currentsize] = funct; \712: petscstack->file[petscstack->currentsize] = __FILE__; \713: petscstack->line[petscstack->currentsize] = __LINE__; \714: petscstack->petscroutine[petscstack->currentsize] = petsc_routine; \715: petscstack->currentsize++; \716: } \717: if (petscstack) { \718: petscstack->hotdepth += (hot || petscstack->hotdepth); \719: } \720: PetscStackSAWsGrantAccess(); \721: } while (0)723: #define PetscStackPopNoCheck \724: do { \725: PetscStackSAWsTakeAccess(); \726: if (petscstack && petscstack->currentsize > 0) { \727: petscstack->currentsize--; \728: petscstack->function[petscstack->currentsize] = 0; \729: petscstack->file[petscstack->currentsize] = 0; \730: petscstack->line[petscstack->currentsize] = 0; \731: petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\732: } \733: if (petscstack) { \734: petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0); \735: } \736: PetscStackSAWsGrantAccess(); \737: } while (0)739: /*MC
741: line of PETSc functions should be return(0);
743: Synopsis:
744: #include <petscsys.h>
747: Not Collective
749: Usage:
750: .vb
751: int something;
754: .ve
756: Notes:
759: Not available in Fortran
761: Level: developer
765: .keywords: traceback, error handling
766: M*/
768: PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \769: PetscRegister__FUNCT__(); \770: } while (0)772: /*MC
774: performance-critical circumstances. Use of this function allows for lighter profiling by default.
776: Synopsis:
777: #include <petscsys.h>
780: Not Collective
782: Usage:
783: .vb
784: int something;
787: .ve
789: Notes:
790: Not available in Fortran
792: Level: developer
796: .keywords: traceback, error handling
797: M*/
799: PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE); \800: PetscRegister__FUNCT__(); \801: } while (0)803: /*MC
806: Synopsis:
807: #include <petscsys.h>
810: Not Collective
812: Usage:
813: .vb
814: int something;
817: .ve
819: Notes:
820: Final line of PETSc functions should be return(0) except for main().
822: Not available in Fortran
825: routine instead of as a PETSc library routine.
827: Level: intermediate
831: .keywords: traceback, error handling
832: M*/
834: do { \835: PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \836: PetscRegister__FUNCT__(); \837: } while (0)840: #define PetscStackPush(n) \841: do { \842: PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE); \843: CHKMEMQ; \844: } while (0)846: #define PetscStackPop \847: do { \848: CHKMEMQ; \849: PetscStackPopNoCheck; \850: } while (0)852: /*MC
853: PetscFunctionReturn - Last executable line of each PETSc function
854: used for error handling. Replaces return()
856: Synopsis:
857: #include <petscsys.h>
858: void return(0);
860: Not Collective
862: Usage:
863: .vb
864: ....
865: return(0);
866: }
867: .ve
869: Notes:
870: Not available in Fortran
872: Level: developer
876: .keywords: traceback, error handling
877: M*/
878: #define PetscFunctionReturn(a) \879: do { \880: PetscStackPopNoCheck; \881: return(a);} while (0)883: #define PetscFunctionReturnVoid() \884: do { \885: PetscStackPopNoCheck; \886: return;} while (0)888: #else
890: PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
891: #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)892: #define PetscStackPopNoCheck do {} while (0)896: #define PetscFunctionReturn(a) return(a)897: #define PetscFunctionReturnVoid() return898: #define PetscStackPop CHKMEMQ899: #define PetscStackPush(f) CHKMEMQ901: #endif
903: /*
904: PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
906: Input Parameters:
907: + name - string that gives the name of the function being called
908: - routine - actual call to the routine, including and
910: Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes
912: 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.
916: */
917: #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while(0)919: /*
920: PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack.
922: Input Parameters:
923: + func- name of the routine
924: - args - arguments to the routine surrounded by ()
926: Notes:
927: This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not.
929: Developer Note: this is so that when an external packge routine results in a crash or corrupts memory, they get blamed instead of PETSc.
931: */
932: #define PetscStackCallStandard(func,args) do { \933: PetscErrorCode __ierr; \934: PetscStackPush(#func); \935: __func args; \936: PetscStackPop; \937: if (__ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)__ierr); \938: } while (0)940: PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
941: PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
942: PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);
944: #endif