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