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_INCOMP 75 /* two arguments are incompatible */
64: #define PETSC_ERR_ARG_NULL 85 /* argument is null that should not be */
65: #define PETSC_ERR_ARG_UNKNOWN_TYPE 86 /* type name doesn't match any registered type */
66: #define PETSC_ERR_ARG_DOMAIN 87 /* argument is not in domain of function */
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_MAX_VALUE 89 /* this is always the one more than the largest error code */
78: #if defined(PETSC_USE_ERRORCHECKING)
80: /*MC
81: SETERRQ - Macro that is called when an error has been detected,
83: Not Collective
85: Synopsis:
86: PetscErrorCode SETERRQ(PetscErrorCode errorcode,char *message)
89: Input Parameters:
90: + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
91: - message - error message
93: Level: beginner
95: Notes:
96: Once the error handler is called the calling function is then returned from with the given error code.
98: See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
100: In Fortran MPI_Abort() is always called
102: Experienced users can set the error handler with PetscPushErrorHandler().
104: Concepts: error^setting condition
106: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
107: M*/
108: #define SETERRQ(n,s) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);}
110: /*MC
111: SETERRQ1 - Macro that is called when an error has been detected,
113: Not Collective
115: Synopsis:
116: PetscErrorCode SETERRQ1(PetscErrorCode errorcode,char *formatmessage,arg)
119: Input Parameters:
120: + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
121: . message - error message in the printf format
122: - arg - argument (for example an integer, string or double)
124: Level: beginner
126: Notes:
127: Once the error handler is called the calling function is then returned from with the given error code.
129: Experienced users can set the error handler with PetscPushErrorHandler().
131: Concepts: error^setting condition
133: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
134: M*/
135: #define SETERRQ1(n,s,a1) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1);}
137: /*MC
138: SETERRQ2 - Macro that is called when an error has been detected,
140: Not Collective
142: Synopsis:
143: PetscErrorCode SETERRQ2(PetscErrorCode errorcode,char *formatmessage,arg1,arg2)
146: Input Parameters:
147: + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
148: . message - error message in the printf format
149: . arg1 - argument (for example an integer, string or double)
150: - arg2 - argument (for example an integer, string or double)
152: Level: beginner
154: Notes:
155: Once the error handler is called the calling function is then returned from with the given error code.
157: Experienced users can set the error handler with PetscPushErrorHandler().
159: Concepts: error^setting condition
161: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
162: M*/
163: #define SETERRQ2(n,s,a1,a2) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2);}
165: /*MC
166: SETERRQ3 - Macro that is called when an error has been detected,
168: Not Collective
170: Synopsis:
171: PetscErrorCode SETERRQ3(PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3)
174: Input Parameters:
175: + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
176: . message - error message in the printf format
177: . arg1 - argument (for example an integer, string or double)
178: . arg2 - argument (for example an integer, string or double)
179: - arg3 - argument (for example an integer, string or double)
181: Level: beginner
183: Notes:
184: Once the error handler is called the calling function is then returned from with the given error code.
186: There are also versions for 4, 5, 6 and 7 arguments.
188: Experienced users can set the error handler with PetscPushErrorHandler().
190: Concepts: error^setting condition
192: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
193: M*/
194: #define SETERRQ3(n,s,a1,a2,a3) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3);}
196: #define SETERRQ4(n,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4);}
197: #define SETERRQ5(n,s,a1,a2,a3,a4,a5) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5);}
198: #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);}
199: #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);}
200: #define SETERRABORT(comm,n,s) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);MPI_Abort(comm,n);}
202: /*MC
203: CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns
205: Not Collective
207: Synopsis:
208: PetscErrorCode CHKERRQ(PetscErrorCode errorcode)
211: Input Parameters:
212: . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
214: Level: beginner
216: Notes:
217: Once the error handler is called the calling function is then returned from with the given error code.
219: Experienced users can set the error handler with PetscPushErrorHandler().
221: CHKERRQ(n) is fundamentally a macro replacement for
222: if (n) return(PetscError(...,n,...));
224: Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
225: highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
226: it cannot be used in functions which return(void) or any other datatype. In these types of functions,
227: you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
228: if (n) {PetscError(....); return(YourReturnType);}
229: where you may pass back a PETSC_NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
230: MPI_Abort() returned immediately.
232: In Fortran MPI_Abort() is always called
234: Concepts: error^setting condition
236: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
237: M*/
238: #define CHKERRQ(n) if (n) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");}
240: #define CHKERRV(n) if (n) {n = PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");return;}
241: #define CHKERRABORT(comm,n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");MPI_Abort(comm,n);}
242: #define CHKERRCONTINUE(n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");}
244: #define CHKFPQ(f) if (f != f) {SETERRQ(PETSC_ERR_FP, "Invalid value: NaN");}
246: /*MC
247: CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
249: Not Collective
251: Synopsis:
252: CHKMEMQ;
254: Level: beginner
256: Notes:
257: Must run with the option -malloc_debug to enable this option
259: Once the error handler is called the calling function is then returned from with the given error code.
261: By defaults prints location where memory that is corrupted was allocated.
263: Use CHKMEMA for functions that return void
265: Concepts: memory corruption
267: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
268: PetscMallocValidate()
269: M*/
270: #define CHKMEMQ {PetscErrorCode _7_PetscMallocValidate(__LINE__,__FUNCT__,__FILE__,__SDIR__);CHKERRQ(_7_ierr);}
272: #define CHKMEMA {PetscMallocValidate(__LINE__,__FUNCT__,__FILE__,__SDIR__);}
274: #if defined(PETSC_UNDERSCORE_CHKERR)
276: #define _ __g
278: #endif
280: #define PETSC_EXCEPTIONS_MAX 256
286: EXTERN PetscErrorCode PetscExceptionPush(PetscErrorCode);
287: EXTERN PetscErrorCode PetscExceptionPop(PetscErrorCode);
289: EXTERN PetscErrorCode PetscErrorSetCatchable(PetscErrorCode,PetscTruth);
290: EXTERN PetscTruth PetscErrorIsCatchable(PetscErrorCode);
291: /*MC
292: PetscExceptionCaught - Indicates if a specific exception zierr was caught.
294: Not Collective
296: Synopsis:
297: PetscTruth PetscExceptionCaught(PetscErrorCode xierr,PetscErrorCode zierr);
299: Input Parameters:
300: + xierr - error code returned from PetscExceptionTry1() or other PETSc routine
301: - zierr - error code you want it to be
303: Level: advanced
305: Notes:
306: PETSc must not be configured using the option --with-errorchecking=0 for this to work
308: Use PetscExceptionValue() to see if an error code is being "tried"
310: Concepts: exceptions, exception handling
312: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
313: CHKERRQ(), PetscExceptionTry1(), PetscExceptionValue()
314: M*/
315: PETSC_STATIC_INLINE PetscTruth PetscExceptionCaught(PetscErrorCode xierr,PetscErrorCode zierr) {
316: PetscInt i;
317: if (xierr != zierr) return PETSC_FALSE;
318: for (i=0; i<PetscErrorUncatchableCount; i++) {
319: if (PetscErrorUncatchable[i] == zierr) {
320: return PETSC_FALSE;
321: }
322: }
323: return PETSC_TRUE;
324: }
326: /*MC
327: PetscExceptionValue - Indicates if the error code is one that is currently being tried
329: Not Collective
331: Synopsis:
332: PetscTruth PetscExceptionValue(PetscErrorCode xierr);
334: Input Parameters:
335: . xierr - error code
337: Level: developer
339: Notes:
340: PETSc must not be configured using the option --with-errorchecking=0 for this to work
342: Use PetscExceptionCaught() to see if the current error code is EXACTLY the one you want
344: Concepts: exceptions, exception hanlding
346: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
347: CHKERRQ(), PetscExceptionTry1(), PetscExceptionCaught()
348: M*/
349: PETSC_STATIC_INLINE PetscTruth PetscExceptionValue(PetscErrorCode zierr) {
350: PetscInt i;
351: for (i=0; i<PetscExceptionsCount; i++) {
352: if (PetscExceptions[i] == zierr) {
353: return PETSC_TRUE;
354: }
355: }
356: return PETSC_FALSE;
357: }
359: /*MC
360: PetscExceptionTry1 - Runs the routine, causing a particular error code to be treated as an exception,
361: rather than an error. That is if that error code is treated the program returns to this level,
362: but does not call the error handlers
364: Not Collective
366: Synopsis:
367: PetscErrorCode PetscExceptionTry1(PetscErrorCode routine(....),PetscErrorCode);
369: Level: advanced
371: No Fortran Equivalent (see PetscExceptionPush() for Fortran)
373: Notes:
374: PETSc must not be configured using the option --with-errorchecking=0 for this to work
376: Note: In general, the outer most try on an exception is the one that will be caught (that is trys down in
377: PETSc code will not usually handle an exception that was issued above). See SNESSolve() for an example
378: of how the local try is ignored if a higher (in the stack) one is also in effect.
380: Concepts: exceptions, exception hanlding
382: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
383: CHKERRQ(), PetscExceptionCaught(), PetscExceptionPush(), PetscExceptionPop()
384: M*/
386: #define PetscExceptionTry1(a,b) (PetscExceptionTmp = PetscExceptionPush(b)) ? PetscExceptionTmp : (PetscExceptionTmp = a, (PetscExceptionPop(b) || PetscExceptionTmp))
388: /*
389: Used by PetscExceptionTrySync(). Returns zierr on ALL processes in comm iff xierr is zierr on at least one process and zero on all others.
390: */
391: PETSC_STATIC_INLINE PetscErrorCode PetscExceptionTrySync_Private(MPI_Comm comm,PetscErrorCode xierr,PetscErrorCode zierr)
392: {
393: PetscReal in[2],out[2];
396: if (xierr != zierr) return xierr;
398: in[0] = xierr;
399: in[1] = 0.0; /* dummy value */
401: MPI_Allreduce(in,out,2,MPIU_REAL,0,comm); if (ierr) {;}
402: return xierr;
403: }
405: /*MC
406: PetscExceptionTrySyncNorm - Runs the routine, causing a particular error code to be treated as an exception,
407: rather than an error. That is if that error code is treated the program returns to this level,
408: but does not call the error handlers
410: Collective on Comm
412: Synopsis:
413: PetscExceptionTrySyncNorm(MPI_Comm comm,PetscErrorCode routine(....),PetscErrorCode);
415: Level: advanced
417: Notes: This synchronizes the error code across all processes in the communicator IF the code matches PetscErrorCode. The next
418: call with an MPI_Reduce()/MPI_Allreduce() MUST be VecNorm() [We can added VecDot() and maybe others as needed].
420: PETSc must not be configured using the option --with-errorchecking=0 for this to work
422: Note: In general, the outer most try on an exception is the one that will be caught (that is trys down in
423: PETSc code will not usually handle an exception that was issued above). See SNESSolve() for an example
424: of how the local try is ignored if a higher (in the stack) one is also in effect.
426: Concepts: exceptions, exception hanlding
428: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
429: CHKERRQ(), PetscExceptionCaught(), PetscExceptionPush(), PetscExceptionPop(), PetscExceptionTry1()
430: M*/
432: #define PetscExceptionTrySyncNorm(comm,a,b) (PetscExceptionTmp = PetscExceptionPush(b)) ? PetscExceptionTmp : \
433: (PetscExceptionTmp = a , PetscExceptionPop(b),PetscExceptionTrySyncNorm_Private(comm,PetscExceptionTmp,b))
435: #else
437: /*
438: These are defined to be empty for when error checking is turned off, with config/configure.py --with-errorchecking=0
439: */
441: #define SETERRQ(n,s) ;
442: #define SETERRQ1(n,s,a1) ;
443: #define SETERRQ2(n,s,a1,a2) ;
444: #define SETERRQ3(n,s,a1,a2,a3) ;
445: #define SETERRQ4(n,s,a1,a2,a3,a4) ;
446: #define SETERRQ5(n,s,a1,a2,a3,a4,a5) ;
447: #define SETERRQ6(n,s,a1,a2,a3,a4,a5,a6) ;
448: #define SETERRABORT(comm,n,s) ;
450: #define CHKERRQ(n) ;
451: #define CHKERRABORT(comm,n) ;
452: #define CHKERRCONTINUE(n) ;
453: #define CHKFPQ(f) ;
454: #define CHKMEMQ ;
456: #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
457: #define _
459: #endif
461: #define PetscExceptionPush(a) 0
462: #define PetscExceptionPop(a) 0
463: #define PetscErrorSetCatchable(a,b) 0
464: #define PetscErrorIsCatchable(a) PETSC_FALSE
466: #define PetscExceptionCaught(a,b) PETSC_FALSE
467: #define PetscExceptionValue(a) PETSC_FALSE
468: #define PetscExceptionTry1(a,b) a
469: #define PetscExceptionTrySyncNorm(comm,a,b) a
471: #endif
473: EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
474: EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
475: EXTERN PetscErrorCode PetscTraceBackErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
476: EXTERN PetscErrorCode PetscIgnoreErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
477: EXTERN PetscErrorCode PetscEmacsClientErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
478: EXTERN PetscErrorCode PetscMPIAbortErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
479: EXTERN PetscErrorCode PetscAbortErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
480: EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
481: EXTERN PetscErrorCode PetscReturnErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*);
482: EXTERN PetscErrorCode PetscError(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,...) PETSC_PRINTF_FORMAT_CHECK(7,8);
483: EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*),void*);
484: EXTERN PetscErrorCode PetscPopErrorHandler(void);
485: EXTERN PetscErrorCode PetscDefaultSignalHandler(int,void*);
486: EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
487: EXTERN PetscErrorCode PetscPopSignalHandler(void);
489: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
490: EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
492: /*
493: Allows the code to build a stack frame as it runs
494: */
495: #if defined(PETSC_USE_DEBUG)
497: #define PETSCSTACKSIZE 15
499: typedef struct {
500: const char *function[PETSCSTACKSIZE];
501: const char *file[PETSCSTACKSIZE];
502: const char *directory[PETSCSTACKSIZE];
503: int line[PETSCSTACKSIZE];
504: int currentsize;
505: } PetscStack;
508: EXTERN PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*);
509: EXTERN PetscErrorCode PetscStackPrint(PetscStack*,FILE* fp);
511: #define PetscStackActive (petscstack != 0)
514: /*MC
516: used for error handling.
518: Synopsis:
521: Usage:
522: .vb
523: int something;
526: .ve
528: Notes:
529: Not available in Fortran
531: Level: developer
533: .seealso: PetscFunctionReturn()
535: .keywords: traceback, error handling
536: M*/
538: {\
539: if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \
540: petscstack->function[petscstack->currentsize] = __FUNCT__; \
541: petscstack->file[petscstack->currentsize] = __FILE__; \
542: petscstack->directory[petscstack->currentsize] = __SDIR__; \
543: petscstack->line[petscstack->currentsize] = __LINE__; \
544: petscstack->currentsize++; \
545: }}
547: #define PetscStackPush(n) \
548: {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \
549: petscstack->function[petscstack->currentsize] = n; \
550: petscstack->file[petscstack->currentsize] = "unknown"; \
551: petscstack->directory[petscstack->currentsize] = "unknown"; \
552: petscstack->line[petscstack->currentsize] = 0; \
553: petscstack->currentsize++; \
554: }}
556: #define PetscStackPop \
557: {if (petscstack && petscstack->currentsize > 0) { \
558: petscstack->currentsize--; \
559: petscstack->function[petscstack->currentsize] = 0; \
560: petscstack->file[petscstack->currentsize] = 0; \
561: petscstack->directory[petscstack->currentsize] = 0; \
562: petscstack->line[petscstack->currentsize] = 0; \
563: }};
565: /*MC
566: PetscFunctionReturn - Last executable line of each PETSc function
567: used for error handling. Replaces return()
569: Synopsis:
570: void return(0);
572: Usage:
573: .vb
574: ....
575: return(0);
576: }
577: .ve
579: Notes:
580: Not available in Fortran
582: Level: developer
586: .keywords: traceback, error handling
587: M*/
588: #define PetscFunctionReturn(a) \
589: {\
590: PetscStackPop; \
591: return(a);}
593: #define PetscFunctionReturnVoid() \
594: {\
595: PetscStackPop; \
596: return;}
599: #else
602: #define PetscFunctionReturn(a) return(a)
603: #define PetscFunctionReturnVoid() return
604: #define PetscStackPop
605: #define PetscStackPush(f)
606: #define PetscStackActive 0
608: #endif
610: EXTERN PetscErrorCode PetscStackCreate(void);
611: EXTERN PetscErrorCode PetscStackView(PetscViewer);
612: EXTERN PetscErrorCode PetscStackDestroy(void);
613: EXTERN PetscErrorCode PetscStackPublish(void);
614: EXTERN PetscErrorCode PetscStackDepublish(void);
618: #endif