Actual source code: petscerror.h
1: /*
2: Contains all error handling interfaces for PETSc.
3: */
6: #include petsc.h
9: /*
10: Defines the directory where the compiled source is located; used
11: in printing error messages. Each makefile has an entry
12: LOCDIR = thedirectory
13: and bmake/common_variables includes in CCPPFLAGS -D__SDIR__='"${LOCDIR}"'
14: which is a flag passed to the C/C++ compilers. This declaration below
15: is only needed if some code is compiled without the -D__SDIR__
16: */
19: #endif
21: /*
22: Defines the function where the compiled source is located; used
23: in printing error messages. This is defined here in case the user
24: does not declare it.
25: */
28: #endif
30: /*
31: These are the generic error codes. These error codes are used
32: many different places in the PETSc source code. The string versions are
33: at src/sys/error/err.c any changes here must also be made there
34: These are also define in include/finclude/petscerror.h any CHANGES here
35: must be also made there.
37: */
38: #define PETSC_ERR_MIN_VALUE 54 /* should always be one less then the smallest value */
40: #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */
41: #define PETSC_ERR_SUP 56 /* no support for requested operation */
42: #define PETSC_ERR_SUP_SYS 57 /* no support for requested operation on this computer system */
43: #define PETSC_ERR_ORDER 58 /* operation done in wrong order */
44: #define PETSC_ERR_SIG 59 /* signal received */
45: #define PETSC_ERR_FP 72 /* floating point exception */
46: #define PETSC_ERR_COR 74 /* corrupted PETSc object */
47: #define PETSC_ERR_LIB 76 /* error in library called by PETSc */
48: #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */
49: #define PETSC_ERR_MEMC 78 /* memory corruption */
50: #define PETSC_ERR_CONV_FAILED 82 /* iterative method (KSP or SNES) failed */
51: #define PETSC_ERR_USER 83 /* user has not provided needed function */
52: #define PETSC_ERR_SYS 88 /* error in system call */
54: #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */
55: #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */
56: #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */
57: #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */
58: #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */
59: #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */
60: #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */
61: #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */
62: #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */
63: #define PETSC_ERR_ARG_TYPENOTSET 89 /* the type of the object has not yet been set */
64: #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */
65: #define PETSC_ERR_ARG_NULL 85 /* argument is null that should not be */
66: #define PETSC_ERR_ARG_UNKNOWN_TYPE 86 /* type name doesn't match any registered type */
68: #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */
69: #define PETSC_ERR_FILE_READ 66 /* unable to read from file */
70: #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */
71: #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */
73: #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */
74: #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */
76: #define PETSC_ERR_FLOP_COUNT 90
77: #define PETSC_ERR_MAX_VALUE 91 /* this is always the one more than the largest error code */
79: #if defined(PETSC_USE_ERRORCHECKING)
81: /*MC
82: SETERRQ - Macro that is called when an error has been detected,
84: Not Collective
86: Synopsis:
87: PetscErrorCode SETERRQ(PetscErrorCode errorcode,char *message)
90: Input Parameters:
91: + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
92: - message - error message
94: Level: beginner
96: Notes:
97: Once the error handler is called the calling function is then returned from with the given error code.
99: See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
101: In Fortran MPI_Abort() is always called
103: Experienced users can set the error handler with PetscPushErrorHandler().
105: Concepts: error^setting condition
107: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
108: M*/
109: #define SETERRQ(n,s) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);}
111: /*MC
112: SETERRQ1 - Macro that is called when an error has been detected,
114: Not Collective
116: Synopsis:
117: PetscErrorCode SETERRQ1(PetscErrorCode errorcode,char *formatmessage,arg)
120: Input Parameters:
121: + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
122: . message - error message in the printf format
123: - arg - argument (for example an integer, string or double)
125: Level: beginner
127: Notes:
128: Once the error handler is called the calling function is then returned from with the given error code.
130: Experienced users can set the error handler with PetscPushErrorHandler().
132: Concepts: error^setting condition
134: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
135: M*/
136: #define SETERRQ1(n,s,a1) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1);}
138: /*MC
139: SETERRQ2 - Macro that is called when an error has been detected,
141: Not Collective
143: Synopsis:
144: PetscErrorCode SETERRQ2(PetscErrorCode errorcode,char *formatmessage,arg1,arg2)
147: Input Parameters:
148: + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
149: . message - error message in the printf format
150: . arg1 - argument (for example an integer, string or double)
151: - arg2 - argument (for example an integer, string or double)
153: Level: beginner
155: Notes:
156: Once the error handler is called the calling function is then returned from with the given error code.
158: Experienced users can set the error handler with PetscPushErrorHandler().
160: Concepts: error^setting condition
162: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
163: M*/
164: #define SETERRQ2(n,s,a1,a2) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2);}
166: /*MC
167: SETERRQ3 - Macro that is called when an error has been detected,
169: Not Collective
171: Synopsis:
172: PetscErrorCode SETERRQ3(PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3)
175: Input Parameters:
176: + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
177: . message - error message in the printf format
178: . arg1 - argument (for example an integer, string or double)
179: . arg2 - argument (for example an integer, string or double)
180: - arg3 - argument (for example an integer, string or double)
182: Level: beginner
184: Notes:
185: Once the error handler is called the calling function is then returned from with the given error code.
187: There are also versions for 4, 5, 6 and 7 arguments.
189: Experienced users can set the error handler with PetscPushErrorHandler().
191: Concepts: error^setting condition
193: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
194: M*/
195: #define SETERRQ3(n,s,a1,a2,a3) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3);}
197: #define SETERRQ4(n,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4);}
198: #define SETERRQ5(n,s,a1,a2,a3,a4,a5) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5);}
199: #define SETERRQ6(n,s,a1,a2,a3,a4,a5,a6) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5,a6);}
200: #define SETERRQ7(n,s,a1,a2,a3,a4,a5,a6,a7) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5,a6,a7);}
201: #define SETERRABORT(comm,n,s) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);MPI_Abort(comm,n);}
203: /*MC
204: CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns
206: Not Collective
208: Synopsis:
209: PetscErrorCode CHKERRQ(PetscErrorCode errorcode)
212: Input Parameters:
213: . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
215: Level: beginner
217: Notes:
218: Once the error handler is called the calling function is then returned from with the given error code.
220: Experienced users can set the error handler with PetscPushErrorHandler().
222: CHKERRQ(n) is fundamentally a macro replacement for
223: if (n) return(PetscError(...,n,...));
225: Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
226: highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
227: it cannot be used in functions which return(void) or any other datatype. In these types of functions,
228: you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
229: if (n) {PetscError(....); return(YourReturnType);}
230: where you may pass back a PETSC_NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
231: MPI_Abort() returned immediately.
233: In Fortran MPI_Abort() is always called
235: Concepts: error^setting condition
237: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
238: M*/
239: #define CHKERRQ(n) if (n) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");}
241: #define CHKERRV(n) if (n) {n = PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");return;}
242: #define CHKERRABORT(comm,n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");MPI_Abort(comm,n);}
243: #define CHKERRCONTINUE(n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");}
245: #ifdef PETSC_CLANGUAGE_CXX
247: #define CHKERRXX(n) if (n) {PetscErrorCxx(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0);}
249: #endif
251: /*MC
252: CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
254: Not Collective
256: Synopsis:
257: CHKMEMQ;
259: Level: beginner
261: Notes:
262: Must run with the option -malloc_debug to enable this option
264: Once the error handler is called the calling function is then returned from with the given error code.
266: By defaults prints location where memory that is corrupted was allocated.
268: Use CHKMEMA for functions that return void
270: Concepts: memory corruption
272: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
273: PetscMallocValidate()
274: M*/
275: #define CHKMEMQ {PetscErrorCode _7_PetscMallocValidate(__LINE__,__FUNCT__,__FILE__,__SDIR__);CHKERRQ(_7_ierr);}
277: #define CHKMEMA {PetscMallocValidate(__LINE__,__FUNCT__,__FILE__,__SDIR__);}
279: #if defined(PETSC_UNDERSCORE_CHKERR)
281: #define _ __g
283: #endif
285: #define PETSC_EXCEPTIONS_MAX 256
291: EXTERN PetscErrorCode PetscExceptionPush(PetscErrorCode);
292: EXTERN PetscErrorCode PetscExceptionPop(PetscErrorCode);
294: EXTERN PetscErrorCode PetscErrorSetCatchable(PetscErrorCode,PetscTruth);
295: EXTERN PetscTruth PetscErrorIsCatchable(PetscErrorCode);
296: /*MC
297: PetscExceptionCaught - Indicates if a specific exception zierr was caught.
299: Not Collective
301: Synopsis:
302: PetscTruth PetscExceptionCaught(PetscErrorCode xierr,PetscErrorCode zierr);
304: Input Parameters:
305: + xierr - error code returned from PetscExceptionTry1() or other PETSc routine
306: - zierr - error code you want it to be
308: Level: advanced
310: Notes:
311: PETSc must not be configured using the option --with-errorchecking=0 for this to work
313: Use PetscExceptionValue() to see if an error code is being "tried"
315: Concepts: exceptions, exception handling
317: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
318: CHKERRQ(), PetscExceptionTry1(), PetscExceptionValue()
319: M*/
320: PETSC_STATIC_INLINE PetscTruth PetscExceptionCaught(PetscErrorCode xierr,PetscErrorCode zierr)
321: {
322: PetscInt i;
323: if (xierr != zierr) return PETSC_FALSE;
324: for (i=0; i<PetscErrorUncatchableCount; i++) {
325: if (PetscErrorUncatchable[i] == zierr) {
326: return PETSC_FALSE;
327: }
328: }
329: return PETSC_TRUE;
330: }
332: /*MC
333: PetscExceptionValue - Indicates if the error code is one that is currently being tried
335: Not Collective
337: Synopsis:
338: PetscTruth PetscExceptionValue(PetscErrorCode xierr);
340: Input Parameters:
341: . xierr - error code
343: Level: developer
345: Notes:
346: PETSc must not be configured using the option --with-errorchecking=0 for this to work
348: Use PetscExceptionCaught() to see if the current error code is EXACTLY the one you want
350: Concepts: exceptions, exception hanlding
352: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
353: CHKERRQ(), PetscExceptionTry1(), PetscExceptionCaught()
354: M*/
355: PETSC_STATIC_INLINE PetscTruth PetscExceptionValue(PetscErrorCode zierr)
356: {
357: PetscInt i;
358: for (i=0; i<PetscExceptionsCount; i++) {
359: if (PetscExceptions[i] == zierr) {
360: return PETSC_TRUE;
361: }
362: }
363: return PETSC_FALSE;
364: }
366: /*MC
367: PetscExceptionTry1 - Runs the routine, causing a particular error code to be treated as an exception,
368: rather than an error. That is if that error code is treated the program returns to this level,
369: but does not call the error handlers
371: Not Collective
373: Synopsis:
374: PetscErrorCode PetscExceptionTry1(PetscErrorCode routine(....),PetscErrorCode);
376: Level: advanced
378: No Fortran Equivalent (see PetscExceptionPush() for Fortran)
380: Notes:
381: PETSc must not be configured using the option --with-errorchecking=0 for this to work
383: Note: In general, the outer most try on an exception is the one that will be caught (that is trys down in
384: PETSc code will not usually handle an exception that was issued above). See SNESSolve() for an example
385: of how the local try is ignored if a higher (in the stack) one is also in effect.
387: Concepts: exceptions, exception hanlding
389: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
390: CHKERRQ(), PetscExceptionCaught(), PetscExceptionPush(), PetscExceptionPop()
391: M*/
393: #define PetscExceptionTry1(a,b) (PetscExceptionTmp1 = PetscExceptionPush(b)) ? PetscExceptionTmp1 : (PetscExceptionTmp1 = a, (PetscExceptionTmp = PetscExceptionPop(b)) ? PetscExceptionTmp : PetscExceptionTmp1)
395: /*
396: Used by PetscExceptionTrySync(). Returns zierr on ALL processes in comm iff xierr is zierr on at least one process and zero on all others.
397: */
398: PETSC_STATIC_INLINE PetscErrorCode PetscExceptionTrySync_Private(MPI_Comm comm,PetscErrorCode xierr,PetscErrorCode zierr)
399: {
400: PetscReal in[2],out[2];
403: if (xierr != zierr) return xierr;
405: in[0] = xierr;
406: in[1] = 0.0; /* dummy value */
408: MPI_Allreduce(in,out,2,MPIU_REAL,0,comm); if (ierr) {;}
409: return xierr;
410: }
412: /*MC
413: PetscExceptionTrySyncNorm - Runs the routine, causing a particular error code to be treated as an exception,
414: rather than an error. That is if that error code is treated the program returns to this level,
415: but does not call the error handlers
417: Collective on Comm
419: Synopsis:
420: PetscExceptionTrySyncNorm(MPI_Comm comm,PetscErrorCode routine(....),PetscErrorCode);
422: Level: advanced
424: Notes: This synchronizes the error code across all processes in the communicator IF the code matches PetscErrorCode. The next
425: call with an MPI_Reduce()/MPI_Allreduce() MUST be VecNorm() [We can added VecDot() and maybe others as needed].
427: PETSc must not be configured using the option --with-errorchecking=0 for this to work
429: Note: In general, the outer most try on an exception is the one that will be caught (that is trys down in
430: PETSc code will not usually handle an exception that was issued above). See SNESSolve() for an example
431: of how the local try is ignored if a higher (in the stack) one is also in effect.
433: Concepts: exceptions, exception hanlding
435: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
436: CHKERRQ(), PetscExceptionCaught(), PetscExceptionPush(), PetscExceptionPop(), PetscExceptionTry1()
437: M*/
438: #define PetscExceptionTrySyncNorm(comm,a,b) (PetscExceptionTmp = PetscExceptionPush(b)) ? PetscExceptionTmp : \
439: (PetscExceptionTmp = a , PetscExceptionPop(b),PetscExceptionTrySyncNorm_Private(comm,PetscExceptionTmp,b))
441: #else
443: /*
444: These are defined to be empty for when error checking is turned off, with config/configure.py --with-errorchecking=0
445: */
447: #define SETERRQ(n,s) ;
448: #define SETERRQ1(n,s,a1) ;
449: #define SETERRQ2(n,s,a1,a2) ;
450: #define SETERRQ3(n,s,a1,a2,a3) ;
451: #define SETERRQ4(n,s,a1,a2,a3,a4) ;
452: #define SETERRQ5(n,s,a1,a2,a3,a4,a5) ;
453: #define SETERRQ6(n,s,a1,a2,a3,a4,a5,a6) ;
454: #define SETERRABORT(comm,n,s) ;
456: #define CHKERRQ(n) ;
457: #define CHKERRABORT(comm,n) ;
458: #define CHKERRCONTINUE(n) ;
459: #define CHKMEMQ ;
461: #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
462: #define _
464: #endif
466: #define PetscExceptionPush(a) 0
467: #define PetscExceptionPop(a) 0
468: #define PetscErrorSetCatchable(a,b) 0
469: #define PetscErrorIsCatchable(a) PETSC_FALSE
471: #define PetscExceptionCaught(a,b) PETSC_FALSE
472: #define PetscExceptionValue(a) PETSC_FALSE
473: #define PetscExceptionTry1(a,b) a
474: #define PetscExceptionTrySyncNorm(comm,a,b) a
476: #endif
478: EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
479: EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
480: EXTERN PetscErrorCode PetscTraceBackErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
481: #ifdef PETSC_CLANGUAGE_CXX
482: #include <sstream>
483: EXTERN void PetscTraceBackErrorHandlerCxx(int,const char *,const char *,const char *,PetscErrorCode,int, std::ostringstream&);
484: #endif
485: EXTERN PetscErrorCode PetscIgnoreErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
486: EXTERN PetscErrorCode PetscEmacsClientErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
487: EXTERN PetscErrorCode PetscMPIAbortErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
488: EXTERN PetscErrorCode PetscAbortErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
489: EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
490: EXTERN PetscErrorCode PetscReturnErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
491: EXTERN PetscErrorCode PetscError(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,...) PETSC_PRINTF_FORMAT_CHECK(7,8);
492: EXTERN void PetscErrorCxx(int,const char*,const char*,const char*,PetscErrorCode,int);
493: EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*),void*);
494: EXTERN PetscErrorCode PetscPopErrorHandler(void);
495: EXTERN PetscErrorCode PetscDefaultSignalHandler(int,void*);
496: EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
497: EXTERN PetscErrorCode PetscPopSignalHandler(void);
499: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
500: EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
502: /*
503: Allows the code to build a stack frame as it runs
504: */
505: #if defined(PETSC_USE_DEBUG)
507: #define PETSCSTACKSIZE 15
509: typedef struct {
510: const char *function[PETSCSTACKSIZE];
511: const char *file[PETSCSTACKSIZE];
512: const char *directory[PETSCSTACKSIZE];
513: int line[PETSCSTACKSIZE];
514: int currentsize;
515: } PetscStack;
518: EXTERN PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*);
519: EXTERN PetscErrorCode PetscStackPrint(PetscStack*,FILE* fp);
521: #define PetscStackActive (petscstack != 0)
524: /*MC
526: used for error handling.
528: Synopsis:
531: Usage:
532: .vb
533: int something;
536: .ve
538: Notes:
539: Not available in Fortran
541: Level: developer
543: .seealso: PetscFunctionReturn()
545: .keywords: traceback, error handling
546: M*/
548: {\
549: if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \
550: petscstack->function[petscstack->currentsize] = __FUNCT__; \
551: petscstack->file[petscstack->currentsize] = __FILE__; \
552: petscstack->directory[petscstack->currentsize] = __SDIR__; \
553: petscstack->line[petscstack->currentsize] = __LINE__; \
554: petscstack->currentsize++; \
555: }}
557: #define PetscStackPush(n) \
558: {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \
559: petscstack->function[petscstack->currentsize] = n; \
560: petscstack->file[petscstack->currentsize] = "unknown"; \
561: petscstack->directory[petscstack->currentsize] = "unknown"; \
562: petscstack->line[petscstack->currentsize] = 0; \
563: petscstack->currentsize++; \
564: }}
566: #define PetscStackPop \
567: {if (petscstack && petscstack->currentsize > 0) { \
568: petscstack->currentsize--; \
569: petscstack->function[petscstack->currentsize] = 0; \
570: petscstack->file[petscstack->currentsize] = 0; \
571: petscstack->directory[petscstack->currentsize] = 0; \
572: petscstack->line[petscstack->currentsize] = 0; \
573: }};
575: /*MC
576: PetscFunctionReturn - Last executable line of each PETSc function
577: used for error handling. Replaces return()
579: Synopsis:
580: void return(0);
582: Usage:
583: .vb
584: ....
585: return(0);
586: }
587: .ve
589: Notes:
590: Not available in Fortran
592: Level: developer
596: .keywords: traceback, error handling
597: M*/
598: #define PetscFunctionReturn(a) \
599: {\
600: PetscStackPop; \
601: return(a);}
603: #define PetscFunctionReturnVoid() \
604: {\
605: PetscStackPop; \
606: return;}
609: #else
612: #define PetscFunctionReturn(a) return(a)
613: #define PetscFunctionReturnVoid() return
614: #define PetscStackPop
615: #define PetscStackPush(f)
616: #define PetscStackActive 0
618: #endif
620: EXTERN PetscErrorCode PetscStackCreate(void);
621: EXTERN PetscErrorCode PetscStackView(PetscViewer);
622: EXTERN PetscErrorCode PetscStackDestroy(void);
623: EXTERN PetscErrorCode PetscStackPublish(void);
624: EXTERN PetscErrorCode PetscStackDepublish(void);
628: #endif