1 /* 2 Contains all error handling interfaces for PETSc. 3 */ 4 #if !defined(PETSCERROR_H) 5 #define PETSCERROR_H 6 7 #include <petscmacros.h> 8 #include <petscsystypes.h> 9 10 /* 11 These are the generic error codes. These error codes are used 12 many different places in the PETSc source code. The string versions are 13 at src/sys/error/err.c any changes here must also be made there 14 These are also define in src/sys/f90-mod/petscerror.h any CHANGES here 15 must be also made there. 16 17 */ 18 #define PETSC_ERR_MIN_VALUE 54 /* should always be one less then the smallest value */ 19 20 #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 21 #define PETSC_ERR_SUP 56 /* no support for requested operation */ 22 #define PETSC_ERR_SUP_SYS 57 /* no support for requested operation on this computer system */ 23 #define PETSC_ERR_ORDER 58 /* operation done in wrong order */ 24 #define PETSC_ERR_SIG 59 /* signal received */ 25 #define PETSC_ERR_FP 72 /* floating point exception */ 26 #define PETSC_ERR_COR 74 /* corrupted PETSc object */ 27 #define PETSC_ERR_LIB 76 /* error in library called by PETSc */ 28 #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */ 29 #define PETSC_ERR_MEMC 78 /* memory corruption */ 30 #define PETSC_ERR_CONV_FAILED 82 /* iterative method (KSP or SNES) failed */ 31 #define PETSC_ERR_USER 83 /* user has not provided needed function */ 32 #define PETSC_ERR_SYS 88 /* error in system call */ 33 #define PETSC_ERR_POINTER 70 /* pointer does not point to valid address */ 34 #define PETSC_ERR_MPI_LIB_INCOMP 87 /* MPI library at runtime is not compatible with MPI user compiled with */ 35 36 #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */ 37 #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */ 38 #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */ 39 #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */ 40 #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */ 41 #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */ 42 #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */ 43 #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */ 44 #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */ 45 #define PETSC_ERR_ARG_TYPENOTSET 89 /* the type of the object has not yet been set */ 46 #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ 47 #define PETSC_ERR_ARG_NULL 85 /* argument is null that should not be */ 48 #define PETSC_ERR_ARG_UNKNOWN_TYPE 86 /* type name doesn't match any registered type */ 49 50 #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ 51 #define PETSC_ERR_FILE_READ 66 /* unable to read from file */ 52 #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */ 53 #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */ 54 55 #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */ 56 #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */ 57 58 #define PETSC_ERR_INT_OVERFLOW 84 59 60 #define PETSC_ERR_FLOP_COUNT 90 61 #define PETSC_ERR_NOT_CONVERGED 91 /* solver did not converge */ 62 #define PETSC_ERR_MISSING_FACTOR 92 /* MatGetFactor() failed */ 63 #define PETSC_ERR_OPT_OVERWRITE 93 /* attempted to over write options which should not be changed */ 64 #define PETSC_ERR_WRONG_MPI_SIZE 94 /* example/application run with number of MPI ranks it does not support */ 65 #define PETSC_ERR_USER_INPUT 95 /* missing or incorrect user input */ 66 #define PETSC_ERR_GPU_RESOURCE 96 /* unable to load a GPU resource, for example cuBLAS */ 67 #define PETSC_ERR_GPU 97 /* An error from a GPU call, this may be due to lack of resources on the GPU or a true error in the call */ 68 #define PETSC_ERR_MPI 98 /* general MPI error */ 69 #define PETSC_ERR_MAX_VALUE 99 /* this is always the one more than the largest error code */ 70 71 #define SETERRQ1(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 72 #define SETERRQ2(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 73 #define SETERRQ3(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 74 #define SETERRQ4(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 75 #define SETERRQ5(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 76 #define SETERRQ6(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 77 #define SETERRQ7(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 78 #define SETERRQ8(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 79 #define SETERRQ9(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 80 81 /*MC 82 SETERRQ - Macro to be called when an error has been detected, 83 84 Synopsis: 85 #include <petscsys.h> 86 PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message,...) 87 88 Collective 89 90 Input Parameters: 91 + comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error 92 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 93 - message - error message 94 95 Level: beginner 96 97 Notes: 98 Once the error handler is called the calling function is then returned from with the given error code. 99 100 Experienced users can set the error handler with PetscPushErrorHandler(). 101 102 Fortran Notes: 103 SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the 104 Fortran main program. 105 106 .seealso: PetscCheck(), PetscAssert(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), 107 PetscError(), PetscCall(), CHKMEMQ, CHKERRA(), PetscCallMPI() 108 M*/ 109 #define SETERRQ(comm,ierr,...) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,__VA_ARGS__) 110 111 /* 112 Returned from PETSc functions that are called from MPI, such as related to attributes 113 Do not confuse PETSC_MPI_ERROR_CODE and PETSC_ERR_MPI, the first is registered with MPI and returned to MPI as 114 an error code, the latter is a regular PETSc error code passed within PETSc code indicating an error was detected in an MPI call. 115 */ 116 PETSC_EXTERN PetscMPIInt PETSC_MPI_ERROR_CLASS; 117 PETSC_EXTERN PetscMPIInt PETSC_MPI_ERROR_CODE; 118 119 /*MC 120 SETERRMPI - Macro to be called when an error has been detected within an MPI callback function 121 122 Synopsis: 123 #include <petscsys.h> 124 PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message,...) 125 126 Collective 127 128 Input Parameters: 129 + comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error 130 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 131 - message - error message 132 133 Level: developer 134 135 Notes: 136 This macro is FOR USE IN MPI CALLBACK FUNCTIONS ONLY, such as those passed to MPI_Comm_create_keyval(). It always returns the error code PETSC_MPI_ERROR_CODE 137 which is registered with MPI_Add_error_code() when PETSc is initialized. 138 139 .seealso: SETERRQ(), PetscCall(), PetscCallMPI(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKMEMQ 140 M*/ 141 #define SETERRMPI(comm,ierr,...) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,__VA_ARGS__),PETSC_MPI_ERROR_CODE) 142 143 /*MC 144 SETERRA - Fortran-only macro that can be called when an error has been detected from the main program 145 146 Synopsis: 147 #include <petscsys.h> 148 PetscErrorCode SETERRA(MPI_Comm comm,PetscErrorCode ierr,char *message) 149 150 Collective 151 152 Input Parameters: 153 + comm - A communicator, so that the error can be collective 154 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 155 - message - error message in the printf format 156 157 Level: beginner 158 159 Notes: 160 This should only be used with Fortran. With C/C++, use SETERRQ(). 161 162 Fortran Notes: 163 SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the 164 Fortran main program. 165 166 .seealso: SETERRQ(), SETERRABORT(), PetscCall(), CHKERRA(), PetscCallAbort() 167 M*/ 168 169 /*MC 170 SETERRABORT - Macro that can be called when an error has been detected, 171 172 Synopsis: 173 #include <petscsys.h> 174 PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message,...) 175 176 Collective 177 178 Input Parameters: 179 + comm - A communicator, so that the error can be collective 180 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 181 - message - error message in the printf format 182 183 Level: beginner 184 185 Notes: 186 This function just calls MPI_Abort(). 187 188 .seealso: SETERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), PetscCall(), CHKMEMQ 189 M*/ 190 #define SETERRABORT(comm,ierr,...) do { \ 191 PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,__VA_ARGS__); \ 192 MPI_Abort(comm,ierr); \ 193 } while (0) 194 195 /*MC 196 PetscCheck - Check that a particular condition is true 197 198 Synopsis: 199 #include <petscerror.h> 200 void PetscCheck(bool cond, MPI_Comm comm, PetscErrorCode ierr, const char *message, ...) 201 202 Collective 203 204 Input Parameters: 205 + cond - The boolean condition 206 . comm - The communicator on which the check can be collective on 207 . ierr - A nonzero error code, see include/petscerror.h for the complete list 208 - message - Error message in printf format 209 210 Notes: 211 Enabled in both optimized and debug builds. 212 213 Calls SETERRQ() if the assertion fails, so can only be called from functions returning a 214 PetscErrorCode (or equivalent type after conversion). 215 216 Level: beginner 217 218 .seealso: PetscAssert(), SETERRQ(), PetscError(), PetscCall() 219 M*/ 220 #define PetscCheck(cond,comm,ierr,...) if (PetscUnlikely(!(cond))) SETERRQ(comm,ierr,__VA_ARGS__) 221 222 /*MC 223 PetscCheckFalse - Check that a particular condition is false 224 225 Synopsis: 226 #include <petscerror.h> 227 void PetscCheckFalse(bool cond, MPI_Comm comm, PetscErrorCode ierr, const char *message, ...) 228 229 Collective 230 231 Input Parameters: 232 + cond - The boolean condition 233 . comm - The communicator on which the check can be collective on 234 . ierr - A nonzero error code, see include/petscerror.h for the complete list 235 - message - Error message in printf format 236 237 Notes: 238 Invert your boolean condition and use PetscCheck() instead. This macro is a temporary stopgap 239 to converting to PetscCheck() and is subject to removal without deprecation in a future 240 release. 241 242 Level: deprecated 243 244 .seealso: PetscCheck() 245 M*/ 246 #define PetscCheckFalse(cond,comm,ierr,...) PetscCheck(!(cond),comm,ierr,__VA_ARGS__) 247 248 /*MC 249 PetscAssert - Assert that a particular condition is true 250 251 Synopsis: 252 #include <petscerror.h> 253 void PetscAssert(bool cond, MPI_Comm comm, PetscErrorCode ierr, const char *message, ...) 254 255 Collective 256 257 Input Parameters: 258 + cond - The boolean condition 259 . comm - The communicator on which the check can be collective on 260 . ierr - A nonzero error code, see include/petscerror.h for the complete list 261 - message - Error message in printf format 262 263 Notes: 264 Enabled only in debug builds. Note that any arguments to this macros are still visible to the 265 compiler optimized builds (so must still contain valid code) but are guaranteed to not be 266 executed. 267 268 See PetscCheck() for usage and behaviour. 269 270 Level: beginner 271 272 .seealso: PetscCheck(), SETERRQ(), PetscError() 273 M*/ 274 #define PetscAssert(cond,comm,ierr,...) if (PetscUnlikelyDebug(!(cond))) SETERRQ(comm,ierr,__VA_ARGS__) 275 276 /*MC 277 PetscCall - Checks error code returned from a PETSc function, if non-zero it calls the error 278 handler and and returns from the current function. 279 280 Synopsis: 281 #include <petscerror.h> 282 void PetscCall(PetscErrorCode ierr) 283 284 Not Collective 285 286 Input Parameter: 287 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 288 289 Notes: 290 Once the error handler is called the calling function is then returned from with the given 291 error code. Experienced users can set the error handler with PetscPushErrorHandler(). 292 293 PetscCall(ierr) is fundamentally a macro replacement for 294 .vb 295 if (ierr) return PetscError(...,ierr,...); 296 .ve 297 298 PetscCall() cannot be used in functions returning a datatype not convertable to 299 PetscErrorCode. For example, PetscCall() may not be used in functions returning void, use 300 PetscCallVoid() in this case. 301 302 Fortran Notes: 303 PetscCall() may be called from Fortran subroutines but CHKERRA() must be called from the 304 Fortran main program. 305 306 Example Usage: 307 .vb 308 PetscCall(PetscInitiailize(...)); // OK to call even when PETSc is not yet initialized! 309 310 extern int foo(int); 311 312 PetscCall(foo(1)); // OK if int is convertable to PetscErrorCode 313 314 struct my_struct 315 { 316 void *data; 317 } my_complex_type; 318 319 struct my_struct bar(void) 320 { 321 PetscCall(foo(15)); // ERROR PetscErrorCode not convertable to struct my_struct! 322 } 323 324 PetscCall(bar()) // ERROR input not convertable to PetscErrorCode 325 .ve 326 327 Level: beginner 328 329 .seealso: SETERRQ(), PetscCheck(), PetscAssert(), PetscTraceBackErrorHandler(), 330 PetscPushErrorHandler(), PetscError(), CHKMEMQ, CHKERRA() 331 M*/ 332 #if defined(PETSC_CLANG_STATIC_ANALYZER) 333 void PetscCall(PetscErrorCode); 334 void PetscCallVoid(PetscErrorCode); 335 #else 336 #define PetscCall(...) do { \ 337 PetscErrorCode ierr_q_ = __VA_ARGS__; \ 338 if (PetscUnlikely(ierr_q_)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr_q_,PETSC_ERROR_REPEAT," "); \ 339 } while (0) 340 #define PetscCallVoid(...) do { \ 341 PetscErrorCode ierr_void_ = __VA_ARGS__; \ 342 if (PetscUnlikely(ierr_void_)) { \ 343 (void)PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr_void_,PETSC_ERROR_REPEAT," "); \ 344 return; \ 345 } \ 346 } while (0) 347 #endif 348 349 /*MC 350 CHKERRQ - Checks error code returned from PETSc function 351 352 Synopsis: 353 #include <petscsys.h> 354 void CHKERRQ(PetscErrorCode ierr) 355 356 Not Collective 357 358 Input Parameters: 359 . ierr - nonzero error code 360 361 Notes: 362 Deprecated in favor of PetscCall(). This routine behaves identically to it. 363 364 Level: deprecated 365 366 .seealso: PetscCall() 367 M*/ 368 #define CHKERRQ(...) PetscCall(__VA_ARGS__) 369 #define CHKERRV(...) PetscCallVoid(__VA_ARGS__) 370 371 /*MC 372 PetscCallMPI - Checks error code returned from MPI calls, if non-zero it calls the error 373 handler and then returns 374 375 Synopsis: 376 #include <petscerror.h> 377 void PetscCallMPI(PetscErrorCode ierr) 378 379 Not Collective 380 381 Input Parameters: 382 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 383 384 Notes: 385 Always returns the error code PETSC_ERR_MPI; the MPI error code and string are embedded in 386 the string error message. Do not use this to call any other routines (for example PETSc 387 routines), it should only be used for direct MPI calls. Due to limitations of the 388 preprocessor this can unfortunately not easily be enforced, so the user should take care to 389 check this themselves. 390 391 Example Usage: 392 .vb 393 PetscCallMPI(MPI_Comm_size(...)); // OK, calling MPI function 394 395 PetscCallMPI(PetscFunction(...)); // ERROR, use PetscCall() instead! 396 .ve 397 398 Level: beginner 399 400 .seealso: SETERRMPI(), PetscCall(), SETERRQ(), SETERRABORT(), PetscCallAbort(), 401 PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKMEMQ 402 M*/ 403 #if defined(PETSC_CLANG_STATIC_ANALYZER) 404 void PetscCallMPI(PetscErrorCode); 405 #else 406 #define PetscCallMPI(...) do { \ 407 PetscMPIInt _7_errorcode = __VA_ARGS__; \ 408 if (PetscUnlikely(_7_errorcode)) { \ 409 char _7_errorstring[MPI_MAX_ERROR_STRING]; \ 410 PetscMPIInt _7_resultlen; \ 411 MPI_Error_string(_7_errorcode,(char*)_7_errorstring,&_7_resultlen); \ 412 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MPI,"MPI error %d %s Ignore the following value %d",(int)_7_errorcode,_7_errorstring,_7_resultlen); \ 413 } \ 414 } while (0) 415 #endif 416 417 /*MC 418 CHKERRMPI - Checks error code returned from MPI calls, if non-zero it calls the error 419 handler and then returns 420 421 Synopsis: 422 #include <petscerror.h> 423 void CHKERRMPI(PetscErrorCode ierr) 424 425 Not Collective 426 427 Input Parameter: 428 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 429 430 Notes: 431 Deprecated in favor of PetscCallMPI(). This routine behaves identically to it. 432 433 Level: deprecated 434 435 .seealso: PetscCallMPI() 436 M*/ 437 #define CHKERRMPI(...) PetscCallMPI(__VA_ARGS__) 438 439 /*MC 440 PetscCallAbort - Checks error code returned from PETSc function, if non-zero it aborts immediately 441 442 Synopsis: 443 #include <petscerror.h> 444 void PetscCallAbort(MPI_Comm comm, PetscErrorCode ierr) 445 446 Collective on comm 447 448 Input Parameters: 449 + comm - the MPI communicator on which to abort 450 - ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 451 452 Notes: 453 This macro has identical type and usage semantics to PetscCall() with the important caveat 454 that this macro does not return. Instead, if ierr is nonzero it calls the PETSc error handler 455 and then immediately calls MPI_Abort(). It can therefore be used anywhere. 456 457 As per MPI_Abort semantics the communicator passed must be valid, although there is currently 458 no attempt made at handling any potential errors from MPI_Abort(). Note that while 459 MPI_Abort() is required to terminate only those processes which reside on comm, it is often 460 the case that MPI_Abort() terminates *all* processes. 461 462 Example Usage: 463 .vb 464 PetscErrorCode boom(void) { return PETSC_ERR_MEM; } 465 466 void foo(void) 467 { 468 PetscCallAbort(PETSC_COMM_WORLD,boom()); // OK, does not return a type 469 } 470 471 double bar(void) 472 { 473 PetscCallAbort(PETSC_COMM_WORLD,boom()); // OK, does not return a type 474 } 475 476 PetscCallAbort(MPI_COMM_NULL,boom()); // ERROR, communicator should be valid 477 478 struct baz 479 { 480 baz() 481 { 482 PetscCallAbort(PETSC_COMM_SELF,boom()); // OK 483 } 484 485 ~baz() 486 { 487 PetscCallAbort(PETSC_COMM_SELF,boom()); // OK (in fact the only way to handle PETSc errors) 488 } 489 }; 490 .ve 491 492 Level: intermediate 493 494 .seealso: SETERRABORT(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), 495 SETERRQ(), CHKMEMQ, PetscCallMPI() 496 M*/ 497 #if defined(PETSC_CLANG_STATIC_ANALYZER) 498 void PetscCallAbort(MPI_Comm,PetscErrorCode); 499 void PetscCallContinue(PetscErrorCode); 500 #else 501 #define PetscCallAbort(comm,...) do { \ 502 PetscErrorCode ierr_abort_ = __VA_ARGS__; \ 503 if (PetscUnlikely(ierr_abort_)) { \ 504 PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr_abort_,PETSC_ERROR_REPEAT," "); \ 505 MPI_Abort(comm,ierr_abort_); \ 506 } \ 507 } while (0) 508 #define PetscCallContinue(...) do { \ 509 PetscErrorCode ierr_continue_ = __VA_ARGS__; \ 510 if (PetscUnlikely(ierr_continue_)) PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr_continue_,PETSC_ERROR_REPEAT," "); \ 511 } while (0) 512 #endif 513 514 /*MC 515 CHKERRABORT - Checks error code returned from PETSc function. If non-zero it aborts immediately. 516 517 Synopsis: 518 #include <petscerror.h> 519 void CHKERRABORT(MPI_Comm comm, PetscErrorCode ierr) 520 521 Not Collective 522 523 Input Parameters: 524 + comm - the MPI communicator 525 - ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 526 527 Notes: 528 Deprecated in favor of PetscCallAbort(). This routine behaves identically to it. 529 530 Level: deprecated 531 532 .seealso: PetscCallAbort() 533 M*/ 534 #define CHKERRABORT(comm,...) PetscCallAbort(comm,__VA_ARGS__) 535 #define CHKERRCONTINUE(...) PetscCallContinue(__VA_ARGS__) 536 537 /*MC 538 CHKERRA - Fortran-only replacement for PetscCall in the main program, which aborts immediately 539 540 Synopsis: 541 #include <petscsys.h> 542 PetscErrorCode CHKERRA(PetscErrorCode ierr) 543 544 Not Collective 545 546 Input Parameters: 547 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 548 549 Level: beginner 550 551 Notes: 552 This should only be used with Fortran. With C/C++, use PetscCall() in normal usage, 553 or PetscCallAbort() if wanting to abort immediately on error. 554 555 Fortran Notes: 556 PetscCall() may be called from Fortran subroutines but CHKERRA() must be called from the 557 Fortran main program. 558 559 .seealso: PetscCall(), PetscCallAbort(), SETERRA(), SETERRQ(), SETERRABORT() 560 M*/ 561 562 PETSC_EXTERN PetscErrorCode PetscAbortFindSourceFile_Private(const char*,PetscInt*); 563 PETSC_EXTERN PetscBool petscwaitonerrorflg; 564 PETSC_EXTERN PetscBool petscindebugger; 565 566 /*MC 567 PETSCABORT - Call MPI_Abort with an informative error code 568 569 Synopsis: 570 #include <petscsys.h> 571 PETSCABORT(MPI_Comm comm, PetscErrorCode ierr) 572 573 Collective 574 575 Input Parameters: 576 + comm - A communicator, so that the error can be collective 577 - ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 578 579 Level: advanced 580 581 Notes: 582 We pass MPI_Abort() an error code of format XX_YYYY_ZZZ, where XX, YYYY are an index and line number of the file 583 where PETSCABORT is called, respectively. ZZZ is the PETSc error code. 584 585 If XX is zero, this means that the call was made in the routine main(). 586 If XX is one, that means 1) the file is not in PETSc (it may be in users code); OR 2) the file is in PETSc but PetscAbortSourceFiles[] 587 is out of date. PETSc developers have to update it. 588 Otherwise, look up the value of XX in the table PetscAbortSourceFiles[] in src/sys/error/err.c to map XX back to the source file where the PETSCABORT() was called. 589 590 If the option -start_in_debugger was used then this calls abort() to stop the program in the debugger. 591 592 M*/ 593 #define PETSCABORT(comm,...) do { \ 594 if (petscwaitonerrorflg) PetscSleep(1000); \ 595 if (petscindebugger) abort(); \ 596 else { \ 597 PetscErrorCode ierr_petsc_abort_ = __VA_ARGS__; \ 598 PetscInt idx = 0; \ 599 PetscAbortFindSourceFile_Private(__FILE__,&idx); \ 600 MPI_Abort(comm,(PetscMPIInt)(0*idx*10000000 + 0*__LINE__*1000 + ierr_petsc_abort_)); \ 601 } \ 602 } while (0) 603 604 #ifdef PETSC_CLANGUAGE_CXX 605 /*MC 606 PetscCallThrow - Checks error code, if non-zero it calls the C++ error handler which throws 607 an exception 608 609 Synopsis: 610 #include <petscerror.h> 611 void PetscCallThrow(PetscErrorCode ierr) 612 613 Not Collective 614 615 Input Parameter: 616 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 617 618 Notes: 619 Requires PETSc to be configured with clanguage = c++. Throws a std::runtime_error() on error. 620 621 Once the error handler throws the exception you can use PetscCallVoid() which returns without 622 an error code (bad idea since the error is ignored) or PetscCallAbort() to have MPI_Abort() 623 called immediately. 624 625 Level: beginner 626 627 .seealso: SETERRQ(), PetscCall(), SETERRABORT(), PetscCallAbort(), PetscTraceBackErrorHandler(), 628 PetscPushErrorHandler(), PetscError(), CHKMEMQ 629 M*/ 630 #define PetscCallThrow(...) do { \ 631 PetscErrorCode ierr_cxx_ = __VA_ARGS__; \ 632 if (PetscUnlikely(ierr_cxx_)) PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr_cxx_,PETSC_ERROR_IN_CXX,PETSC_NULLPTR); \ 633 } while (0) 634 635 /*MC 636 CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception 637 638 Synopsis: 639 #include <petscerror.h> 640 void CHKERRXX(PetscErrorCode ierr) 641 642 Not Collective 643 644 Input Parameter: 645 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 646 647 Notes: 648 Deprecated in favor of PetscCallThrow(). This routine behaves identically to it. 649 650 Level: deprecated 651 652 .seealso: PetscCallThrow() 653 M*/ 654 #define CHKERRXX(...) PetscCallThrow(__VA_ARGS__) 655 #endif 656 657 /*MC 658 PetscCallCXX - Checks C++ function calls and if they throw an exception, catch it and then 659 return a PETSc error code 660 661 Synopsis: 662 #include <petscerror.h> 663 void PetscCallCXX(expr) noexcept; 664 665 Not Collective 666 667 Input Parameter: 668 . expr - An arbitrary expression 669 670 Notes: 671 PetscCallCXX(expr) is a macro replacement for 672 .vb 673 try { 674 expr; 675 } catch (const std::exception& e) { 676 return ConvertToPetscErrorCode(e); 677 } 678 .ve 679 Due to the fact that it catches any (reasonable) exception, it is essentially noexcept. 680 681 Example Usage: 682 .vb 683 void foo(void) { throw std::runtime_error("error"); } 684 685 void bar() 686 { 687 PetscCallCXX(foo()); // ERROR bar() does not return PetscErrorCode 688 } 689 690 PetscErrorCode baz() 691 { 692 PetscCallCXX(foo()); // OK 693 694 PetscCallCXX( 695 bar(); 696 foo(); // OK mutliple statements allowed 697 ); 698 } 699 700 struct bop 701 { 702 bop() 703 { 704 PetscCallCXX(foo()); // ERROR returns PetscErrorCode, cannot be used in constructors 705 } 706 }; 707 708 // ERROR contains do-while, cannot be used as function-try block 709 PetscErrorCode qux() PetscCallCXX( 710 bar(); 711 baz(); 712 foo(); 713 return 0; 714 ) 715 .ve 716 717 Level: beginner 718 719 .seealso: PetscCallThrow(), SETERRQ(), PetscCall(), SETERRABORT(), PetscCallAbort(), 720 PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKMEMQ 721 M*/ 722 #define PetscCallCXX(...) do { \ 723 try { \ 724 __VA_ARGS__; \ 725 } catch (const std::exception& e) { \ 726 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"%s",e.what()); \ 727 } \ 728 } while (0) 729 730 /*MC 731 CHKERRCXX - Checks C++ function calls and if they throw an exception, catch it and then 732 return a PETSc error code 733 734 Synopsis: 735 #include <petscerror.h> 736 void CHKERRCXX(func) noexcept; 737 738 Not Collective 739 740 Input Parameter: 741 . func - C++ function calls 742 743 Notes: 744 Deprecated in favor of PetscCallCXX(). This routine behaves identically to it. 745 746 Level: deprecated 747 748 .seealso: PetscCallCXX() 749 M*/ 750 #define CHKERRCXX(...) PetscCallCXX(__VA_ARGS__) 751 752 /*MC 753 CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected 754 755 Synopsis: 756 #include <petscsys.h> 757 CHKMEMQ; 758 759 Not Collective 760 761 Level: beginner 762 763 Notes: 764 We highly recommend using Valgrind https://petsc.org/release/faq/#valgrind or for NVIDIA CUDA systems 765 https://docs.nvidia.com/cuda/cuda-memcheck/index.html for finding memory problems. The ``CHKMEMQ`` macro is useful on systems that 766 do not have valgrind, but is not as good as valgrind or cuda-memcheck. 767 768 Must run with the option -malloc_debug (-malloc_test in debug mode; or if PetscMallocSetDebug() called) to enable this option 769 770 Once the error handler is called the calling function is then returned from with the given error code. 771 772 By defaults prints location where memory that is corrupted was allocated. 773 774 Use CHKMEMA for functions that return void 775 776 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), PetscMallocValidate() 777 M*/ 778 #if defined(PETSC_CLANG_STATIC_ANALYZER) 779 #define CHKMEMQ 780 #define CHKMEMA 781 #else 782 #define CHKMEMQ PetscCall(PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)); 783 #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__) 784 #endif 785 786 /*E 787 PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers 788 789 Level: advanced 790 791 PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated 792 793 Developer Notes: 794 This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler() 795 796 .seealso: PetscError(), SETERRXX() 797 E*/ 798 typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType; 799 800 #if defined(__clang_analyzer__) 801 __attribute__((analyzer_noreturn)) 802 #endif 803 PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...) PETSC_ATTRIBUTE_COLD PETSC_ATTRIBUTE_FORMAT(7,8); 804 805 PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void); 806 PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **); 807 PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*) PETSC_ATTRIBUTE_COLD; 808 PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*) PETSC_ATTRIBUTE_COLD; 809 PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*) PETSC_ATTRIBUTE_COLD; 810 PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*) PETSC_ATTRIBUTE_COLD; 811 PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*) PETSC_ATTRIBUTE_COLD; 812 PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*) PETSC_ATTRIBUTE_COLD; 813 PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*) PETSC_ATTRIBUTE_COLD; 814 PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*); 815 PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void); 816 PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*); 817 PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*); 818 PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void); 819 PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt); 820 PETSC_EXTERN void PetscSignalSegvCheckPointerOrMpi(void); 821 PETSC_DEPRECATED_FUNCTION("Use PetscSignalSegvCheckPointerOrMpi() (since version 3.13)") static inline void PetscSignalSegvCheckPointer(void) {PetscSignalSegvCheckPointerOrMpi();} 822 823 /*MC 824 PetscErrorPrintf - Prints error messages. 825 826 Synopsis: 827 #include <petscsys.h> 828 PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 829 830 Not Collective 831 832 Input Parameter: 833 . format - the usual printf() format string 834 835 Options Database Keys: 836 + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr 837 - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.) 838 839 Notes: 840 Use 841 $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 842 $ error is handled.) and 843 $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function 844 845 Use 846 PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file. 847 PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file. 848 849 Use 850 PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print 851 852 Level: developer 853 854 Fortran Note: 855 This routine is not supported in Fortran. 856 857 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf() 858 M*/ 859 PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...) PETSC_ATTRIBUTE_FORMAT(1,2); 860 861 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 862 PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap); 863 PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap); 864 PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void); 865 PETSC_EXTERN PetscErrorCode PetscDetermineInitialFPTrap(void); 866 867 /* 868 Allows the code to build a stack frame as it runs 869 */ 870 871 #if defined(PETSC_USE_DEBUG) 872 #define PETSCSTACKSIZE 64 873 typedef struct { 874 const char *function[PETSCSTACKSIZE]; 875 const char *file[PETSCSTACKSIZE]; 876 int line[PETSCSTACKSIZE]; 877 int petscroutine[PETSCSTACKSIZE]; /* 0 external called from petsc, 1 petsc functions, 2 petsc user functions */ 878 int currentsize; 879 int hotdepth; 880 PetscBool check; /* runtime option to check for correct Push/Pop semantics at runtime */ 881 } PetscStack; 882 PETSC_EXTERN PetscStack petscstack; 883 #else 884 typedef struct { 885 char Silence_empty_struct_has_size_0_in_C_size_1_in_Cpp; 886 } PetscStack; 887 #endif 888 889 #if defined(PETSC_SERIALIZE_FUNCTIONS) 890 #include <petsc/private/petscfptimpl.h> 891 /* 892 Registers the current function into the global function pointer to function name table 893 894 Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc 895 */ 896 #define PetscRegister__FUNCT__() do { \ 897 static PetscBool __chked = PETSC_FALSE; \ 898 if (!__chked) {\ 899 void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\ 900 __chked = PETSC_TRUE;\ 901 }} while (0) 902 #else 903 #define PetscRegister__FUNCT__() 904 #endif 905 906 #if defined(PETSC_CLANG_STATIC_ANALYZER) 907 #define PetscStackPushNoCheck(funct,petsc_routine,hot) 908 #define PetscStackPopNoCheck 909 #define PetscStackClearTop 910 #define PetscFunctionBegin 911 #define PetscFunctionBeginUser 912 #define PetscFunctionBeginHot 913 #define PetscFunctionReturn(a) return a 914 #define PetscFunctionReturnVoid() return 915 #define PetscStackPop 916 #define PetscStackPush(f) 917 #elif defined(PETSC_USE_DEBUG) 918 /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error 919 * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at 920 * least more useful than "unknown" because it can distinguish multiple calls from the same function. 921 */ 922 #define PetscStackPushNoCheck(funct,petsc_routine,hot) do { \ 923 PetscStackSAWsTakeAccess(); \ 924 if (petscstack.currentsize < PETSCSTACKSIZE) { \ 925 petscstack.function[petscstack.currentsize] = funct; \ 926 petscstack.file[petscstack.currentsize] = __FILE__; \ 927 petscstack.line[petscstack.currentsize] = __LINE__; \ 928 petscstack.petscroutine[petscstack.currentsize] = petsc_routine; \ 929 } \ 930 ++petscstack.currentsize; \ 931 petscstack.hotdepth += (hot || petscstack.hotdepth); \ 932 PetscStackSAWsGrantAccess(); \ 933 } while (0) 934 935 #define PetscStackPopNoCheck(funct) do { \ 936 PetscStackSAWsTakeAccess(); \ 937 if (PetscUnlikely(petscstack.currentsize <= 0)) { \ 938 if (PetscUnlikely(petscstack.check)) { \ 939 printf("Invalid stack size %d, pop %s\n",petscstack.currentsize,funct); \ 940 } \ 941 } else { \ 942 if (--petscstack.currentsize < PETSCSTACKSIZE) { \ 943 if (PetscUnlikely( \ 944 petscstack.check && \ 945 petscstack.petscroutine[petscstack.currentsize] && \ 946 (petscstack.function[petscstack.currentsize] != \ 947 (const char*)funct))) { \ 948 /* We need this string comparison because "unknown" can be defined in different static strings: */ \ 949 PetscBool _cmpflg; \ 950 const char *_funct = petscstack.function[petscstack.currentsize]; \ 951 PetscStrcmp(_funct,funct,&_cmpflg); \ 952 if (!_cmpflg) printf("Invalid stack: push from %s, pop from %s\n", _funct,funct); \ 953 } \ 954 petscstack.function[petscstack.currentsize] = PETSC_NULLPTR; \ 955 petscstack.file[petscstack.currentsize] = PETSC_NULLPTR; \ 956 petscstack.line[petscstack.currentsize] = 0; \ 957 petscstack.petscroutine[petscstack.currentsize] = 0; \ 958 } \ 959 petscstack.hotdepth = PetscMax(petscstack.hotdepth-1,0); \ 960 } \ 961 PetscStackSAWsGrantAccess(); \ 962 } while (0) 963 964 #define PetscStackClearTop do { \ 965 PetscStackSAWsTakeAccess(); \ 966 if (petscstack.currentsize > 0 && \ 967 --petscstack.currentsize < PETSCSTACKSIZE) { \ 968 petscstack.function[petscstack.currentsize] = PETSC_NULLPTR; \ 969 petscstack.file[petscstack.currentsize] = PETSC_NULLPTR; \ 970 petscstack.line[petscstack.currentsize] = 0; \ 971 petscstack.petscroutine[petscstack.currentsize] = 0; \ 972 } \ 973 petscstack.hotdepth = PetscMax(petscstack.hotdepth-1,0); \ 974 PetscStackSAWsGrantAccess(); \ 975 } while (0) 976 977 /*MC 978 PetscFunctionBegin - First executable line of each PETSc function, used for error handling. Final 979 line of PETSc functions should be PetscFunctionReturn(0); 980 981 Synopsis: 982 #include <petscsys.h> 983 void PetscFunctionBegin; 984 985 Not Collective 986 987 Usage: 988 .vb 989 int something; 990 991 PetscFunctionBegin; 992 .ve 993 994 Notes: 995 Use PetscFunctionBeginUser for application codes. 996 997 Not available in Fortran 998 999 Level: developer 1000 1001 .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser() 1002 1003 M*/ 1004 #define PetscFunctionBegin do { \ 1005 PetscStackPushNoCheck(PETSC_FUNCTION_NAME,1,PETSC_FALSE); \ 1006 PetscRegister__FUNCT__(); \ 1007 } while (0) 1008 1009 /*MC 1010 PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in 1011 performance-critical circumstances. Use of this function allows for lighter profiling by default. 1012 1013 Synopsis: 1014 #include <petscsys.h> 1015 void PetscFunctionBeginHot; 1016 1017 Not Collective 1018 1019 Usage: 1020 .vb 1021 int something; 1022 1023 PetscFunctionBeginHot; 1024 .ve 1025 1026 Notes: 1027 Not available in Fortran 1028 1029 Level: developer 1030 1031 .seealso: PetscFunctionBegin, PetscFunctionReturn() 1032 1033 M*/ 1034 #define PetscFunctionBeginHot do { \ 1035 PetscStackPushNoCheck(PETSC_FUNCTION_NAME,1,PETSC_TRUE); \ 1036 PetscRegister__FUNCT__(); \ 1037 } while (0) 1038 1039 /*MC 1040 PetscFunctionBeginUser - First executable line of user provided PETSc routine 1041 1042 Synopsis: 1043 #include <petscsys.h> 1044 void PetscFunctionBeginUser; 1045 1046 Not Collective 1047 1048 Usage: 1049 .vb 1050 int something; 1051 1052 PetscFunctionBeginUser; 1053 .ve 1054 1055 Notes: 1056 Final line of PETSc functions should be PetscFunctionReturn(0) except for main(). 1057 1058 Not available in Fortran 1059 1060 This is identical to PetscFunctionBegin except it labels the routine as a user 1061 routine instead of as a PETSc library routine. 1062 1063 Level: intermediate 1064 1065 .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot 1066 1067 M*/ 1068 #define PetscFunctionBeginUser do { \ 1069 PetscStackPushNoCheck(PETSC_FUNCTION_NAME,2,PETSC_FALSE); \ 1070 PetscRegister__FUNCT__(); \ 1071 } while (0) 1072 1073 #define PetscStackPush(n) do { \ 1074 PetscStackPushNoCheck(n,0,PETSC_FALSE); \ 1075 CHKMEMQ; \ 1076 } while (0) 1077 1078 #define PetscStackPop do { \ 1079 CHKMEMQ; \ 1080 PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \ 1081 } while (0) 1082 1083 /*MC 1084 PetscFunctionReturn - Last executable line of each PETSc function 1085 used for error handling. Replaces return() 1086 1087 Synopsis: 1088 #include <petscsys.h> 1089 void PetscFunctionReturn(0); 1090 1091 Not Collective 1092 1093 Usage: 1094 .vb 1095 .... 1096 PetscFunctionReturn(0); 1097 } 1098 .ve 1099 1100 Notes: 1101 Not available in Fortran 1102 1103 Level: developer 1104 1105 .seealso: PetscFunctionBegin() 1106 1107 M*/ 1108 #define PetscFunctionReturn(a) do { \ 1109 PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \ 1110 return a; \ 1111 } while (0) 1112 1113 #define PetscFunctionReturnVoid() do { \ 1114 PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \ 1115 return; \ 1116 } while (0) 1117 #else /* PETSC_USE_DEBUG */ 1118 #define PetscStackPushNoCheck(funct,petsc_routine,hot) 1119 #define PetscStackPopNoCheck 1120 #define PetscStackClearTop 1121 #define PetscFunctionBegin 1122 #define PetscFunctionBeginUser 1123 #define PetscFunctionBeginHot 1124 #define PetscFunctionReturn(a) return a 1125 #define PetscFunctionReturnVoid() return 1126 #define PetscStackPop CHKMEMQ 1127 #define PetscStackPush(f) CHKMEMQ 1128 #endif /* PETSC_USE_DEBUG */ 1129 1130 #if defined(PETSC_CLANG_STATIC_ANALYZER) 1131 #define PetscStackCall(name,routine) 1132 #define PetscStackCallStandard(func,...) 1133 #else 1134 /* 1135 PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack. 1136 1137 Input Parameters: 1138 + name - string that gives the name of the function being called 1139 - routine - actual call to the routine, including ierr = and PetscCall(ierr); 1140 1141 Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes 1142 1143 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. 1144 1145 */ 1146 #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while (0) 1147 1148 /* 1149 PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack. 1150 1151 Input Parameters: 1152 + func- name of the routine 1153 - args - arguments to the routine surrounded by () 1154 1155 Notes: 1156 This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not. 1157 1158 Developer Note: this is so that when an external packge routine results in a crash or corrupts memory, they get blamed instead of PETSc. 1159 1160 */ 1161 #define PetscStackCallStandard(func,...) do { \ 1162 PetscStackPush(PetscStringize(func)); \ 1163 PetscErrorCode __ierr = func(__VA_ARGS__); \ 1164 PetscStackPop; \ 1165 PetscCheck(!__ierr,PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",PetscStringize(func),__ierr); \ 1166 } while (0) 1167 #endif /* PETSC_CLANG_STATIC_ANALYZER */ 1168 1169 #endif 1170