1 /* 2 Contains all error handling interfaces for PETSc. 3 */ 4 #ifndef PETSCERROR_H 5 #define PETSCERROR_H 6 7 #include <petscmacros.h> 8 #include <petscsystypes.h> 9 10 #if defined(__cplusplus) 11 #include <exception> // std::exception 12 #endif 13 14 /* SUBMANSEC = Sys */ 15 16 #define SETERRQ1(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 17 #define SETERRQ2(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 18 #define SETERRQ3(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 19 #define SETERRQ4(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 20 #define SETERRQ5(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 21 #define SETERRQ6(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 22 #define SETERRQ7(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 23 #define SETERRQ8(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 24 #define SETERRQ9(...) PETSC_DEPRECATED_MACRO("GCC warning \"Use SETERRQ() (since version 3.17)\"") SETERRQ(__VA_ARGS__) 25 26 /*MC 27 SETERRQ - Macro to be called when an error has been detected, 28 29 Synopsis: 30 #include <petscsys.h> 31 PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message,...) 32 33 Collective 34 35 Input Parameters: 36 + comm - A communicator, use `PETSC_COMM_SELF` unless you know all ranks of another communicator will detect the error 37 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 38 - message - error message 39 40 Level: beginner 41 42 Notes: 43 This is rarely needed, one should use `PetscCheck()` and `PetscCall()` and friends to automatically handle error conditions. 44 Once the error handler is called the calling function is then returned from with the given error code. 45 46 Experienced users can set the error handler with `PetscPushErrorHandler()`. 47 48 Fortran Notes: 49 SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the 50 Fortran main program. 51 52 .seealso: `PetscCheck()`, `PetscAssert()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, 53 `PetscError()`, `PetscCall()`, `CHKMEMQ`, `CHKERRA()`, `PetscCallMPI()` 54 M*/ 55 #define SETERRQ(comm, ierr, ...) \ 56 do { \ 57 PetscErrorCode ierr_seterrq_petsc_ = PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr, PETSC_ERROR_INITIAL, __VA_ARGS__); \ 58 return ierr_seterrq_petsc_ ? ierr_seterrq_petsc_ : PETSC_ERR_RETURN; \ 59 } while (0) 60 61 /* 62 Returned from PETSc functions that are called from MPI, such as related to attributes 63 Do not confuse PETSC_MPI_ERROR_CODE and PETSC_ERR_MPI, the first is registered with MPI and returned to MPI as 64 an error code, the latter is a regular PETSc error code passed within PETSc code indicating an error was detected in an MPI call. 65 */ 66 PETSC_EXTERN PetscMPIInt PETSC_MPI_ERROR_CLASS; 67 PETSC_EXTERN PetscMPIInt PETSC_MPI_ERROR_CODE; 68 69 /*MC 70 SETERRMPI - Macro to be called when an error has been detected within an MPI callback function 71 72 Synopsis: 73 #include <petscsys.h> 74 PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message,...) 75 76 Collective 77 78 Input Parameters: 79 + comm - A communicator, use `PETSC_COMM_SELF` unless you know all ranks of another communicator will detect the error 80 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 81 - message - error message 82 83 Level: developer 84 85 Notes: 86 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` 87 which is registered with `MPI_Add_error_code()` when PETSc is initialized. 88 89 .seealso: `SETERRQ()`, `PetscCall()`, `PetscCallMPI()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, `PetscError()`, `CHKMEMQ` 90 M*/ 91 #define SETERRMPI(comm, ierr, ...) return ((void)PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr, PETSC_ERROR_INITIAL, __VA_ARGS__), PETSC_MPI_ERROR_CODE) 92 93 /*MC 94 SETERRA - Fortran-only macro that can be called when an error has been detected from the main program 95 96 Synopsis: 97 #include <petscsys.h> 98 PetscErrorCode SETERRA(MPI_Comm comm,PetscErrorCode ierr,char *message) 99 100 Collective 101 102 Input Parameters: 103 + comm - A communicator, so that the error can be collective 104 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 105 - message - error message in the printf format 106 107 Level: beginner 108 109 Notes: 110 This should only be used with Fortran. With C/C++, use `SETERRQ()`. 111 112 Fortran Notes: 113 `SETERRQ()` may be called from Fortran subroutines but `SETERRA()` must be called from the 114 Fortran main program. 115 116 .seealso: `SETERRQ()`, `SETERRABORT()`, `PetscCall()`, `CHKERRA()`, `PetscCallAbort()` 117 M*/ 118 119 /*MC 120 SETERRABORT - Macro that can be called when an error has been detected, 121 122 Synopsis: 123 #include <petscsys.h> 124 PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message,...) 125 126 Collective 127 128 Input Parameters: 129 + comm - A communicator, so that the error can be collective 130 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 131 - message - error message in the printf format 132 133 Level: beginner 134 135 Notes: 136 This function just calls `MPI_Abort()`. 137 138 This should only be called in routines that cannot return an error code, such as in C++ constructors. 139 140 .seealso: `SETERRQ()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, `PetscError()`, `PetscCall()`, `CHKMEMQ` 141 M*/ 142 #define SETERRABORT(comm, ierr, ...) \ 143 do { \ 144 (void)PetscError(comm, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr, PETSC_ERROR_INITIAL, __VA_ARGS__); \ 145 MPI_Abort(comm, ierr); \ 146 } while (0) 147 148 /*MC 149 PetscCheck - Check that a particular condition is true 150 151 Synopsis: 152 #include <petscerror.h> 153 void PetscCheck(bool cond, MPI_Comm comm, PetscErrorCode ierr, const char *message, ...) 154 155 Collective 156 157 Input Parameters: 158 + cond - The boolean condition 159 . comm - The communicator on which the check can be collective on 160 . ierr - A nonzero error code, see include/petscerror.h for the complete list 161 - message - Error message in printf format 162 163 Notes: 164 Enabled in both optimized and debug builds. 165 166 Calls `SETERRQ()` if the assertion fails, so can only be called from functions returning a 167 `PetscErrorCode` (or equivalent type after conversion). 168 169 Level: beginner 170 171 .seealso: `PetscAssert()`, `SETERRQ()`, `PetscError()`, `PetscCall()`, `PetscCheckAbort()` 172 M*/ 173 #define PetscCheck(cond, comm, ierr, ...) \ 174 do { \ 175 if (PetscUnlikely(!(cond))) SETERRQ(comm, ierr, __VA_ARGS__); \ 176 } while (0) 177 178 /*MC 179 PetscCheckAbort - Check that a particular condition is true, otherwise prints error and aborts 180 181 Synopsis: 182 #include <petscerror.h> 183 void PetscCheckAbort(bool cond, MPI_Comm comm, PetscErrorCode ierr, const char *message, ...) 184 185 Collective 186 187 Input Parameters: 188 + cond - The boolean condition 189 . comm - The communicator on which the check can be collective on 190 . ierr - A nonzero error code, see include/petscerror.h for the complete list 191 - message - Error message in printf format 192 193 Notes: 194 Enabled in both optimized and debug builds. 195 196 Calls `SETERRABORT()` if the assertion fails, can be called from a function that does not return an 197 error code, such as a C++ constructor. usually `PetscCheck()` should be used. 198 199 Level: developer 200 201 .seealso: `PetscAssertAbort()`, `PetscAssert()`, `SETERRQ()`, `PetscError()`, `PetscCall()`, `PetscCheck()`, `SETTERRABORT()` 202 M*/ 203 #define PetscCheckAbort(cond, comm, ierr, ...) \ 204 do { \ 205 if (PetscUnlikely(!(cond))) SETERRABORT(comm, ierr, __VA_ARGS__); \ 206 } while (0) 207 208 /*MC 209 PetscAssert - Assert that a particular condition is true 210 211 Synopsis: 212 #include <petscerror.h> 213 void PetscAssert(bool cond, MPI_Comm comm, PetscErrorCode ierr, const char *message, ...) 214 215 Collective 216 217 Input Parameters: 218 + cond - The boolean condition 219 . comm - The communicator on which the check can be collective on 220 . ierr - A nonzero error code, see include/petscerror.h for the complete list 221 - message - Error message in printf format 222 223 Notes: 224 Equivalent to `PetscCheck()` if debugging is enabled, and `PetscAssume(cond)` otherwise. 225 226 See `PetscCheck()` for usage and behaviour. 227 228 This is needed instead of simply using `assert()` because this correctly handles the collective nature of errors under MPI 229 230 Level: beginner 231 232 .seealso: `PetscCheck()`, `SETERRQ()`, `PetscError()`, `PetscAssertAbort()` 233 M*/ 234 #if PetscDefined(USE_DEBUG) 235 #define PetscAssert(cond, comm, ierr, ...) PetscCheck(cond, comm, ierr, __VA_ARGS__) 236 #else 237 #define PetscAssert(cond, ...) PetscAssume(cond) 238 #endif 239 240 /*MC 241 PetscAssertAbort - Assert that a particular condition is true, otherwise prints error and aborts 242 243 Synopsis: 244 #include <petscerror.h> 245 void PetscAssertAbort(bool cond, MPI_Comm comm, PetscErrorCode ierr, const char *message, ...) 246 247 Collective 248 249 Input Parameters: 250 + cond - The boolean condition 251 . comm - The communicator on which the check can be collective on 252 . ierr - A nonzero error code, see include/petscerror.h for the complete list 253 - message - Error message in printf format 254 255 Notes: 256 Enabled only in debug builds. See `PetscCheckAbort()` for usage. 257 258 Level: beginner 259 260 .seealso: `PetscCheckAbort()`, `PetscAssert()`, `PetscCheck()`, `SETERRABORT()`, `PetscError()` 261 M*/ 262 #if PetscDefined(USE_DEBUG) 263 #define PetscAssertAbort(cond, comm, ierr, ...) PetscCheckAbort(cond, comm, ierr, __VA_ARGS__) 264 #else 265 #define PetscAssertAbort(cond, comm, ierr, ...) PetscAssume(cond) 266 #endif 267 268 /*MC 269 PetscCall - Calls a PETSc function and then checks the resulting error code, if it is 270 non-zero it calls the error handler and returns from the current function with the error 271 code. 272 273 Synopsis: 274 #include <petscerror.h> 275 void PetscCall(PetscFunction(args)) 276 277 Not Collective 278 279 Input Parameter: 280 . PetscFunction - any PETSc function that returns an error code 281 282 Notes: 283 Once the error handler is called the calling function is then returned from with the given 284 error code. Experienced users can set the error handler with `PetscPushErrorHandler()`. 285 286 `PetscCall()` cannot be used in functions returning a datatype not convertible to 287 `PetscErrorCode`. For example, `PetscCall()` may not be used in functions returning void, use 288 `PetscCallAbort()` or `PetscCallVoid()` in this case. 289 290 Example Usage: 291 .vb 292 PetscCall(PetscInitiailize(...)); // OK to call even when PETSc is not yet initialized! 293 294 struct my_struct 295 { 296 void *data; 297 } my_complex_type; 298 299 struct my_struct bar(void) 300 { 301 PetscCall(foo(15)); // ERROR PetscErrorCode not convertible to struct my_struct! 302 } 303 304 PetscCall(bar()) // ERROR input not convertible to PetscErrorCode 305 .ve 306 307 It is also possible to call this directly on a `PetscErrorCode` variable 308 .vb 309 PetscCall(ierr); // check if ierr is nonzero 310 .ve 311 312 Should not be used to call callback functions provided by users, `PetscCallBack()` should be used in that situation. 313 314 `PetscUseTypeMethod()` or `PetscTryTypeMethod()` should be used when calling functions pointers contained in a PETSc object's `ops` array 315 316 Fortran Notes: 317 The Fortran function from which this is used must declare a variable PetscErrorCode ierr and ierr must be 318 the final argument to the PETSc function being called. 319 320 In the main program and in Fortran subroutines that do not have ierr as the final return parameter one 321 should use `PetscCallA()` 322 323 Example Fortran Usage: 324 .vb 325 PetscErrorCode ierr 326 Vec v 327 328 ... 329 PetscCall(VecShift(v,1.0,ierr)) 330 PetscCallA(VecShift(v,1.0,ierr)) 331 .ve 332 333 Level: beginner 334 335 .seealso: `SETERRQ()`, `PetscCheck()`, `PetscAssert()`, `PetscTraceBackErrorHandler()`, 336 `PetscCallMPI()`, `PetscPushErrorHandler()`, `PetscError()`, `CHKMEMQ`, `CHKERRA()`, 337 `CHKERRMPI()`, `PetscCallBack()`, `PetscCallAbort()`, `PetscCallVoid()` 338 M*/ 339 340 /*MC 341 PetscCallBack - Calls a user provided PETSc callback function and then checks the resulting error code, if it is non-zero it calls the error 342 handler and returns from the current function with the error code. 343 344 Synopsis: 345 #include <petscerror.h> 346 void PetscCallBack(const char *functionname,PetscFunction(args)) 347 348 Not Collective 349 350 Input Parameters: 351 + functionname - the name of the function being called, this can be a string with spaces that describes the meaning of the callback 352 - PetscFunction - user provided callback function that returns an error code 353 354 Notes: 355 Once the error handler is called the calling function is then returned from with the given 356 error code. Experienced users can set the error handler with `PetscPushErrorHandler()`. 357 358 `PetscCallBack()` should only be called in PETSc when a call is being made to a user provided call-back routine. 359 360 Example Usage: 361 .vb 362 PetscCallBack("XXX callback to do something",a->callback(...)); 363 .ve 364 365 Level: developer 366 367 .seealso: `SETERRQ()`, `PetscCheck()`, `PetscCall()`, `PetscAssert()`, `PetscTraceBackErrorHandler()`, `PetscCallMPI()` 368 `PetscPushErrorHandler()`, `PetscError()`, `CHKMEMQ`, `CHKERRA()`, `CHKERRMPI()`, `PetscCall()` 369 M*/ 370 371 /*MC 372 PetscCallVoid - Like `PetscCall()` but for functions returning `void` 373 374 Synopsis: 375 #include <petscerror.h> 376 void PetscCall(PetscFunction(args)) 377 378 Not Collective 379 380 Input Parameter: 381 . PetscFunction - any PETSc function that returns an error code 382 383 Notes: 384 Has identical usage to `PetscCall()`, except that it returns `void` on error instead of a 385 `PetscErrorCode`. See `PetscCall()` for more detail discussion. 386 387 Note that users should prefer `PetscCallAbort()` to this routine. While this routine does 388 "handle" errors by returning from the enclosing function, it effectively gobbles the 389 error. Since the enclosing function itself returns `void`, its callers have no way of knowing 390 that the routine returned early due to an error. `PetscCallAbort()` at least ensures that the 391 program crashes gracefully. 392 393 Example Usage: 394 .vb 395 void foo() 396 { 397 KSP ksp; 398 399 PetscFunctionBeginUser; 400 // OK, properly handles PETSc error codes 401 PetscCallVoid(KSPCreate(PETSC_COMM_WORLD, &ksp)); 402 PetscFunctionReturn(PETSC_SUCCESS); 403 } 404 405 PetscErrorCode bar() 406 { 407 KSP ksp; 408 409 PetscFunctionBeginUser; 410 // ERROR, Non-void function 'bar' should return a value 411 PetscCallVoid(KSPCreate(PETSC_COMM_WORLD, &ksp)); 412 // OK, returning PetscErrorCode 413 PetscCall(KSPCreate(PETSC_COMM_WORLD, &ksp)); 414 PetscFunctionReturn(PETSC_SUCCESS); 415 } 416 ,ve 417 418 Level: beginner 419 420 .seealso: `PetscCall()`, `PetscErrorCode` 421 M*/ 422 #if defined(PETSC_CLANG_STATIC_ANALYZER) 423 void PetscCall(PetscErrorCode); 424 void PetscCallBack(const char *, PetscErrorCode); 425 void PetscCallVoid(PetscErrorCode); 426 #else 427 #define PetscCall(...) \ 428 do { \ 429 PetscErrorCode ierr_petsc_call_q_; \ 430 PetscStackUpdateLine; \ 431 ierr_petsc_call_q_ = __VA_ARGS__; \ 432 if (PetscUnlikely(ierr_petsc_call_q_ != PETSC_SUCCESS)) return PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_petsc_call_q_, PETSC_ERROR_REPEAT, " "); \ 433 } while (0) 434 #define PetscCallBack(function, ...) \ 435 do { \ 436 PetscErrorCode ierr_petsc_call_q_; \ 437 PetscStackUpdateLine; \ 438 PetscStackPushExternal(function); \ 439 ierr_petsc_call_q_ = __VA_ARGS__; \ 440 PetscStackPop; \ 441 if (PetscUnlikely(ierr_petsc_call_q_ != PETSC_SUCCESS)) return PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_petsc_call_q_, PETSC_ERROR_REPEAT, " "); \ 442 } while (0) 443 #define PetscCallVoid(...) \ 444 do { \ 445 PetscErrorCode ierr_petsc_call_void_; \ 446 PetscStackUpdateLine; \ 447 ierr_petsc_call_void_ = __VA_ARGS__; \ 448 if (PetscUnlikely(ierr_petsc_call_void_ != PETSC_SUCCESS)) { \ 449 ierr_petsc_call_void_ = PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_petsc_call_void_, PETSC_ERROR_REPEAT, " "); \ 450 (void)ierr_petsc_call_void_; \ 451 return; \ 452 } \ 453 } while (0) 454 #endif 455 456 /*MC 457 CHKERRQ - Checks error code returned from PETSc function 458 459 Synopsis: 460 #include <petscsys.h> 461 void CHKERRQ(PetscErrorCode ierr) 462 463 Not Collective 464 465 Input Parameters: 466 . ierr - nonzero error code 467 468 Notes: 469 Deprecated in favor of `PetscCall()`. This routine behaves identically to it. 470 471 Level: deprecated 472 473 .seealso: `PetscCall()` 474 M*/ 475 #define CHKERRQ(...) PetscCall(__VA_ARGS__) 476 #define CHKERRV(...) PetscCallVoid(__VA_ARGS__) 477 478 PETSC_EXTERN void PetscMPIErrorString(PetscMPIInt, char *); 479 480 /*MC 481 PetscCallMPI - Checks error code returned from MPI calls, if non-zero it calls the error 482 handler and then returns 483 484 Synopsis: 485 #include <petscerror.h> 486 void PetscCallMPI(MPI_Function(args)) 487 488 Not Collective 489 490 Input Parameters: 491 . MPI_Function - an MPI function that returns an MPI error code 492 493 Notes: 494 Always returns the error code `PETSC_ERR_MPI`; the MPI error code and string are embedded in 495 the string error message. Do not use this to call any other routines (for example PETSc 496 routines), it should only be used for direct MPI calls. The user may configure PETSc with the 497 `--with-strict-petscerrorcode` option to check this at compile-time, otherwise they must 498 check this themselves. 499 500 This rouine can only be used in functions returning `PetscErrorCode` themselves. If the 501 calling function returns a different type, use `PetscCallMPIAbort()` instead. 502 503 Example Usage: 504 .vb 505 PetscCallMPI(MPI_Comm_size(...)); // OK, calling MPI function 506 507 PetscCallMPI(PetscFunction(...)); // ERROR, use PetscCall() instead! 508 .ve 509 510 Fortran Notes: 511 The Fortran function from which this is used must declare a variable `PetscErrorCode` ierr and ierr must be 512 the final argument to the MPI function being called. 513 514 In the main program and in Fortran subroutines that do not have ierr as the final return parameter one 515 should use `PetscCallMPIA()` 516 517 Fortran Usage: 518 .vb 519 PetscErrorCode ierr or integer ierr 520 ... 521 PetscCallMPI(MPI_Comm_size(...,ierr)) 522 PetscCallMPIA(MPI_Comm_size(...,ierr)) ! Will abort after calling error handler 523 524 PetscCallMPI(MPI_Comm_size(...,eflag)) ! ERROR, final argument must be ierr 525 .ve 526 527 Level: beginner 528 529 .seealso: `SETERRMPI()`, `PetscCall()`, `SETERRQ()`, `SETERRABORT()`, `PetscCallAbort()`, 530 `PetscCallMPIAbort()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, 531 `PetscError()`, `CHKMEMQ` 532 M*/ 533 534 /*MC 535 PetscCallMPIAbort - Like `PetscCallMPI()` but calls `MPI_Abort()` on error 536 537 Synopsis: 538 #include <petscerror.h> 539 void PetscCallMPIAbort(MPI_Comm comm, MPI_Function(args)) 540 541 Not Collective 542 543 Input Parameters: 544 + comm - the MPI communicator to abort on 545 - MPI_Function - an MPI function that returns an MPI error code 546 547 Notes: 548 Usage is identical to `PetscCallMPI()`. See `PetscCallMPI()` for detailed discussion. 549 550 This routine may be used in functions returning `void` or other non-`PetscErrorCode` types. 551 552 Level: beginner 553 554 .seealso: `PetscCallMPI()`, `PetscCallAbort()`, `SETERRABORT()` 555 M*/ 556 #if defined(PETSC_CLANG_STATIC_ANALYZER) 557 void PetscCallMPI(PetscMPIInt); 558 void PetscCallMPIAbort(MPI_Comm, PetscMPIInt); 559 #else 560 #define PetscCallMPI_Private(__PETSC_STACK_POP_FUNC__, __SETERR_FUNC__, __COMM__, ...) \ 561 do { \ 562 PetscMPIInt ierr_petsc_call_mpi_; \ 563 PetscStackUpdateLine; \ 564 PetscStackPushExternal("MPI function"); \ 565 { \ 566 ierr_petsc_call_mpi_ = __VA_ARGS__; \ 567 } \ 568 __PETSC_STACK_POP_FUNC__; \ 569 if (PetscUnlikely(ierr_petsc_call_mpi_ != MPI_SUCCESS)) { \ 570 char petsc_mpi_7_errorstring[2 * MPI_MAX_ERROR_STRING]; \ 571 PetscMPIErrorString(ierr_petsc_call_mpi_, (char *)petsc_mpi_7_errorstring); \ 572 __SETERR_FUNC__(__COMM__, PETSC_ERR_MPI, "MPI error %d %s", (int)ierr_petsc_call_mpi_, petsc_mpi_7_errorstring); \ 573 } \ 574 } while (0) 575 576 #define PetscCallMPI(...) PetscCallMPI_Private(PetscStackPop, SETERRQ, PETSC_COMM_SELF, __VA_ARGS__) 577 #define PetscCallMPIAbort(comm, ...) PetscCallMPI_Private(PetscStackPopNoCheck(PETSC_FUNCTION_NAME), SETERRABORT, comm, __VA_ARGS__) 578 #endif 579 580 /*MC 581 CHKERRMPI - Checks error code returned from MPI calls, if non-zero it calls the error 582 handler and then returns 583 584 Synopsis: 585 #include <petscerror.h> 586 void CHKERRMPI(PetscErrorCode ierr) 587 588 Not Collective 589 590 Input Parameter: 591 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 592 593 Notes: 594 Deprecated in favor of `PetscCallMPI()`. This routine behaves identically to it. 595 596 Level: deprecated 597 598 .seealso: `PetscCallMPI()` 599 M*/ 600 #define CHKERRMPI(...) PetscCallMPI(__VA_ARGS__) 601 602 /*MC 603 PetscCallAbort - Checks error code returned from PETSc function, if non-zero it aborts immediately 604 605 Synopsis: 606 #include <petscerror.h> 607 void PetscCallAbort(MPI_Comm comm, PetscErrorCode ierr) 608 609 Collective 610 611 Input Parameters: 612 + comm - the MPI communicator on which to abort 613 - ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 614 615 Notes: 616 This macro has identical type and usage semantics to `PetscCall()` with the important caveat 617 that this macro does not return. Instead, if ierr is nonzero it calls the PETSc error handler 618 and then immediately calls `MPI_Abort()`. It can therefore be used anywhere. 619 620 As per `MPI_Abort()` semantics the communicator passed must be valid, although there is currently 621 no attempt made at handling any potential errors from `MPI_Abort()`. Note that while 622 `MPI_Abort()` is required to terminate only those processes which reside on comm, it is often 623 the case that `MPI_Abort()` terminates *all* processes. 624 625 Example Usage: 626 .vb 627 PetscErrorCode boom(void) { return PETSC_ERR_MEM; } 628 629 void foo(void) 630 { 631 PetscCallAbort(PETSC_COMM_WORLD,boom()); // OK, does not return a type 632 } 633 634 double bar(void) 635 { 636 PetscCallAbort(PETSC_COMM_WORLD,boom()); // OK, does not return a type 637 } 638 639 PetscCallAbort(MPI_COMM_NULL,boom()); // ERROR, communicator should be valid 640 641 struct baz 642 { 643 baz() 644 { 645 PetscCallAbort(PETSC_COMM_SELF,boom()); // OK 646 } 647 648 ~baz() 649 { 650 PetscCallAbort(PETSC_COMM_SELF,boom()); // OK (in fact the only way to handle PETSc errors) 651 } 652 }; 653 .ve 654 655 Level: intermediate 656 657 .seealso: `SETERRABORT()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, `PetscError()`, 658 `SETERRQ()`, `CHKMEMQ`, `PetscCallMPI()`, `PetscCallCXXAbort()` 659 M*/ 660 #if defined(PETSC_CLANG_STATIC_ANALYZER) 661 void PetscCallAbort(MPI_Comm, PetscErrorCode); 662 void PetscCallContinue(PetscErrorCode); 663 #else 664 #define PetscCallAbort(comm, ...) \ 665 do { \ 666 PetscErrorCode ierr_petsc_call_abort_; \ 667 PetscStackUpdateLine; \ 668 ierr_petsc_call_abort_ = __VA_ARGS__; \ 669 if (PetscUnlikely(ierr_petsc_call_abort_ != PETSC_SUCCESS)) { \ 670 ierr_petsc_call_abort_ = PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_petsc_call_abort_, PETSC_ERROR_REPEAT, " "); \ 671 (void)MPI_Abort(comm, (PetscMPIInt)ierr_petsc_call_abort_); \ 672 } \ 673 } while (0) 674 #define PetscCallContinue(...) \ 675 do { \ 676 PetscErrorCode ierr_petsc_call_continue_; \ 677 PetscStackUpdateLine; \ 678 ierr_petsc_call_continue_ = __VA_ARGS__; \ 679 if (PetscUnlikely(ierr_petsc_call_continue_ != PETSC_SUCCESS)) { \ 680 ierr_petsc_call_continue_ = PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_petsc_call_continue_, PETSC_ERROR_REPEAT, " "); \ 681 (void)ierr_petsc_call_continue_; \ 682 } \ 683 } while (0) 684 #endif 685 686 /*MC 687 CHKERRABORT - Checks error code returned from PETSc function. If non-zero it aborts immediately. 688 689 Synopsis: 690 #include <petscerror.h> 691 void CHKERRABORT(MPI_Comm comm, PetscErrorCode ierr) 692 693 Not Collective 694 695 Input Parameters: 696 + comm - the MPI communicator 697 - ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 698 699 Notes: 700 Deprecated in favor of `PetscCallAbort()`. This routine behaves identically to it. 701 702 Level: deprecated 703 704 .seealso: `PetscCallAbort()` 705 M*/ 706 #define CHKERRABORT(comm, ...) PetscCallAbort(comm, __VA_ARGS__) 707 #define CHKERRCONTINUE(...) PetscCallContinue(__VA_ARGS__) 708 709 /*MC 710 CHKERRA - Fortran-only replacement for use of `CHKERRQ()` in the main program, which aborts immediately 711 712 Synopsis: 713 #include <petscsys.h> 714 PetscErrorCode CHKERRA(PetscErrorCode ierr) 715 716 Not Collective 717 718 Input Parameters: 719 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 720 721 Level: deprecated 722 723 Note: 724 This macro is rarely needed, normal usage is `PetscCallA()` in the main Fortran program. 725 726 .seealso: `PetscCall()`, `PetscCallA()`, `PetscCallAbort()`, `CHKERRQ()`, `SETERRA()`, `SETERRQ()`, `SETERRABORT()` 727 M*/ 728 729 PETSC_EXTERN PetscBool petscwaitonerrorflg; 730 PETSC_EXTERN PetscBool petscindebugger; 731 732 /*MC 733 PETSCABORT - Call MPI_Abort with an informative error code 734 735 Synopsis: 736 #include <petscsys.h> 737 PETSCABORT(MPI_Comm comm, PetscErrorCode ierr) 738 739 Collective 740 741 Input Parameters: 742 + comm - A communicator, so that the error can be collective 743 - ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 744 745 Level: advanced 746 747 Notes: 748 If the option -start_in_debugger was used then this calls abort() to stop the program in the debugger. 749 750 if `PetscCIEnabledPortableErrorOutput` is set it strives to exit cleanly without call `MPI_Abort()` 751 752 M*/ 753 #if defined(PETSC_CLANG_STATIC_ANALYZER) 754 void PETSCABORT(MPI_Comm, PetscErrorCode); 755 #else 756 #define PETSCABORT(comm, ...) \ 757 do { \ 758 PetscErrorCode ierr_petsc_abort_; \ 759 if (petscwaitonerrorflg) { ierr_petsc_abort_ = PetscSleep(1000); } \ 760 if (petscindebugger) { \ 761 abort(); \ 762 } else { \ 763 PetscMPIInt size_; \ 764 ierr_petsc_abort_ = __VA_ARGS__; \ 765 MPI_Comm_size(comm, &size_); \ 766 if (PetscCIEnabledPortableErrorOutput && size_ == PetscGlobalSize && ierr_petsc_abort_ != PETSC_ERR_SIG) { \ 767 MPI_Finalize(); \ 768 exit(0); \ 769 } else if (PetscCIEnabledPortableErrorOutput && PetscGlobalSize == 1) { \ 770 exit(0); \ 771 } else { \ 772 MPI_Abort(comm, (PetscMPIInt)ierr_petsc_abort_); \ 773 } \ 774 } \ 775 } while (0) 776 #endif 777 778 #ifdef PETSC_CLANGUAGE_CXX 779 /*MC 780 PetscCallThrow - Checks error code, if non-zero it calls the C++ error handler which throws 781 an exception 782 783 Synopsis: 784 #include <petscerror.h> 785 void PetscCallThrow(PetscErrorCode ierr) 786 787 Not Collective 788 789 Input Parameter: 790 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 791 792 Notes: 793 Requires PETSc to be configured with clanguage = c++. Throws a std::runtime_error() on error. 794 795 Once the error handler throws the exception you can use `PetscCallVoid()` which returns without 796 an error code (bad idea since the error is ignored) or `PetscCallAbort()` to have `MPI_Abort()` 797 called immediately. 798 799 Level: beginner 800 801 .seealso: `SETERRQ()`, `PetscCall()`, `SETERRABORT()`, `PetscCallAbort()`, `PetscTraceBackErrorHandler()`, 802 `PetscPushErrorHandler()`, `PetscError()`, `CHKMEMQ` 803 M*/ 804 #define PetscCallThrow(...) \ 805 do { \ 806 PetscStackUpdateLine; \ 807 PetscErrorCode ierr_petsc_call_throw_ = __VA_ARGS__; \ 808 if (PetscUnlikely(ierr_petsc_call_throw_ != PETSC_SUCCESS)) PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_petsc_call_throw_, PETSC_ERROR_IN_CXX, PETSC_NULLPTR); \ 809 } while (0) 810 811 /*MC 812 CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception 813 814 Synopsis: 815 #include <petscerror.h> 816 void CHKERRXX(PetscErrorCode ierr) 817 818 Not Collective 819 820 Input Parameter: 821 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 822 823 Notes: 824 Deprecated in favor of `PetscCallThrow()`. This routine behaves identically to it. 825 826 Level: deprecated 827 828 .seealso: `PetscCallThrow()` 829 M*/ 830 #define CHKERRXX(...) PetscCallThrow(__VA_ARGS__) 831 #endif 832 833 #define PetscCallCXX_Private(__SETERR_FUNC__, __COMM__, ...) \ 834 do { \ 835 PetscStackUpdateLine; \ 836 try { \ 837 __VA_ARGS__; \ 838 } catch (const std::exception &e) { \ 839 __SETERR_FUNC__(__COMM__, PETSC_ERR_LIB, "%s", e.what()); \ 840 } \ 841 } while (0) 842 843 /*MC 844 PetscCallCXX - Checks C++ function calls and if they throw an exception, catch it and then 845 return a PETSc error code 846 847 Synopsis: 848 #include <petscerror.h> 849 void PetscCallCXX(...) noexcept; 850 851 Not Collective 852 853 Input Parameter: 854 . __VA_ARGS__ - An arbitrary expression 855 856 Level: beginner 857 858 Notes: 859 `PetscCallCXX(...)` is a macro replacement for 860 .vb 861 try { 862 __VA_ARGS__; 863 } catch (const std::exception& e) { 864 return ConvertToPetscErrorCode(e); 865 } 866 .ve 867 Due to the fact that it catches any (reasonable) exception, it is essentially noexcept. 868 869 If you cannot return a `PetscErrorCode` use `PetscCallCXXAbort()` instead. 870 871 Example Usage: 872 .vb 873 void foo(void) { throw std::runtime_error("error"); } 874 875 void bar() 876 { 877 PetscCallCXX(foo()); // ERROR bar() does not return PetscErrorCode 878 } 879 880 PetscErrorCode baz() 881 { 882 PetscCallCXX(foo()); // OK 883 884 PetscCallCXX( 885 bar(); 886 foo(); // OK multiple statements allowed 887 ); 888 } 889 890 struct bop 891 { 892 bop() 893 { 894 PetscCallCXX(foo()); // ERROR returns PetscErrorCode, cannot be used in constructors 895 } 896 }; 897 898 // ERROR contains do-while, cannot be used as function-try block 899 PetscErrorCode qux() PetscCallCXX( 900 bar(); 901 baz(); 902 foo(); 903 return 0; 904 ) 905 .ve 906 907 .seealso: `PetscCallCXXAbort()`, `PetscCallThrow()`, `SETERRQ()`, `PetscCall()`, 908 `SETERRABORT()`, `PetscCallAbort()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, 909 `PetscError()`, `CHKMEMQ` 910 M*/ 911 #define PetscCallCXX(...) PetscCallCXX_Private(SETERRQ, PETSC_COMM_SELF, __VA_ARGS__) 912 913 /*MC 914 PetscCallCXXAbort - Like `PetscCallCXX()` but calls `MPI_Abort()` instead of returning an 915 error-code 916 917 Synopsis: 918 #include <petscerror.h> 919 void PetscCallCXXAbort(MPI_Comm comm, ...) noexcept; 920 921 Collective on `comm` 922 923 Input Parameters: 924 + comm - The MPI communicator to abort on 925 - __VA_ARGS__ - An arbitrary expression 926 927 Level: beginner 928 929 Notes: 930 This macro may be used to check C++ expressions for exceptions in cases where you cannot 931 return an error code. This includes constructors, destructors, copy/move assignment functions 932 or constructors among others. 933 934 If an exception is caught, the macro calls `SETERRABORT()` on `comm`. The exception must 935 derive from `std::exception` in order to be caught. 936 937 If the routine _can_ return an error-code it is highly advised to use `PetscCallCXX()` 938 instead. 939 940 See `PetscCallCXX()` for additional discussion. 941 942 Fortran Note: 943 Not available from Fortran. 944 945 Example Usage: 946 .vb 947 class Foo 948 { 949 std::vector<int> data_; 950 951 public: 952 // normally std::vector::reserve() may raise an exception, but since we handle it with 953 // PetscCallCXXAbort() we may mark this routine as noexcept! 954 Foo() noexcept 955 { 956 PetscCallCXXAbort(PETSC_COMM_SELF, data_.reserve(10)); 957 } 958 }; 959 960 std::vector<int> bar() 961 { 962 std::vector<int> v; 963 964 PetscFunctionBegin; 965 // OK! 966 PetscCallCXXAbort(PETSC_COMM_SELF, v.emplace_back(1)); 967 PetscFunctionReturn(v); 968 } 969 970 PetscErrorCode baz() 971 { 972 std::vector<int> v; 973 974 PetscFunctionBegin; 975 // WRONG! baz() returns a PetscErrorCode, prefer PetscCallCXX() instead 976 PetscCallCXXAbort(PETSC_COMM_SELF, v.emplace_back(1)); 977 PetscFunctionReturn(PETSC_SUCCESS); 978 } 979 .ve 980 981 .seealso: `PetscCallCXX()`, `SETERRABORT()`, `PetscCallAbort()` 982 M*/ 983 #define PetscCallCXXAbort(comm, ...) PetscCallCXX_Private(SETERRABORT, comm, __VA_ARGS__) 984 985 /*MC 986 CHKERRCXX - Checks C++ function calls and if they throw an exception, catch it and then 987 return a PETSc error code 988 989 Synopsis: 990 #include <petscerror.h> 991 void CHKERRCXX(func) noexcept; 992 993 Not Collective 994 995 Input Parameter: 996 . func - C++ function calls 997 998 Notes: 999 Deprecated in favor of `PetscCallCXX()`. This routine behaves identically to it. 1000 1001 Level: deprecated 1002 1003 .seealso: `PetscCallCXX()` 1004 M*/ 1005 #define CHKERRCXX(...) PetscCallCXX(__VA_ARGS__) 1006 1007 /*MC 1008 CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected 1009 1010 Synopsis: 1011 #include <petscsys.h> 1012 CHKMEMQ; 1013 1014 Not Collective 1015 1016 Level: beginner 1017 1018 Notes: 1019 We highly recommend using Valgrind https://petsc.org/release/faq/#valgrind or for NVIDIA CUDA systems 1020 https://docs.nvidia.com/cuda/cuda-memcheck/index.html for finding memory problems. The ``CHKMEMQ`` macro is useful on systems that 1021 do not have valgrind, but is not as good as valgrind or cuda-memcheck. 1022 1023 Must run with the option -malloc_debug (-malloc_test in debug mode; or if `PetscMallocSetDebug()` called) to enable this option 1024 1025 Once the error handler is called the calling function is then returned from with the given error code. 1026 1027 By defaults prints location where memory that is corrupted was allocated. 1028 1029 Use `CHKMEMA` for functions that return void 1030 1031 .seealso: `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, `PetscError()`, `SETERRQ()`, `PetscMallocValidate()` 1032 M*/ 1033 #if defined(PETSC_CLANG_STATIC_ANALYZER) 1034 #define CHKMEMQ 1035 #define CHKMEMA 1036 #else 1037 #define CHKMEMQ \ 1038 do { \ 1039 PetscErrorCode ierr_petsc_memq_ = PetscMallocValidate(__LINE__, PETSC_FUNCTION_NAME, __FILE__); \ 1040 if (PetscUnlikely(ierr_petsc_memq_ != PETSC_SUCCESS)) return PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr_petsc_memq_, PETSC_ERROR_REPEAT, " "); \ 1041 } while (0) 1042 #define CHKMEMA PetscMallocValidate(__LINE__, PETSC_FUNCTION_NAME, __FILE__) 1043 #endif 1044 1045 /*E 1046 PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers 1047 1048 Level: advanced 1049 1050 `PETSC_ERROR_IN_CXX` indicates the error was detected in C++ and an exception should be generated 1051 1052 Developer Notes: 1053 This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler() 1054 1055 .seealso: `PetscError()`, `SETERRQ()` 1056 E*/ 1057 typedef enum { 1058 PETSC_ERROR_INITIAL = 0, 1059 PETSC_ERROR_REPEAT = 1, 1060 PETSC_ERROR_IN_CXX = 2 1061 } PetscErrorType; 1062 1063 #if defined(__clang_analyzer__) 1064 __attribute__((analyzer_noreturn)) 1065 #endif 1066 PETSC_EXTERN PetscErrorCode 1067 PetscError(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, ...) PETSC_ATTRIBUTE_COLD PETSC_ATTRIBUTE_FORMAT(7, 8); 1068 1069 PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void); 1070 PETSC_EXTERN PetscErrorCode PetscErrorMessage(PetscErrorCode, const char *[], char **); 1071 PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD; 1072 PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD; 1073 PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD; 1074 PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD; 1075 PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD; 1076 PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD; 1077 PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *) PETSC_ATTRIBUTE_COLD; 1078 PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm, int, const char *, const char *, PetscErrorCode, PetscErrorType, const char *, void *), void *); 1079 PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void); 1080 PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int, void *); 1081 PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int, void *), void *); 1082 PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void); 1083 PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt); 1084 PETSC_EXTERN void PetscSignalSegvCheckPointerOrMpi(void); 1085 PETSC_DEPRECATED_FUNCTION("Use PetscSignalSegvCheckPointerOrMpi() (since version 3.13)") static inline void PetscSignalSegvCheckPointer(void) 1086 { 1087 PetscSignalSegvCheckPointerOrMpi(); 1088 } 1089 1090 /*MC 1091 PetscErrorPrintf - Prints error messages. 1092 1093 Not Collective; No Fortran Support 1094 1095 Synopsis: 1096 #include <petscsys.h> 1097 PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 1098 1099 Input Parameter: 1100 . format - the usual `printf()` format string 1101 1102 Options Database Keys: 1103 + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr 1104 - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.) 1105 1106 Level: developer 1107 1108 Notes: 1109 Use 1110 $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 1111 $ error is handled.) and 1112 $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function 1113 1114 Use 1115 `PETSC_STDERR` = FILE* obtained from a file open etc. to have stderr printed to the file. 1116 `PETSC_STDOUT` = FILE* obtained from a file open etc. to have stdout printed to the file. 1117 1118 Use 1119 `PetscPushErrorHandler()` to provide your own error handler that determines what kind of messages to print 1120 1121 .seealso: `PetscFPrintf()`, `PetscSynchronizedPrintf()`, `PetscHelpPrintf()`, `PetscPrintf()`, `PetscPushErrorHandler()`, `PetscVFPrintf()`, `PetscHelpPrintf()` 1122 M*/ 1123 PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[], ...) PETSC_ATTRIBUTE_FORMAT(1, 2); 1124 1125 /*E 1126 PetscFPTrap - types of floating point exceptions that may be trapped 1127 1128 Currently only `PETSC_FP_TRAP_OFF` and `PETSC_FP_TRAP_ON` are handled. All others are treated as `PETSC_FP_TRAP_ON`. 1129 1130 Level: intermediate 1131 1132 .seealso: `PetscSetFPTrap()`, `PetscPushFPTrap()` 1133 E*/ 1134 typedef enum { 1135 PETSC_FP_TRAP_OFF = 0, 1136 PETSC_FP_TRAP_INDIV = 1, 1137 PETSC_FP_TRAP_FLTOPERR = 2, 1138 PETSC_FP_TRAP_FLTOVF = 4, 1139 PETSC_FP_TRAP_FLTUND = 8, 1140 PETSC_FP_TRAP_FLTDIV = 16, 1141 PETSC_FP_TRAP_FLTINEX = 32 1142 } PetscFPTrap; 1143 #define PETSC_FP_TRAP_ON (PetscFPTrap)(PETSC_FP_TRAP_INDIV | PETSC_FP_TRAP_FLTOPERR | PETSC_FP_TRAP_FLTOVF | PETSC_FP_TRAP_FLTDIV | PETSC_FP_TRAP_FLTINEX) 1144 PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap); 1145 PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap); 1146 PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void); 1147 PETSC_EXTERN PetscErrorCode PetscDetermineInitialFPTrap(void); 1148 1149 /* 1150 Allows the code to build a stack frame as it runs 1151 */ 1152 1153 #define PETSCSTACKSIZE 64 1154 typedef struct { 1155 const char *function[PETSCSTACKSIZE]; 1156 const char *file[PETSCSTACKSIZE]; 1157 int line[PETSCSTACKSIZE]; 1158 int petscroutine[PETSCSTACKSIZE]; /* 0 external called from petsc, 1 petsc functions, 2 petsc user functions */ 1159 int currentsize; 1160 int hotdepth; 1161 PetscBool check; /* option to check for correct Push/Pop semantics, true for default petscstack but not other stacks */ 1162 } PetscStack; 1163 #if defined(PETSC_USE_DEBUG) && !defined(PETSC_HAVE_THREADSAFETY) 1164 PETSC_EXTERN PetscStack petscstack; 1165 #endif 1166 1167 #if defined(PETSC_SERIALIZE_FUNCTIONS) 1168 #include <petsc/private/petscfptimpl.h> 1169 /* 1170 Registers the current function into the global function pointer to function name table 1171 1172 Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc 1173 */ 1174 #define PetscRegister__FUNCT__() \ 1175 do { \ 1176 static PetscBool __chked = PETSC_FALSE; \ 1177 if (!__chked) { \ 1178 void *ptr; \ 1179 PetscCallAbort(PETSC_COMM_SELF, PetscDLSym(NULL, PETSC_FUNCTION_NAME, &ptr)); \ 1180 __chked = PETSC_TRUE; \ 1181 } \ 1182 } while (0) 1183 #else 1184 #define PetscRegister__FUNCT__() 1185 #endif 1186 1187 #if defined(PETSC_CLANG_STATIC_ANALYZER) 1188 #define PetscStackPushNoCheck(funct, petsc_routine, hot) 1189 #define PetscStackUpdateLine 1190 #define PetscStackPushExternal(funct) 1191 #define PetscStackPopNoCheck 1192 #define PetscStackClearTop 1193 #define PetscFunctionBegin 1194 #define PetscFunctionBeginUser 1195 #define PetscFunctionBeginHot 1196 #define PetscFunctionReturn(...) return __VA_ARGS__ 1197 #define PetscFunctionReturnVoid() return 1198 #define PetscStackPop 1199 #define PetscStackPush(f) 1200 #elif defined(PETSC_USE_DEBUG) && !defined(PETSC_HAVE_THREADSAFETY) 1201 1202 #define PetscStackPush_Private(stack__, file__, func__, line__, petsc_routine__, hot__) \ 1203 do { \ 1204 if (stack__.currentsize < PETSCSTACKSIZE) { \ 1205 stack__.function[stack__.currentsize] = func__; \ 1206 if (petsc_routine__) { \ 1207 stack__.file[stack__.currentsize] = file__; \ 1208 stack__.line[stack__.currentsize] = line__; \ 1209 } else { \ 1210 stack__.file[stack__.currentsize] = PETSC_NULLPTR; \ 1211 stack__.line[stack__.currentsize] = 0; \ 1212 } \ 1213 stack__.petscroutine[stack__.currentsize] = petsc_routine__; \ 1214 } \ 1215 ++stack__.currentsize; \ 1216 stack__.hotdepth += (hot__ || stack__.hotdepth); \ 1217 } while (0) 1218 1219 /* uses PetscCheckAbort() because may be used in a function that does not return an error code */ 1220 #define PetscStackPop_Private(stack__, func__) \ 1221 do { \ 1222 PetscCheckAbort(!stack__.check || stack__.currentsize > 0, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid stack size %d, pop %s %s:%d.\n", stack__.currentsize, func__, __FILE__, __LINE__); \ 1223 if (--stack__.currentsize < PETSCSTACKSIZE) { \ 1224 PetscCheckAbort(!stack__.check || stack__.petscroutine[stack__.currentsize] != 1 || stack__.function[stack__.currentsize] == (const char *)(func__), PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid stack: push from %s %s:%d. Pop from %s %s:%d.\n", \ 1225 stack__.function[stack__.currentsize], stack__.file[stack__.currentsize], stack__.line[stack__.currentsize], func__, __FILE__, __LINE__); \ 1226 stack__.function[stack__.currentsize] = PETSC_NULLPTR; \ 1227 stack__.file[stack__.currentsize] = PETSC_NULLPTR; \ 1228 stack__.line[stack__.currentsize] = 0; \ 1229 stack__.petscroutine[stack__.currentsize] = 0; \ 1230 } \ 1231 stack__.hotdepth = PetscMax(stack__.hotdepth - 1, 0); \ 1232 } while (0) 1233 1234 /*MC 1235 PetscStackPushNoCheck - Pushes a new function name and line number onto the PETSc default stack that tracks where the running program is 1236 currently in the source code. 1237 1238 Not Collective 1239 1240 Synopsis: 1241 #include <petscsys.h> 1242 void PetscStackPushNoCheck(char *funct,int petsc_routine,PetscBool hot); 1243 1244 Input Parameters: 1245 + funct - the function name 1246 . petsc_routine - 2 user function, 1 PETSc function, 0 some other function 1247 - hot - indicates that the function may be called often so expensive error checking should be turned off inside the function 1248 1249 Level: developer 1250 1251 Notes: 1252 In debug mode PETSc maintains a stack of the current function calls that can be used to help to quickly see where a problem has 1253 occurred, for example, when a signal is received without running in the debugger. It is recommended to use the debugger if extensive information is needed to 1254 help debug the problem. 1255 1256 This version does not check the memory corruption (an expensive operation), use `PetscStackPush()` to check the memory. 1257 1258 Use `PetscStackPushExternal()` for a function call that is about to be made to a non-PETSc or user function (such as BLAS etc). 1259 1260 The default stack is a global variable called `petscstack`. 1261 1262 .seealso: `PetscAttachDebugger()`, `PetscStackCopy()`, `PetscStackView()`, `PetscStackPopNoCheck()`, `PetscCall()`, `PetscFunctionBegin()`, 1263 `PetscFunctionReturn()`, `PetscFunctionBeginHot()`, `PetscFunctionBeginUser()`, `PetscStackPush()`, `PetscStackPop`, 1264 `PetscStackPushExternal()` 1265 M*/ 1266 #define PetscStackPushNoCheck(funct, petsc_routine, hot) \ 1267 do { \ 1268 PetscStackSAWsTakeAccess(); \ 1269 PetscStackPush_Private(petscstack, __FILE__, funct, __LINE__, petsc_routine, hot); \ 1270 PetscStackSAWsGrantAccess(); \ 1271 } while (0) 1272 1273 /*MC 1274 PetscStackUpdateLine - in a function that has a `PetscFunctionBegin` or `PetscFunctionBeginUser` updates the stack line number to the 1275 current line number. 1276 1277 Not Collective 1278 1279 Synopsis: 1280 #include <petscsys.h> 1281 void PetscStackUpdateLine 1282 1283 Level: developer 1284 1285 Notes: 1286 Using `PetscCall()` and friends automatically handles this process 1287 1288 In debug mode PETSc maintains a stack of the current function calls that can be used to help to quickly see where a problem has 1289 occurred, for example, when a signal is received. It is recommended to use the debugger if extensive information is needed to 1290 help debug the problem. 1291 1292 The default stack is a global variable called petscstack. 1293 1294 This is used by `PetscCall()` and is otherwise not like to be needed 1295 1296 .seealso: `PetscAttachDebugger()`, `PetscStackCopy()`, `PetscStackView()`, `PetscStackPushNoCheck()`, `PetscStackPop`, `PetscCall()` 1297 M*/ 1298 #define PetscStackUpdateLine \ 1299 do { \ 1300 if (petscstack.currentsize > 0 && petscstack.function[petscstack.currentsize - 1] == PETSC_FUNCTION_NAME) { petscstack.line[petscstack.currentsize - 1] = __LINE__; } \ 1301 } while (0) 1302 1303 /*MC 1304 PetscStackPushExternal - Pushes a new function name onto the PETSc default stack that tracks where the running program is 1305 currently in the source code. Does not include the filename or line number since this is called by the calling routine 1306 for non-PETSc or user functions. 1307 1308 Not Collective 1309 1310 Synopsis: 1311 #include <petscsys.h> 1312 void PetscStackPushExternal(char *funct); 1313 1314 Input Parameters: 1315 . funct - the function name 1316 1317 Level: developer 1318 1319 Notes: 1320 Using `PetscCallExternal()` and friends automatically handles this process 1321 1322 In debug mode PETSc maintains a stack of the current function calls that can be used to help to quickly see where a problem has 1323 occurred, for example, when a signal is received. It is recommended to use the debugger if extensive information is needed to 1324 help debug the problem. 1325 1326 The default stack is a global variable called `petscstack`. 1327 1328 This is to be used when calling an external package function such as a BLAS function. 1329 1330 This also updates the stack line number for the current stack function. 1331 1332 .seealso: `PetscAttachDebugger()`, `PetscStackCopy()`, `PetscStackView()`, `PetscStackPopNoCheck()`, `PetscCall()`, `PetscFunctionBegin()`, 1333 `PetscFunctionReturn()`, `PetscFunctionBeginHot()`, `PetscFunctionBeginUser()`, `PetscStackPushNoCheck()`, `PetscStackPop` 1334 M*/ 1335 #define PetscStackPushExternal(funct) \ 1336 do { \ 1337 PetscStackUpdateLine; \ 1338 PetscStackPushNoCheck(funct, 0, PETSC_TRUE); \ 1339 } while (0); 1340 1341 /*MC 1342 PetscStackPopNoCheck - Pops a function name from the PETSc default stack that tracks where the running program is 1343 currently in the source code. 1344 1345 Not Collective 1346 1347 Synopsis: 1348 #include <petscsys.h> 1349 void PetscStackPopNoCheck(char *funct); 1350 1351 Input Parameter: 1352 . funct - the function name 1353 1354 Level: developer 1355 1356 Notes: 1357 Using `PetscCall()`, `PetscCallExternal()`, `PetscCallBack()` and friends negates the need to call this 1358 1359 In debug mode PETSc maintains a stack of the current function calls that can be used to help to quickly see where a problem has 1360 occurred, for example, when a signal is received. It is recommended to use the debugger if extensive information is needed to 1361 help debug the problem. 1362 1363 The default stack is a global variable called petscstack. 1364 1365 Developer Note: 1366 `PetscStackPopNoCheck()` takes a function argument while `PetscStackPop` does not, this difference is likely just historical. 1367 1368 .seealso: `PetscAttachDebugger()`, `PetscStackCopy()`, `PetscStackView()`, `PetscStackPushNoCheck()`, `PetscStackPop` 1369 M*/ 1370 #define PetscStackPopNoCheck(funct) \ 1371 do { \ 1372 PetscStackSAWsTakeAccess(); \ 1373 PetscStackPop_Private(petscstack, funct); \ 1374 PetscStackSAWsGrantAccess(); \ 1375 } while (0) 1376 1377 #define PetscStackClearTop \ 1378 do { \ 1379 PetscStackSAWsTakeAccess(); \ 1380 if (petscstack.currentsize > 0 && --petscstack.currentsize < PETSCSTACKSIZE) { \ 1381 petscstack.function[petscstack.currentsize] = PETSC_NULLPTR; \ 1382 petscstack.file[petscstack.currentsize] = PETSC_NULLPTR; \ 1383 petscstack.line[petscstack.currentsize] = 0; \ 1384 petscstack.petscroutine[petscstack.currentsize] = 0; \ 1385 } \ 1386 petscstack.hotdepth = PetscMax(petscstack.hotdepth - 1, 0); \ 1387 PetscStackSAWsGrantAccess(); \ 1388 } while (0) 1389 1390 /*MC 1391 PetscFunctionBegin - First executable line of each PETSc function, used for error handling. Final 1392 line of PETSc functions should be `PetscFunctionReturn`(0); 1393 1394 Synopsis: 1395 #include <petscsys.h> 1396 void PetscFunctionBegin; 1397 1398 Not Collective 1399 1400 Usage: 1401 .vb 1402 int something; 1403 1404 PetscFunctionBegin; 1405 .ve 1406 1407 Notes: 1408 Use `PetscFunctionBeginUser` for application codes. 1409 1410 Not available in Fortran 1411 1412 Level: developer 1413 1414 .seealso: `PetscFunctionReturn()`, `PetscFunctionBeginHot()`, `PetscFunctionBeginUser()`, `PetscStackPushNoCheck()` 1415 1416 M*/ 1417 #define PetscFunctionBegin \ 1418 do { \ 1419 PetscStackPushNoCheck(PETSC_FUNCTION_NAME, 1, PETSC_FALSE); \ 1420 PetscRegister__FUNCT__(); \ 1421 } while (0) 1422 1423 /*MC 1424 PetscFunctionBeginHot - Substitute for `PetscFunctionBegin` to be used in functions that are called in 1425 performance-critical circumstances. Use of this function allows for lighter profiling by default. 1426 1427 Synopsis: 1428 #include <petscsys.h> 1429 void PetscFunctionBeginHot; 1430 1431 Not Collective 1432 1433 Usage: 1434 .vb 1435 int something; 1436 1437 PetscFunctionBeginHot; 1438 .ve 1439 1440 Notes: 1441 Not available in Fortran 1442 1443 Level: developer 1444 1445 .seealso: `PetscFunctionBegin`, `PetscFunctionReturn()`, `PetscStackPushNoCheck()` 1446 1447 M*/ 1448 #define PetscFunctionBeginHot \ 1449 do { \ 1450 PetscStackPushNoCheck(PETSC_FUNCTION_NAME, 1, PETSC_TRUE); \ 1451 PetscRegister__FUNCT__(); \ 1452 } while (0) 1453 1454 /*MC 1455 PetscFunctionBeginUser - First executable line of user provided routines 1456 1457 Synopsis: 1458 #include <petscsys.h> 1459 void PetscFunctionBeginUser; 1460 1461 Not Collective 1462 1463 Usage: 1464 .vb 1465 int something; 1466 1467 PetscFunctionBeginUser; 1468 .ve 1469 1470 Notes: 1471 Functions that incorporate this must call `PetscFunctionReturn()` instead of return except for main(). 1472 1473 May be used before `PetscInitialize()` 1474 1475 Not available in Fortran 1476 1477 This is identical to `PetscFunctionBegin` except it labels the routine as a user 1478 routine instead of as a PETSc library routine. 1479 1480 Level: intermediate 1481 1482 .seealso: `PetscFunctionReturn()`, `PetscFunctionBegin`, `PetscFunctionBeginHot`, `PetscStackPushNoCheck()` 1483 1484 M*/ 1485 #define PetscFunctionBeginUser \ 1486 do { \ 1487 PetscStackPushNoCheck(PETSC_FUNCTION_NAME, 2, PETSC_FALSE); \ 1488 PetscRegister__FUNCT__(); \ 1489 } while (0) 1490 1491 /*MC 1492 PetscStackPush - Pushes a new function name and line number onto the PETSc default stack that tracks where the running program is 1493 currently in the source code and verifies the memory is not corrupted. 1494 1495 Not Collective 1496 1497 Synopsis: 1498 #include <petscsys.h> 1499 void PetscStackPush(char *funct) 1500 1501 Input Parameter: 1502 . funct - the function name 1503 1504 Level: developer 1505 1506 Notes: 1507 In debug mode PETSc maintains a stack of the current function calls that can be used to help to quickly see where a problem has 1508 occurred, for example, when a signal is received. It is recommended to use the debugger if extensive information is needed to 1509 help debug the problem. 1510 1511 The default stack is a global variable called petscstack. 1512 1513 .seealso: `PetscAttachDebugger()`, `PetscStackCopy()`, `PetscStackView()`, `PetscStackPopNoCheck()`, `PetscCall()`, `PetscFunctionBegin()`, 1514 `PetscFunctionReturn()`, `PetscFunctionBeginHot()`, `PetscFunctionBeginUser()`, `PetscStackPushNoCheck()`, `PetscStackPop` 1515 M*/ 1516 #define PetscStackPush(n) \ 1517 do { \ 1518 PetscStackPushNoCheck(n, 0, PETSC_FALSE); \ 1519 CHKMEMQ; \ 1520 } while (0) 1521 1522 /*MC 1523 PetscStackPop - Pops a function name from the PETSc default stack that tracks where the running program is 1524 currently in the source code and verifies the memory is not corrupted. 1525 1526 Not Collective 1527 1528 Synopsis: 1529 #include <petscsys.h> 1530 void PetscStackPop 1531 1532 Level: developer 1533 1534 Notes: 1535 In debug mode PETSc maintains a stack of the current function calls that can be used to help to quickly see where a problem has 1536 occurred, for example, when a signal is received. It is recommended to use the debugger if extensive information is needed to 1537 help debug the problem. 1538 1539 The default stack is a global variable called petscstack. 1540 1541 .seealso: `PetscAttachDebugger()`, `PetscStackCopy()`, `PetscStackView()`, `PetscStackPushNoCheck()`, `PetscStackPopNoCheck()`, `PetscStackPush()` 1542 M*/ 1543 #define PetscStackPop \ 1544 do { \ 1545 CHKMEMQ; \ 1546 PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \ 1547 } while (0) 1548 1549 /*MC 1550 PetscFunctionReturn - Last executable line of each PETSc function used for error 1551 handling. Replaces `return()`. 1552 1553 Synopsis: 1554 #include <petscerror.h> 1555 void PetscFunctionReturn(...) 1556 1557 Not Collective 1558 1559 Level: beginner 1560 1561 Notes: 1562 This routine is a macro, so while it does not "return" anything itself, it does return from 1563 the function in the literal sense. 1564 1565 Usually the return value is the integer literal `0` (for example in any function returning 1566 `PetscErrorCode`), however it is possible to return any arbitrary type. The arguments of 1567 this macro are placed before the `return` statement as-is. 1568 1569 Any routine which returns via `PetscFunctionReturn()` must begin with a corresponding 1570 `PetscFunctionBegin`. 1571 1572 For routines which return `void` use `PetscFunctionReturnVoid()` instead. 1573 1574 Example Usage: 1575 .vb 1576 PetscErrorCode foo(int *x) 1577 { 1578 PetscFunctionBegin; // don't forget the begin! 1579 *x = 10; 1580 PetscFunctionReturn(PETSC_SUCCESS); 1581 } 1582 .ve 1583 1584 May return any arbitrary type\: 1585 .vb 1586 struct Foo 1587 { 1588 int x; 1589 }; 1590 1591 struct Foo make_foo(int value) 1592 { 1593 struct Foo f; 1594 1595 PetscFunctionBegin; 1596 f.x = value; 1597 PetscFunctionReturn(f); 1598 } 1599 .ve 1600 1601 Fortran Note: 1602 Not available in Fortran 1603 1604 .seealso: `PetscFunctionBegin`, `PetscFunctionBeginUser`, `PetscFunctionReturnVoid()`, 1605 `PetscStackPopNoCheck()` 1606 M*/ 1607 #define PetscFunctionReturn(...) \ 1608 do { \ 1609 PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \ 1610 return __VA_ARGS__; \ 1611 } while (0) 1612 1613 /*MC 1614 PetscFunctionReturnVoid - Like `PetscFunctionReturn()` but returns `void` 1615 1616 Synopsis: 1617 #include <petscerror.h> 1618 void PetscFunctionReturnVoid() 1619 1620 Not Collective 1621 1622 Level: beginner 1623 1624 Note: 1625 Behaves identically to `PetscFunctionReturn()` except that it returns `void`. That is, this 1626 macro culminates with `return`. 1627 1628 Example Usage: 1629 .vb 1630 void foo() 1631 { 1632 PetscFunctionBegin; // must start with PetscFunctionBegin! 1633 bar(); 1634 baz(); 1635 PetscFunctionReturnVoid(); 1636 } 1637 .ve 1638 1639 .seealso: `PetscFunctionReturn()`, `PetscFunctionBegin`, PetscFunctionBeginUser` 1640 M*/ 1641 #define PetscFunctionReturnVoid() \ 1642 do { \ 1643 PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \ 1644 return; \ 1645 } while (0) 1646 #else /* PETSC_USE_DEBUG */ 1647 #define PetscStackPushNoCheck(funct, petsc_routine, hot) 1648 #define PetscStackUpdateLine 1649 #define PetscStackPushExternal(funct) 1650 #define PetscStackPopNoCheck(...) 1651 #define PetscStackClearTop 1652 #define PetscFunctionBegin 1653 #define PetscFunctionBeginUser 1654 #define PetscFunctionBeginHot 1655 #define PetscFunctionReturn(...) return __VA_ARGS__ 1656 #define PetscFunctionReturnVoid() return 1657 #define PetscStackPop CHKMEMQ 1658 #define PetscStackPush(f) CHKMEMQ 1659 #endif /* PETSC_USE_DEBUG */ 1660 1661 #if defined(PETSC_CLANG_STATIC_ANALYZER) 1662 #define PetscStackCallExternalVoid(...) 1663 template <typename F, typename... Args> 1664 void PetscCallExternal(F, Args...); 1665 #else 1666 /*MC 1667 PetscStackCallExternalVoid - Calls an external library routine or user function after pushing the name of the routine on the stack. 1668 1669 Input Parameters: 1670 + name - string that gives the name of the function being called 1671 - routine - actual call to the routine, for example, functionname(a,b) 1672 1673 Level: developer 1674 1675 Note: 1676 Often one should use `PetscCallExternal()` instead. This routine is intended for external library routines that DO NOT return error codes 1677 1678 In debug mode this also checks the memory for corruption at the end of the function call. 1679 1680 Certain external packages, such as BLAS/LAPACK may have their own macros for managing the call, error checking, etc. 1681 1682 Developer Note: 1683 This is so that when a user or external library routine results in a crash or corrupts memory, they get blamed instead of PETSc. 1684 1685 .seealso: `PetscCall()`, `PetscStackPushNoCheck()`, `PetscStackPush()`, `PetscCallExternal()`, `PetscCallBLAS()` 1686 @*/ 1687 #define PetscStackCallExternalVoid(name, ...) \ 1688 do { \ 1689 PetscStackPush(name); \ 1690 __VA_ARGS__; \ 1691 PetscStackPop; \ 1692 } while (0) 1693 1694 /*MC 1695 PetscCallExternal - Calls an external library routine that returns an error code after pushing the name of the routine on the stack. 1696 1697 Input Parameters: 1698 + func- name of the routine 1699 - args - arguments to the routine 1700 1701 Level: developer 1702 1703 Notes: 1704 This is intended for external package routines that return error codes. Use `PetscStackCallExternalVoid()` for those that do not. 1705 1706 In debug mode this also checks the memory for corruption at the end of the function call. 1707 1708 Assumes the error return code of the function is an integer and that a value of 0 indicates success 1709 1710 Developer Note: 1711 This is so that when an external package routine results in a crash or corrupts memory, they get blamed instead of PETSc. 1712 1713 .seealso: `PetscCall()`, `PetscStackPushNoCheck()`, `PetscStackPush()`, `PetscStackCallExternalVoid()` 1714 M*/ 1715 #define PetscCallExternal(func, ...) \ 1716 do { \ 1717 PetscStackPush(PetscStringize(func)); \ 1718 int ierr_petsc_call_external_ = func(__VA_ARGS__); \ 1719 PetscStackPop; \ 1720 PetscCheck(ierr_petsc_call_external_ == 0, PETSC_COMM_SELF, PETSC_ERR_LIB, "Error in %s(): error code %d", PetscStringize(func), ierr_petsc_call_external_); \ 1721 } while (0) 1722 #endif /* PETSC_CLANG_STATIC_ANALYZER */ 1723 1724 #endif 1725