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