xref: /petsc/include/petscerror.h (revision 84df9cb40eca90ea9b18a456fab7a4ecc7f6c1a4)
1 /*
2     Contains all error handling interfaces for PETSc.
3 */
4 #if !defined(__PETSCERROR_H)
5 #define __PETSCERROR_H
6 
7 #if defined(PETSC_HAVE_STRING_H)
8 #include <string.h> /* for strcmp */
9 #endif
10 
11 PETSC_EXTERN_CXX_BEGIN
12 
13 /*
14    Defines the directory where the compiled source is located; used
15    in printing error messages. Each makefile has an entry
16    LOCDIR	  =  thedirectory
17    and bmake/common_variables includes in CCPPFLAGS -D__SDIR__=${LOCDIR}
18    which is a flag passed to the C/C++ compilers. This declaration below
19    is only needed if some code is compiled without the -D__SDIR__
20 */
21 #if !defined(__INSDIR__)
22 #define __INSDIR__ "unknowndirectory/"
23 #endif
24 
25 /*
26    Defines the function where the compiled source is located; used
27    in printing error messages. This is defined here in case the user
28    does not declare it.
29 */
30 #if !defined(__FUNCT__)
31 #define __FUNCT__ "User provided function"
32 #endif
33 
34 /*
35      These are the generic error codes. These error codes are used
36      many different places in the PETSc source code. The string versions are
37      at src/sys/error/err.c any changes here must also be made there
38      These are also define in include/finclude/petscerror.h any CHANGES here
39      must be also made there.
40 
41 */
42 #define PETSC_ERR_MIN_VALUE        54   /* should always be one less then the smallest value */
43 
44 #define PETSC_ERR_MEM              55   /* unable to allocate requested memory */
45 #define PETSC_ERR_SUP              56   /* no support for requested operation */
46 #define PETSC_ERR_SUP_SYS          57   /* no support for requested operation on this computer system */
47 #define PETSC_ERR_ORDER            58   /* operation done in wrong order */
48 #define PETSC_ERR_SIG              59   /* signal received */
49 #define PETSC_ERR_FP               72   /* floating point exception */
50 #define PETSC_ERR_COR              74   /* corrupted PETSc object */
51 #define PETSC_ERR_LIB              76   /* error in library called by PETSc */
52 #define PETSC_ERR_PLIB             77   /* PETSc library generated inconsistent data */
53 #define PETSC_ERR_MEMC             78   /* memory corruption */
54 #define PETSC_ERR_CONV_FAILED      82   /* iterative method (KSP or SNES) failed */
55 #define PETSC_ERR_USER             83   /* user has not provided needed function */
56 #define PETSC_ERR_SYS              88   /* error in system call */
57 
58 #define PETSC_ERR_ARG_SIZ          60   /* nonconforming object sizes used in operation */
59 #define PETSC_ERR_ARG_IDN          61   /* two arguments not allowed to be the same */
60 #define PETSC_ERR_ARG_WRONG        62   /* wrong argument (but object probably ok) */
61 #define PETSC_ERR_ARG_CORRUPT      64   /* null or corrupted PETSc object as argument */
62 #define PETSC_ERR_ARG_OUTOFRANGE   63   /* input argument, out of range */
63 #define PETSC_ERR_ARG_BADPTR       68   /* invalid pointer argument */
64 #define PETSC_ERR_ARG_NOTSAMETYPE  69   /* two args must be same object type */
65 #define PETSC_ERR_ARG_NOTSAMECOMM  80   /* two args must be same communicators */
66 #define PETSC_ERR_ARG_WRONGSTATE   73   /* object in argument is in wrong state, e.g. unassembled mat */
67 #define PETSC_ERR_ARG_TYPENOTSET   89   /* the type of the object has not yet been set */
68 #define PETSC_ERR_ARG_INCOMP       75   /* two arguments are incompatible */
69 #define PETSC_ERR_ARG_NULL         85   /* argument is null that should not be */
70 #define PETSC_ERR_ARG_UNKNOWN_TYPE 86   /* type name doesn't match any registered type */
71 
72 #define PETSC_ERR_FILE_OPEN        65   /* unable to open file */
73 #define PETSC_ERR_FILE_READ        66   /* unable to read from file */
74 #define PETSC_ERR_FILE_WRITE       67   /* unable to write to file */
75 #define PETSC_ERR_FILE_UNEXPECTED  79   /* unexpected data in file */
76 
77 #define PETSC_ERR_MAT_LU_ZRPVT     71   /* detected a zero pivot during LU factorization */
78 #define PETSC_ERR_MAT_CH_ZRPVT     81   /* detected a zero pivot during Cholesky factorization */
79 
80 #define PETSC_ERR_INT_OVERFLOW     84   /* should always be one less then the smallest value */
81 
82 #define PETSC_ERR_FLOP_COUNT       90
83 #define PETSC_ERR_NOT_CONVERGED    91  /* solver did not converge */
84 #define PETSC_ERR_MAX_VALUE        92  /* this is always the one more than the largest error code */
85 
86 #define PetscStringizeArg(a) #a
87 #define PetscStringize(a) PetscStringizeArg(a)
88 #define __SDIR__ PetscStringize(__INSDIR__)
89 
90 #if defined(PETSC_USE_ERRORCHECKING)
91 
92 /*MC
93    SETERRQ - Macro that is called when an error has been detected,
94 
95    Synopsis:
96    PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode errorcode,char *message)
97 
98    Not Collective
99 
100    Input Parameters:
101 +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
102 -  message - error message
103 
104   Level: beginner
105 
106    Notes:
107     Once the error handler is called the calling function is then returned from with the given error code.
108 
109     See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
110 
111     In Fortran MPI_Abort() is always called
112 
113     Experienced users can set the error handler with PetscPushErrorHandler().
114 
115    Concepts: error^setting condition
116 
117 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
118 M*/
119 #define SETERRQ(comm,n,s)              return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s)
120 
121 /*MC
122    SETERRQ1 - Macro that is called when an error has been detected,
123 
124    Synopsis:
125    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg)
126 
127    Not Collective
128 
129    Input Parameters:
130 +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
131 .  message - error message in the printf format
132 -  arg - argument (for example an integer, string or double)
133 
134   Level: beginner
135 
136    Notes:
137     Once the error handler is called the calling function is then returned from with the given error code.
138 
139    Experienced users can set the error handler with PetscPushErrorHandler().
140 
141    Concepts: error^setting condition
142 
143 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
144 M*/
145 #define SETERRQ1(comm,n,s,a1)          return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1)
146 
147 /*MC
148    SETERRQ2 - Macro that is called when an error has been detected,
149 
150    Synopsis:
151    PetscErrorCode SETERRQ2(PetscErrorCode errorcode,char *formatmessage,arg1,arg2)
152 
153    Not Collective
154 
155    Input Parameters:
156 +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
157 .  message - error message in the printf format
158 .  arg1 - argument (for example an integer, string or double)
159 -  arg2 - argument (for example an integer, string or double)
160 
161   Level: beginner
162 
163    Notes:
164     Once the error handler is called the calling function is then returned from with the given error code.
165 
166    Experienced users can set the error handler with PetscPushErrorHandler().
167 
168    Concepts: error^setting condition
169 
170 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
171 M*/
172 #define SETERRQ2(comm,n,s,a1,a2)       return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2)
173 
174 /*MC
175    SETERRQ3 - Macro that is called when an error has been detected,
176 
177    Synopsis:
178    PetscErrorCode SETERRQ3(PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3)
179 
180    Not Collective
181 
182    Input Parameters:
183 +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
184 .  message - error message in the printf format
185 .  arg1 - argument (for example an integer, string or double)
186 .  arg2 - argument (for example an integer, string or double)
187 -  arg3 - argument (for example an integer, string or double)
188 
189   Level: beginner
190 
191    Notes:
192     Once the error handler is called the calling function is then returned from with the given error code.
193 
194     There are also versions for 4, 5, 6 and 7 arguments.
195 
196    Experienced users can set the error handler with PetscPushErrorHandler().
197 
198    Concepts: error^setting condition
199 
200 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
201 M*/
202 #define SETERRQ3(comm,n,s,a1,a2,a3)    return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3)
203 
204 #define SETERRQ4(comm,n,s,a1,a2,a3,a4) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4)
205 #define SETERRQ5(comm,n,s,a1,a2,a3,a4,a5)       return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5)
206 #define SETERRQ6(comm,n,s,a1,a2,a3,a4,a5,a6)    return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6)
207 #define SETERRQ7(comm,n,s,a1,a2,a3,a4,a5,a6,a7) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7)
208 #define SETERRABORT(comm,n,s)     do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,n);} while (0)
209 
210 /*MC
211    CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns
212 
213    Synopsis:
214    PetscErrorCode CHKERRQ(PetscErrorCode errorcode)
215 
216    Not Collective
217 
218    Input Parameters:
219 .  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
220 
221   Level: beginner
222 
223    Notes:
224     Once the error handler is called the calling function is then returned from with the given error code.
225 
226     Experienced users can set the error handler with PetscPushErrorHandler().
227 
228     CHKERRQ(n) is fundamentally a macro replacement for
229          if (n) return(PetscError(...,n,...));
230 
231     Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
232     highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
233     it cannot be used in functions which return(void) or any other datatype.  In these types of functions,
234     you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
235          if (n) {PetscError(....); return(YourReturnType);}
236     where you may pass back a PETSC_NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
237     MPI_Abort() returned immediately.
238 
239     In Fortran MPI_Abort() is always called
240 
241    Concepts: error^setting condition
242 
243 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
244 M*/
245 #define CHKERRQ(n)             do {if (PetscUnlikely(n)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");} while (0)
246 
247 #define CHKERRV(n)             do {if (PetscUnlikely(n)) {n = PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");return;}} while(0)
248 #define CHKERRABORT(comm,n)    do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");MPI_Abort(comm,n);}} while (0)
249 #define CHKERRCONTINUE(n)      do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");}} while (0)
250 
251 #ifdef PETSC_CLANGUAGE_CXX
252 
253 /*MC
254    CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
255 
256    Synopsis:
257    void CHKERRXX(PetscErrorCode errorcode)
258 
259    Not Collective
260 
261    Input Parameters:
262 .  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
263 
264   Level: beginner
265 
266    Notes:
267     Once the error handler throws a ??? exception.
268 
269     You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
270     or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
271 
272    Concepts: error^setting condition
273 
274 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
275 M*/
276 #define CHKERRXX(n)            do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_IN_CXX,0);}} while(0)
277 
278 #endif
279 
280 /*MC
281    CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
282 
283    Synopsis:
284    CHKMEMQ;
285 
286    Not Collective
287 
288   Level: beginner
289 
290    Notes:
291     Must run with the option -malloc_debug to enable this option
292 
293     Once the error handler is called the calling function is then returned from with the given error code.
294 
295     By defaults prints location where memory that is corrupted was allocated.
296 
297     Use CHKMEMA for functions that return void
298 
299    Concepts: memory corruption
300 
301 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
302           PetscMallocValidate()
303 M*/
304 #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__);CHKERRQ(_7_ierr);} while(0)
305 
306 #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__)
307 
308 #if defined(PETSC_UNDERSCORE_CHKERR)
309 extern  PetscErrorCode __gierr;
310 #define _   __gierr =
311 #define ___  CHKERRQ(__gierr);
312 #endif
313 
314 #else /* PETSC_USE_ERRORCHECKING */
315 
316 /*
317     These are defined to be empty for when error checking is turned off, with ./configure --with-errorchecking=0
318 */
319 
320 #define SETERRQ(c,n,s)
321 #define SETERRQ1(c,n,s,a1)
322 #define SETERRQ2(c,n,s,a1,a2)
323 #define SETERRQ3(c,n,s,a1,a2,a3)
324 #define SETERRQ4(c,n,s,a1,a2,a3,a4)
325 #define SETERRQ5(c,n,s,a1,a2,a3,a4,a5)
326 #define SETERRQ6(c,n,s,a1,a2,a3,a4,a5,a6)
327 #define SETERRABORT(comm,n,s)
328 
329 #define CHKERRQ(n)     ;
330 #define CHKERRABORT(comm,n) ;
331 #define CHKERRCONTINUE(n) ;
332 #define CHKMEMQ        ;
333 
334 #ifdef PETSC_CLANGUAGE_CXX
335 #define CHKERRXX(n) ;
336 #endif
337 
338 #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
339 #define _
340 #define ___
341 #endif
342 
343 #endif /* PETSC_USE_ERRORCHECKING */
344 
345 /*E
346   PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
347 
348   Level: advanced
349 
350   PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
351 
352   Developer Notes: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandling()
353 
354 .seealso: PetscError(), SETERRXX()
355 E*/
356 typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
357 
358 extern PetscErrorCode  PetscErrorPrintfInitialize(void);
359 extern PetscErrorCode  PetscErrorMessage(int,const char*[],char **);
360 extern PetscErrorCode  PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
361 #if defined(PETSC_CLANGUAGE_CXX) && !defined(PETSC_USE_EXTERN_CXX)
362 #include <sstream>
363 extern PetscErrorCode  PetscTraceBackErrorHandlerCxx(MPI_Comm,int,const char *,const char *,const char *,PetscErrorCode,PetscErrorType,const char*,void*);
364 #endif
365 extern PetscErrorCode  PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
366 extern PetscErrorCode  PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
367 extern PetscErrorCode  PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
368 extern PetscErrorCode  PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
369 extern PetscErrorCode  PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
370 extern PetscErrorCode  PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
371 extern PetscErrorCode  PetscError(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);
372 extern PetscErrorCode  PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
373 extern PetscErrorCode  PetscPopErrorHandler(void);
374 extern PetscErrorCode  PetscDefaultSignalHandler(int,void*);
375 extern PetscErrorCode  PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
376 extern PetscErrorCode  PetscPopSignalHandler(void);
377 
378 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
379 extern PetscErrorCode   PetscSetFPTrap(PetscFPTrap);
380 
381 /*
382       Allows the code to build a stack frame as it runs
383 */
384 #if defined(PETSC_USE_DEBUG) && !defined(PETSC_USE_PTHREAD)
385 
386 #define PETSCSTACKSIZE 64
387 
388 typedef struct  {
389   const char *function[PETSCSTACKSIZE];
390   const char *file[PETSCSTACKSIZE];
391   const char *directory[PETSCSTACKSIZE];
392         int  line[PETSCSTACKSIZE];
393         int currentsize;
394 } PetscStack;
395 
396 extern  PetscStack *petscstack;
397 extern PetscErrorCode   PetscStackCopy(PetscStack*,PetscStack*);
398 extern PetscErrorCode   PetscStackPrint(PetscStack*,FILE* fp);
399 
400 #define PetscStackActive (petscstack != 0)
401 
402 /*MC
403    PetscFunctionBegin - First executable line of each PETSc function
404         used for error handling.
405 
406    Synopsis:
407    void PetscFunctionBegin;
408 
409    Not Collective
410 
411    Usage:
412 .vb
413      int something;
414 
415      PetscFunctionBegin;
416 .ve
417 
418    Notes:
419      Not available in Fortran
420 
421    Level: developer
422 
423 .seealso: PetscFunctionReturn()
424 
425 .keywords: traceback, error handling
426 M*/
427 #define PetscFunctionBegin \
428   do {                                                                  \
429     if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {     \
430       petscstack->function[petscstack->currentsize]  = PETSC_FUNCTION_NAME; \
431       petscstack->file[petscstack->currentsize]      = __FILE__;        \
432       petscstack->directory[petscstack->currentsize] = __SDIR__;        \
433       petscstack->line[petscstack->currentsize]      = __LINE__;        \
434       petscstack->currentsize++;                                        \
435     }                                                                   \
436     PetscCheck__FUNCT__();                                              \
437   } while (0)
438 
439 #define PetscCheck__FUNCT__() do { \
440     if (strcmp(PETSC_FUNCTION_NAME,__FUNCT__) && strcmp(__FUNCT__,"User provided function")) { \
441       (*PetscErrorPrintf)("%s%s:%d: __FUNCT__=\"%s\" does not agree with %s=\"%s\"\n",__SDIR__,__FILE__,__LINE__,__FUNCT__,PetscStringize(PETSC_FUNCTION_NAME),PETSC_FUNCTION_NAME); \
442     }                                                                   \
443   } while (0)
444 
445 #define PetscStackPush(n) \
446   do {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
447     petscstack->function[petscstack->currentsize]  = n; \
448     petscstack->file[petscstack->currentsize]      = "unknown"; \
449     petscstack->directory[petscstack->currentsize] = "unknown"; \
450     petscstack->line[petscstack->currentsize]      = 0; \
451     petscstack->currentsize++; \
452   } CHKMEMQ;} while (0)
453 
454 #define PetscStackPop \
455   do {CHKMEMQ; if (petscstack && petscstack->currentsize > 0) {	\
456     petscstack->currentsize--; \
457     petscstack->function[petscstack->currentsize]  = 0; \
458     petscstack->file[petscstack->currentsize]      = 0; \
459     petscstack->directory[petscstack->currentsize] = 0; \
460     petscstack->line[petscstack->currentsize]      = 0; \
461   }} while (0)
462 
463 /*MC
464    PetscFunctionReturn - Last executable line of each PETSc function
465         used for error handling. Replaces return()
466 
467    Synopsis:
468    void PetscFunctionReturn(0);
469 
470    Not Collective
471 
472    Usage:
473 .vb
474     ....
475      PetscFunctionReturn(0);
476    }
477 .ve
478 
479    Notes:
480      Not available in Fortran
481 
482    Level: developer
483 
484 .seealso: PetscFunctionBegin()
485 
486 .keywords: traceback, error handling
487 M*/
488 #define PetscFunctionReturn(a) \
489   do {\
490   if (petscstack && petscstack->currentsize > 0) {	\
491     petscstack->currentsize--; \
492     petscstack->function[petscstack->currentsize]  = 0; \
493     petscstack->file[petscstack->currentsize]      = 0; \
494     petscstack->directory[petscstack->currentsize] = 0; \
495     petscstack->line[petscstack->currentsize]      = 0; \
496   }\
497   return(a);} while (0)
498 
499 #define PetscFunctionReturnVoid() \
500   do {\
501   if (petscstack && petscstack->currentsize > 0) {	\
502     petscstack->currentsize--; \
503     petscstack->function[petscstack->currentsize]  = 0; \
504     petscstack->file[petscstack->currentsize]      = 0; \
505     petscstack->directory[petscstack->currentsize] = 0; \
506     petscstack->line[petscstack->currentsize]      = 0; \
507   }\
508   return;} while (0)
509 
510 #else
511 
512 #define PetscFunctionBegin
513 #define PetscFunctionReturn(a)  return(a)
514 #define PetscFunctionReturnVoid() return
515 #define PetscStackPop     CHKMEMQ
516 #define PetscStackPush(f) CHKMEMQ
517 #define PetscStackActive        0
518 
519 #endif
520 
521 /*
522     PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
523 
524    Input Parameters:
525 +   name - string that gives the name of the function being called
526 -   routine - actual call to the routine
527 
528    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.
529 
530 */
531 #define PetscStackCall(name,routine) PetscStackPush(name);routine;PetscStackPop;
532 
533 extern PetscErrorCode   PetscStackCreate(void);
534 extern PetscErrorCode   PetscStackView(PetscViewer);
535 extern PetscErrorCode   PetscStackDestroy(void);
536 extern PetscErrorCode   PetscStackPublish(void);
537 extern PetscErrorCode   PetscStackDepublish(void);
538 
539 
540 PETSC_EXTERN_CXX_END
541 #endif
542