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,PetscTruth); 318 EXTERN PetscTruth PETSCSYS_DLLEXPORT PetscErrorIsCatchable(PetscErrorCode); 319 /*MC 320 PetscExceptionCaught - Indicates if a specific exception zierr was caught. 321 322 Synopsis: 323 PetscTruth 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 PetscTruth 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 PetscTruth 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 PetscTruth 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 #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 485 #define _ 486 #define ___ 487 #endif 488 489 #define PetscExceptionPush(a) 0 490 #define PetscExceptionPop(a) 0 491 #define PetscErrorSetCatchable(a,b) 0 492 #define PetscErrorIsCatchable(a) PETSC_FALSE 493 494 #define PetscExceptionCaught(a,b) PETSC_FALSE 495 #define PetscExceptionValue(a) PETSC_FALSE 496 #define PetscExceptionTry1(a,b) a 497 #define PetscExceptionTrySyncNorm(comm,a,b) a 498 499 #endif 500 501 /*E 502 PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers 503 504 Level: advanced 505 506 PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated 507 508 Developer Notes: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandling() 509 510 .seealso: PetscError(), SETERRXX() 511 E*/ 512 typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType; 513 514 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscErrorPrintfInitialize(void); 515 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscErrorMessage(int,const char*[],char **); 516 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 517 #if defined(PETSC_CLANGUAGE_CXX) && !defined(PETSC_USE_EXTERN_CXX) 518 #include <sstream> 519 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscTraceBackErrorHandlerCxx(MPI_Comm,int,const char *,const char *,const char *,PetscErrorCode,PetscErrorType,const char*,void*); 520 #endif 521 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 522 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 523 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 524 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 525 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 526 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 527 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscError(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...) PETSC_PRINTF_FORMAT_CHECK(7,8); 528 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*); 529 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPopErrorHandler(void); 530 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscDefaultSignalHandler(int,void*); 531 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*); 532 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPopSignalHandler(void); 533 534 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 535 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSetFPTrap(PetscFPTrap); 536 537 /* 538 Allows the code to build a stack frame as it runs 539 */ 540 #if defined(PETSC_USE_DEBUG) && !defined(PETSC_USE_PTHREAD) 541 542 #define PETSCSTACKSIZE 64 543 544 typedef struct { 545 const char *function[PETSCSTACKSIZE]; 546 const char *file[PETSCSTACKSIZE]; 547 const char *directory[PETSCSTACKSIZE]; 548 int line[PETSCSTACKSIZE]; 549 int currentsize; 550 } PetscStack; 551 552 extern PETSCSYS_DLLEXPORT PetscStack *petscstack; 553 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStackCopy(PetscStack*,PetscStack*); 554 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStackPrint(PetscStack*,FILE* fp); 555 556 #define PetscStackActive (petscstack != 0) 557 558 /*MC 559 PetscFunctionBegin - First executable line of each PETSc function 560 used for error handling. 561 562 Synopsis: 563 void PetscFunctionBegin; 564 565 Not Collective 566 567 Usage: 568 .vb 569 int something; 570 571 PetscFunctionBegin; 572 .ve 573 574 Notes: 575 Not available in Fortran 576 577 Level: developer 578 579 .seealso: PetscFunctionReturn() 580 581 .keywords: traceback, error handling 582 M*/ 583 #define PetscFunctionBegin \ 584 do { \ 585 if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 586 petscstack->function[petscstack->currentsize] = PETSC_FUNCTION_NAME; \ 587 petscstack->file[petscstack->currentsize] = __FILE__; \ 588 petscstack->directory[petscstack->currentsize] = __SDIR__; \ 589 petscstack->line[petscstack->currentsize] = __LINE__; \ 590 petscstack->currentsize++; \ 591 } \ 592 PetscCheck__FUNCT__(); \ 593 } while (0) 594 595 #define PetscCheck__FUNCT__() do { \ 596 if (strcmp(PETSC_FUNCTION_NAME,__FUNCT__) && strcmp(__FUNCT__,"User provided function")) { \ 597 (*PetscErrorPrintf)("%s%s:%d: __FUNCT__=\"%s\" does not agree with %s=\"%s\"\n",__SDIR__,__FILE__,__LINE__,__FUNCT__,PetscStringize(PETSC_FUNCTION_NAME),PETSC_FUNCTION_NAME); \ 598 } \ 599 } while (0) 600 601 #define PetscStackPush(n) \ 602 do {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 603 petscstack->function[petscstack->currentsize] = n; \ 604 petscstack->file[petscstack->currentsize] = "unknown"; \ 605 petscstack->directory[petscstack->currentsize] = "unknown"; \ 606 petscstack->line[petscstack->currentsize] = 0; \ 607 petscstack->currentsize++; \ 608 } CHKMEMQ;} while (0) 609 610 #define PetscStackPop \ 611 do {CHKMEMQ; if (petscstack && petscstack->currentsize > 0) { \ 612 petscstack->currentsize--; \ 613 petscstack->function[petscstack->currentsize] = 0; \ 614 petscstack->file[petscstack->currentsize] = 0; \ 615 petscstack->directory[petscstack->currentsize] = 0; \ 616 petscstack->line[petscstack->currentsize] = 0; \ 617 }} while (0) 618 619 /*MC 620 PetscFunctionReturn - Last executable line of each PETSc function 621 used for error handling. Replaces return() 622 623 Synopsis: 624 void PetscFunctionReturn(0); 625 626 Not Collective 627 628 Usage: 629 .vb 630 .... 631 PetscFunctionReturn(0); 632 } 633 .ve 634 635 Notes: 636 Not available in Fortran 637 638 Level: developer 639 640 .seealso: PetscFunctionBegin() 641 642 .keywords: traceback, error handling 643 M*/ 644 #define PetscFunctionReturn(a) \ 645 do {\ 646 if (petscstack && petscstack->currentsize > 0) { \ 647 petscstack->currentsize--; \ 648 petscstack->function[petscstack->currentsize] = 0; \ 649 petscstack->file[petscstack->currentsize] = 0; \ 650 petscstack->directory[petscstack->currentsize] = 0; \ 651 petscstack->line[petscstack->currentsize] = 0; \ 652 }\ 653 return(a);} while (0) 654 655 #define PetscFunctionReturnVoid() \ 656 do {\ 657 if (petscstack && petscstack->currentsize > 0) { \ 658 petscstack->currentsize--; \ 659 petscstack->function[petscstack->currentsize] = 0; \ 660 petscstack->file[petscstack->currentsize] = 0; \ 661 petscstack->directory[petscstack->currentsize] = 0; \ 662 petscstack->line[petscstack->currentsize] = 0; \ 663 }\ 664 return;} while (0) 665 666 #else 667 668 #define PetscFunctionBegin 669 #define PetscFunctionReturn(a) return(a) 670 #define PetscFunctionReturnVoid() return 671 #define PetscStackPop CHKMEMQ 672 #define PetscStackPush(f) CHKMEMQ 673 #define PetscStackActive 0 674 675 #endif 676 677 /* 678 PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack. 679 680 Input Parameters: 681 + name - string that gives the name of the function being called 682 - routine - actual call to the routine 683 684 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. 685 686 */ 687 #define PetscStackCall(name,routine) PetscStackPush(name);routine;PetscStackPop; 688 689 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStackCreate(void); 690 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStackView(PetscViewer); 691 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStackDestroy(void); 692 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStackPublish(void); 693 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStackDepublish(void); 694 695 696 PETSC_EXTERN_CXX_END 697 #endif 698