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