xref: /petsc/include/petscerror.h (revision efe48dd8cf8b935accbbb9f4bcb20bc83865fa4d)
1 /*
2     Contains all error handling interfaces for PETSc.
3 */
4 #if !defined(__PETSCERROR_H)
5 #define __PETSCERROR_H
6 
7 PETSC_EXTERN_CXX_BEGIN
8 
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 */
17 #if !defined(__INSDIR__)
18 #define __INSDIR__ "unknowndirectory/"
19 #endif
20 
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 */
26 #if !defined(__FUNCT__)
27 #define __FUNCT__ "User provided function"
28 #endif
29 
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.
36 
37 */
38 #define PETSC_ERR_MIN_VALUE        54   /* should always be one less then the smallest value */
39 
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 */
53 
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 */
67 
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 */
72 
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 */
75 
76 #define PETSC_ERR_FLOP_COUNT       90
77 #define PETSC_ERR_NOT_CONVERGED    91  /* solver did not converge */
78 #define PETSC_ERR_MAX_VALUE        92  /* this is always the one more than the largest error code */
79 
80 #define PetscStringizeArg(a) #a
81 #define PetscStringize(a) PetscStringizeArg(a)
82 #define __SDIR__ PetscStringize(__INSDIR__)
83 
84 #if defined(PETSC_USE_ERRORCHECKING)
85 
86 /*MC
87    SETERRQ - Macro that is called when an error has been detected,
88 
89    Synopsis:
90    PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode errorcode,char *message)
91 
92    Not Collective
93 
94    Input Parameters:
95 +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
96 -  message - error message
97 
98   Level: beginner
99 
100    Notes:
101     Once the error handler is called the calling function is then returned from with the given error code.
102 
103     See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
104 
105     In Fortran MPI_Abort() is always called
106 
107     Experienced users can set the error handler with PetscPushErrorHandler().
108 
109    Concepts: error^setting condition
110 
111 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
112 M*/
113 #define SETERRQ(comm,n,s)              return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s)
114 
115 /*MC
116    SETERRQ1 - Macro that is called when an error has been detected,
117 
118    Synopsis:
119    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg)
120 
121    Not Collective
122 
123    Input Parameters:
124 +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
125 .  message - error message in the printf format
126 -  arg - argument (for example an integer, string or double)
127 
128   Level: beginner
129 
130    Notes:
131     Once the error handler is called the calling function is then returned from with the given error code.
132 
133    Experienced users can set the error handler with PetscPushErrorHandler().
134 
135    Concepts: error^setting condition
136 
137 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
138 M*/
139 #define SETERRQ1(comm,n,s,a1)          return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1)
140 
141 /*MC
142    SETERRQ2 - Macro that is called when an error has been detected,
143 
144    Synopsis:
145    PetscErrorCode SETERRQ2(PetscErrorCode errorcode,char *formatmessage,arg1,arg2)
146 
147    Not Collective
148 
149    Input Parameters:
150 +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
151 .  message - error message in the printf format
152 .  arg1 - argument (for example an integer, string or double)
153 -  arg2 - argument (for example an integer, string or double)
154 
155   Level: beginner
156 
157    Notes:
158     Once the error handler is called the calling function is then returned from with the given error code.
159 
160    Experienced users can set the error handler with PetscPushErrorHandler().
161 
162    Concepts: error^setting condition
163 
164 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
165 M*/
166 #define SETERRQ2(comm,n,s,a1,a2)       return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2)
167 
168 /*MC
169    SETERRQ3 - Macro that is called when an error has been detected,
170 
171    Synopsis:
172    PetscErrorCode SETERRQ3(PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3)
173 
174    Not Collective
175 
176    Input Parameters:
177 +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
178 .  message - error message in the printf format
179 .  arg1 - argument (for example an integer, string or double)
180 .  arg2 - argument (for example an integer, string or double)
181 -  arg3 - argument (for example an integer, string or double)
182 
183   Level: beginner
184 
185    Notes:
186     Once the error handler is called the calling function is then returned from with the given error code.
187 
188     There are also versions for 4, 5, 6 and 7 arguments.
189 
190    Experienced users can set the error handler with PetscPushErrorHandler().
191 
192    Concepts: error^setting condition
193 
194 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
195 M*/
196 #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)
197 
198 #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)
199 #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)
200 #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)
201 #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)
202 #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)
203 
204 /*MC
205    CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns
206 
207    Synopsis:
208    PetscErrorCode CHKERRQ(PetscErrorCode errorcode)
209 
210    Not Collective
211 
212    Input Parameters:
213 .  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
214 
215   Level: beginner
216 
217    Notes:
218     Once the error handler is called the calling function is then returned from with the given error code.
219 
220     Experienced users can set the error handler with PetscPushErrorHandler().
221 
222     CHKERRQ(n) is fundamentally a macro replacement for
223          if (n) return(PetscError(...,n,...));
224 
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.
232 
233     In Fortran MPI_Abort() is always called
234 
235    Concepts: error^setting condition
236 
237 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
238 M*/
239 #define CHKERRQ(n)             do {if (PetscUnlikely(n)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");} while (0)
240 
241 #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)
242 #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)
243 #define CHKERRCONTINUE(n)      do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");}} while (0)
244 
245 #ifdef PETSC_CLANGUAGE_CXX
246 
247 /*MC
248    CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
249 
250    Synopsis:
251    void CHKERRXX(PetscErrorCode errorcode)
252 
253    Not Collective
254 
255    Input Parameters:
256 .  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
257 
258   Level: beginner
259 
260    Notes:
261     Once the error handler throws a ??? exception.
262 
263     You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
264     or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
265 
266    Concepts: error^setting condition
267 
268 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
269 M*/
270 #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)
271 
272 #endif
273 
274 /*MC
275    CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
276 
277    Synopsis:
278    CHKMEMQ;
279 
280    Not Collective
281 
282   Level: beginner
283 
284    Notes:
285     Must run with the option -malloc_debug to enable this option
286 
287     Once the error handler is called the calling function is then returned from with the given error code.
288 
289     By defaults prints location where memory that is corrupted was allocated.
290 
291     Use CHKMEMA for functions that return void
292 
293    Concepts: memory corruption
294 
295 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
296           PetscMallocValidate()
297 M*/
298 #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__);CHKERRQ(_7_ierr);} while(0)
299 
300 #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__)
301 
302 #if defined(PETSC_UNDERSCORE_CHKERR)
303 extern  PetscErrorCode __gierr;
304 #define _   __gierr =
305 #define ___  CHKERRQ(__gierr);
306 #endif
307 
308 #define               PETSC_EXCEPTIONS_MAX  256
309 extern PetscErrorCode PetscErrorUncatchable[PETSC_EXCEPTIONS_MAX];
310 extern PetscInt       PetscErrorUncatchableCount;
311 extern PetscErrorCode PetscExceptions[PETSC_EXCEPTIONS_MAX];
312 extern PetscInt       PetscExceptionsCount;
313 
314 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscExceptionPush(PetscErrorCode);
315 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscExceptionPop(PetscErrorCode);
316 
317 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscErrorSetCatchable(PetscErrorCode,PetscBool );
318 EXTERN PetscBool  PETSCSYS_DLLEXPORT PetscErrorIsCatchable(PetscErrorCode);
319 /*MC
320    PetscExceptionCaught - Indicates if a specific exception zierr was caught.
321 
322    Synopsis:
323      PetscBool  PetscExceptionCaught(PetscErrorCode xierr,PetscErrorCode zierr);
324 
325    Not Collective
326 
327   Input Parameters:
328   + xierr - error code returned from PetscExceptionTry1() or other PETSc routine
329   - zierr - error code you want it to be
330 
331   Level: advanced
332 
333    Notes:
334     PETSc must not be configured using the option --with-errorchecking=0 for this to work
335 
336     Use PetscExceptionValue() to see if an error code is being "tried"
337 
338   Concepts: exceptions, exception handling
339 
340 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
341           CHKERRQ(), PetscExceptionTry1(), PetscExceptionValue()
342 M*/
343 PETSC_STATIC_INLINE PetscBool  PetscExceptionCaught(PetscErrorCode xierr,PetscErrorCode zierr)
344 {
345   PetscInt i;
346   if (xierr != zierr) return PETSC_FALSE;
347   for (i=0; i<PetscErrorUncatchableCount; i++) {
348     if (PetscErrorUncatchable[i] == zierr) {
349       return PETSC_FALSE;
350     }
351   }
352   return PETSC_TRUE;
353 }
354 
355 /*MC
356    PetscExceptionValue - Indicates if the error code is one that is currently being tried
357 
358    Synopsis:
359      PetscBool  PetscExceptionValue(PetscErrorCode xierr);
360 
361    Not Collective
362 
363   Input Parameters:
364   . xierr - error code
365 
366   Level: developer
367 
368    Notes:
369     PETSc must not be configured using the option --with-errorchecking=0 for this to work
370 
371     Use PetscExceptionCaught() to see if the current error code is EXACTLY the one you want
372 
373   Concepts: exceptions, exception hanlding
374 
375 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
376           CHKERRQ(), PetscExceptionTry1(), PetscExceptionCaught()
377 M*/
378 PETSC_STATIC_INLINE PetscBool  PetscExceptionValue(PetscErrorCode zierr)
379 {
380   PetscInt i;
381   for (i=0; i<PetscExceptionsCount; i++) {
382     if (PetscExceptions[i] == zierr) {
383       return PETSC_TRUE;
384     }
385   }
386   return PETSC_FALSE;
387 }
388 
389 /*MC
390    PetscExceptionTry1 - Runs the routine, causing a particular error code to be treated as an exception,
391          rather than an error. That is if that error code is treated the program returns to this level,
392          but does not call the error handlers
393 
394    Synopsis:
395      PetscErrorCode PetscExceptionTry1(PetscErrorCode routine(....),PetscErrorCode);
396 
397    Not Collective
398 
399   Level: advanced
400 
401    No Fortran Equivalent (see PetscExceptionPush() for Fortran)
402 
403    Notes:
404     PETSc must not be configured using the option --with-errorchecking=0 for this to work
405 
406   Note: In general, the outer most try on an exception is the one that will be caught (that is trys down in
407         PETSc code will not usually handle an exception that was issued above). See SNESSolve() for an example
408         of how the local try is ignored if a higher (in the stack) one is also in effect.
409 
410   Concepts: exceptions, exception hanlding
411 
412 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
413           CHKERRQ(), PetscExceptionCaught(), PetscExceptionPush(), PetscExceptionPop()
414 M*/
415 extern PetscErrorCode PetscExceptionTmp,PetscExceptionTmp1;
416 #define PetscExceptionTry1(a,b) (PetscExceptionTmp1 = PetscExceptionPush(b)) ? PetscExceptionTmp1 : (PetscExceptionTmp1 = a, (PetscExceptionTmp = PetscExceptionPop(b)) ? PetscExceptionTmp : PetscExceptionTmp1)
417 
418 /*
419    Used by PetscExceptionTrySync(). Returns zierr on ALL processes in comm iff xierr is zierr on at least one process and zero on all others.
420 */
421 PETSC_STATIC_INLINE PetscErrorCode PetscExceptionTrySync_Private(MPI_Comm comm,PetscErrorCode xierr,PetscErrorCode zierr)
422 {
423   PetscReal      in[2],out[2];
424   PetscErrorCode ierr;
425 
426   if (xierr != zierr) return xierr;
427 
428   in[0] = xierr;
429   in[1] = 0.0;   /* dummy value */
430 
431   ierr = MPI_Allreduce(in,out,2,MPIU_REAL,0,comm); if (ierr) {;}
432   return xierr;
433 }
434 
435 /*MC
436    PetscExceptionTrySyncNorm - Runs the routine, causing a particular error code to be treated as an exception,
437          rather than an error. That is if that error code is treated the program returns to this level,
438          but does not call the error handlers
439 
440    Synopsis:
441      PetscExceptionTrySyncNorm(MPI_Comm comm,PetscErrorCode routine(....),PetscErrorCode);
442 
443      Collective on Comm
444 
445   Level: advanced
446 
447    Notes: This synchronizes the error code across all processes in the communicator IF the code matches PetscErrorCode. The next
448      call with an MPI_Reduce()/MPI_Allreduce() MUST be VecNorm() [We can added VecDot() and maybe others as needed].
449 
450     PETSc must not be configured using the option --with-errorchecking=0 for this to work
451 
452   Note: In general, the outer most try on an exception is the one that will be caught (that is trys down in
453         PETSc code will not usually handle an exception that was issued above). See SNESSolve() for an example
454         of how the local try is ignored if a higher (in the stack) one is also in effect.
455 
456   Concepts: exceptions, exception hanlding
457 
458 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
459           CHKERRQ(), PetscExceptionCaught(), PetscExceptionPush(), PetscExceptionPop(), PetscExceptionTry1()
460 M*/
461 #define PetscExceptionTrySyncNorm(comm,a,b) (PetscExceptionTmp = PetscExceptionPush(b)) ? PetscExceptionTmp : \
462                                         (PetscExceptionTmp = a , PetscExceptionPop(b),PetscExceptionTrySyncNorm_Private(comm,PetscExceptionTmp,b))
463 
464 #else
465 
466 /*
467     These are defined to be empty for when error checking is turned off, with ./configure --with-errorchecking=0
468 */
469 
470 #define SETERRQ(c,n,s)
471 #define SETERRQ1(c,n,s,a1)
472 #define SETERRQ2(c,n,s,a1,a2)
473 #define SETERRQ3(c,n,s,a1,a2,a3)
474 #define SETERRQ4(c,n,s,a1,a2,a3,a4)
475 #define SETERRQ5(c,n,s,a1,a2,a3,a4,a5)
476 #define SETERRQ6(c,n,s,a1,a2,a3,a4,a5,a6)
477 #define SETERRABORT(comm,n,s)
478 
479 #define CHKERRQ(n)     ;
480 #define CHKERRABORT(comm,n) ;
481 #define CHKERRCONTINUE(n) ;
482 #define CHKMEMQ        ;
483 
484 #ifdef PETSC_CLANGUAGE_CXX
485 #define CHKERRXX(n) ;
486 #endif
487 
488 #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
489 #define _
490 #define ___
491 #endif
492 
493 #define PetscExceptionPush(a)                0
494 #define PetscExceptionPop(a)                 0
495 #define PetscErrorSetCatchable(a,b)          0
496 #define PetscErrorIsCatchable(a)             PETSC_FALSE
497 
498 #define PetscExceptionCaught(a,b)            PETSC_FALSE
499 #define PetscExceptionValue(a)               PETSC_FALSE
500 #define PetscExceptionTry1(a,b)              a
501 #define PetscExceptionTrySyncNorm(comm,a,b)  a
502 
503 #endif
504 
505 /*E
506   PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
507 
508   Level: advanced
509 
510   PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
511 
512   Developer Notes: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandling()
513 
514 .seealso: PetscError(), SETERRXX()
515 E*/
516 typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
517 
518 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscErrorPrintfInitialize(void);
519 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscErrorMessage(int,const char*[],char **);
520 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
521 #if defined(PETSC_CLANGUAGE_CXX) && !defined(PETSC_USE_EXTERN_CXX)
522 #include <sstream>
523 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscTraceBackErrorHandlerCxx(MPI_Comm,int,const char *,const char *,const char *,PetscErrorCode,PetscErrorType,const char*,void*);
524 #endif
525 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
526 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
527 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
528 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
529 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
530 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
531 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscError(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...) PETSC_PRINTF_FORMAT_CHECK(7,8);
532 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
533 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPopErrorHandler(void);
534 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscDefaultSignalHandler(int,void*);
535 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
536 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPopSignalHandler(void);
537 
538 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
539 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT  PetscSetFPTrap(PetscFPTrap);
540 
541 /*
542       Allows the code to build a stack frame as it runs
543 */
544 #if defined(PETSC_USE_DEBUG) && !defined(PETSC_USE_PTHREAD)
545 
546 #define PETSCSTACKSIZE 64
547 
548 typedef struct  {
549   const char *function[PETSCSTACKSIZE];
550   const char *file[PETSCSTACKSIZE];
551   const char *directory[PETSCSTACKSIZE];
552         int  line[PETSCSTACKSIZE];
553         int currentsize;
554 } PetscStack;
555 
556 extern PETSCSYS_DLLEXPORT PetscStack *petscstack;
557 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT  PetscStackCopy(PetscStack*,PetscStack*);
558 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT  PetscStackPrint(PetscStack*,FILE* fp);
559 
560 #define PetscStackActive (petscstack != 0)
561 
562 /*MC
563    PetscFunctionBegin - First executable line of each PETSc function
564         used for error handling.
565 
566    Synopsis:
567    void PetscFunctionBegin;
568 
569    Not Collective
570 
571    Usage:
572 .vb
573      int something;
574 
575      PetscFunctionBegin;
576 .ve
577 
578    Notes:
579      Not available in Fortran
580 
581    Level: developer
582 
583 .seealso: PetscFunctionReturn()
584 
585 .keywords: traceback, error handling
586 M*/
587 #define PetscFunctionBegin \
588   do {                                                                  \
589     if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {     \
590       petscstack->function[petscstack->currentsize]  = PETSC_FUNCTION_NAME; \
591       petscstack->file[petscstack->currentsize]      = __FILE__;        \
592       petscstack->directory[petscstack->currentsize] = __SDIR__;        \
593       petscstack->line[petscstack->currentsize]      = __LINE__;        \
594       petscstack->currentsize++;                                        \
595     }                                                                   \
596     PetscCheck__FUNCT__();                                              \
597   } while (0)
598 
599 #define PetscCheck__FUNCT__() do { \
600     if (strcmp(PETSC_FUNCTION_NAME,__FUNCT__) && strcmp(__FUNCT__,"User provided function")) { \
601       (*PetscErrorPrintf)("%s%s:%d: __FUNCT__=\"%s\" does not agree with %s=\"%s\"\n",__SDIR__,__FILE__,__LINE__,__FUNCT__,PetscStringize(PETSC_FUNCTION_NAME),PETSC_FUNCTION_NAME); \
602     }                                                                   \
603   } while (0)
604 
605 #define PetscStackPush(n) \
606   do {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
607     petscstack->function[petscstack->currentsize]  = n; \
608     petscstack->file[petscstack->currentsize]      = "unknown"; \
609     petscstack->directory[petscstack->currentsize] = "unknown"; \
610     petscstack->line[petscstack->currentsize]      = 0; \
611     petscstack->currentsize++; \
612   } CHKMEMQ;} while (0)
613 
614 #define PetscStackPop \
615   do {CHKMEMQ; if (petscstack && petscstack->currentsize > 0) {	\
616     petscstack->currentsize--; \
617     petscstack->function[petscstack->currentsize]  = 0; \
618     petscstack->file[petscstack->currentsize]      = 0; \
619     petscstack->directory[petscstack->currentsize] = 0; \
620     petscstack->line[petscstack->currentsize]      = 0; \
621   }} while (0)
622 
623 /*MC
624    PetscFunctionReturn - Last executable line of each PETSc function
625         used for error handling. Replaces return()
626 
627    Synopsis:
628    void PetscFunctionReturn(0);
629 
630    Not Collective
631 
632    Usage:
633 .vb
634     ....
635      PetscFunctionReturn(0);
636    }
637 .ve
638 
639    Notes:
640      Not available in Fortran
641 
642    Level: developer
643 
644 .seealso: PetscFunctionBegin()
645 
646 .keywords: traceback, error handling
647 M*/
648 #define PetscFunctionReturn(a) \
649   do {\
650   if (petscstack && petscstack->currentsize > 0) {	\
651     petscstack->currentsize--; \
652     petscstack->function[petscstack->currentsize]  = 0; \
653     petscstack->file[petscstack->currentsize]      = 0; \
654     petscstack->directory[petscstack->currentsize] = 0; \
655     petscstack->line[petscstack->currentsize]      = 0; \
656   }\
657   return(a);} while (0)
658 
659 #define PetscFunctionReturnVoid() \
660   do {\
661   if (petscstack && petscstack->currentsize > 0) {	\
662     petscstack->currentsize--; \
663     petscstack->function[petscstack->currentsize]  = 0; \
664     petscstack->file[petscstack->currentsize]      = 0; \
665     petscstack->directory[petscstack->currentsize] = 0; \
666     petscstack->line[petscstack->currentsize]      = 0; \
667   }\
668   return;} while (0)
669 
670 #else
671 
672 #define PetscFunctionBegin
673 #define PetscFunctionReturn(a)  return(a)
674 #define PetscFunctionReturnVoid() return
675 #define PetscStackPop     CHKMEMQ
676 #define PetscStackPush(f) CHKMEMQ
677 #define PetscStackActive        0
678 
679 #endif
680 
681 /*
682     PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
683 
684    Input Parameters:
685 +   name - string that gives the name of the function being called
686 -   routine - actual call to the routine
687 
688    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.
689 
690 */
691 #define PetscStackCall(name,routine) PetscStackPush(name);routine;PetscStackPop;
692 
693 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT  PetscStackCreate(void);
694 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT  PetscStackView(PetscViewer);
695 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT  PetscStackDestroy(void);
696 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT  PetscStackPublish(void);
697 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT  PetscStackDepublish(void);
698 
699 
700 PETSC_EXTERN_CXX_END
701 #endif
702