1 /* 2 Contains all error handling interfaces for PETSc. 3 */ 4 #if !defined(__PETSCERROR_H) 5 #define __PETSCERROR_H 6 7 /* 8 These are the generic error codes. These error codes are used 9 many different places in the PETSc source code. The string versions are 10 at src/sys/error/err.c any changes here must also be made there 11 These are also define in include/petsc/finclude/petscerror.h any CHANGES here 12 must be also made there. 13 14 */ 15 #define PETSC_ERR_MIN_VALUE 54 /* should always be one less then the smallest value */ 16 17 #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 18 #define PETSC_ERR_SUP 56 /* no support for requested operation */ 19 #define PETSC_ERR_SUP_SYS 57 /* no support for requested operation on this computer system */ 20 #define PETSC_ERR_ORDER 58 /* operation done in wrong order */ 21 #define PETSC_ERR_SIG 59 /* signal received */ 22 #define PETSC_ERR_FP 72 /* floating point exception */ 23 #define PETSC_ERR_COR 74 /* corrupted PETSc object */ 24 #define PETSC_ERR_LIB 76 /* error in library called by PETSc */ 25 #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */ 26 #define PETSC_ERR_MEMC 78 /* memory corruption */ 27 #define PETSC_ERR_CONV_FAILED 82 /* iterative method (KSP or SNES) failed */ 28 #define PETSC_ERR_USER 83 /* user has not provided needed function */ 29 #define PETSC_ERR_SYS 88 /* error in system call */ 30 #define PETSC_ERR_POINTER 70 /* pointer does not point to valid address */ 31 #define PETSC_ERR_MPI_LIB_INCOMP 87 /* MPI library at runtime is not compatible with MPI user compiled with */ 32 33 #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */ 34 #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */ 35 #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */ 36 #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */ 37 #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */ 38 #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */ 39 #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */ 40 #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */ 41 #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */ 42 #define PETSC_ERR_ARG_TYPENOTSET 89 /* the type of the object has not yet been set */ 43 #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ 44 #define PETSC_ERR_ARG_NULL 85 /* argument is null that should not be */ 45 #define PETSC_ERR_ARG_UNKNOWN_TYPE 86 /* type name doesn't match any registered type */ 46 47 #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ 48 #define PETSC_ERR_FILE_READ 66 /* unable to read from file */ 49 #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */ 50 #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */ 51 52 #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */ 53 #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */ 54 55 #define PETSC_ERR_INT_OVERFLOW 84 56 57 #define PETSC_ERR_FLOP_COUNT 90 58 #define PETSC_ERR_NOT_CONVERGED 91 /* solver did not converge */ 59 #define PETSC_ERR_MISSING_FACTOR 92 /* MatGetFactor() failed */ 60 #define PETSC_ERR_OPT_OVERWRITE 93 /* attempted to over wrote options which should not be changed */ 61 62 #define PETSC_ERR_MAX_VALUE 94 /* this is always the one more than the largest error code */ 63 64 #define PetscStringizeArg(a) #a 65 #define PetscStringize(a) PetscStringizeArg(a) 66 67 #if defined(PETSC_USE_ERRORCHECKING) 68 69 /*MC 70 SETERRQ - Macro to be called when an error has been detected, 71 72 Synopsis: 73 #include <petscsys.h> 74 PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message) 75 76 Collective on MPI_Comm 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: beginner 84 85 Notes: 86 Once the error handler is called the calling function is then returned from with the given error code. 87 88 See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments 89 90 In Fortran MPI_Abort() is always called 91 92 Experienced users can set the error handler with PetscPushErrorHandler(). 93 94 Concepts: error^setting condition 95 96 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3() 97 M*/ 98 #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s) 99 #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE) 100 101 /*MC 102 SETERRQ1 - Macro that is called when an error has been detected, 103 104 Synopsis: 105 #include <petscsys.h> 106 PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg) 107 108 Collective on MPI_Comm 109 110 Input Parameters: 111 + comm - A communicator, so that the error can be collective 112 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 113 . message - error message in the printf format 114 - arg - argument (for example an integer, string or double) 115 116 Level: beginner 117 118 Notes: 119 Once the error handler is called the calling function is then returned from with the given error code. 120 121 Experienced users can set the error handler with PetscPushErrorHandler(). 122 123 Concepts: error^setting condition 124 125 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3() 126 M*/ 127 #define SETERRQ1(comm,ierr,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1) 128 129 /*MC 130 SETERRQ2 - Macro that is called when an error has been detected, 131 132 Synopsis: 133 #include <petscsys.h> 134 PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2) 135 136 Collective on MPI_Comm 137 138 Input Parameters: 139 + comm - A communicator, so that the error can be collective 140 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 141 . message - error message in the printf format 142 . arg1 - argument (for example an integer, string or double) 143 - arg2 - argument (for example an integer, string or double) 144 145 Level: beginner 146 147 Notes: 148 Once the error handler is called the calling function is then returned from with the given error code. 149 150 Experienced users can set the error handler with PetscPushErrorHandler(). 151 152 Concepts: error^setting condition 153 154 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3() 155 M*/ 156 #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2) 157 158 /*MC 159 SETERRQ3 - Macro that is called when an error has been detected, 160 161 Synopsis: 162 #include <petscsys.h> 163 PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3) 164 165 Collective on MPI_Comm 166 167 Input Parameters: 168 + comm - A communicator, so that the error can be collective 169 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 170 . message - error message in the printf format 171 . arg1 - argument (for example an integer, string or double) 172 . arg2 - argument (for example an integer, string or double) 173 - arg3 - argument (for example an integer, string or double) 174 175 Level: beginner 176 177 Notes: 178 Once the error handler is called the calling function is then returned from with the given error code. 179 180 There are also versions for 4, 5, 6 and 7 arguments. 181 182 Experienced users can set the error handler with PetscPushErrorHandler(). 183 184 Concepts: error^setting condition 185 186 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 187 M*/ 188 #define SETERRQ3(comm,ierr,s,a1,a2,a3) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3) 189 190 /*MC 191 SETERRQ4 - Macro that is called when an error has been detected, 192 193 Synopsis: 194 #include <petscsys.h> 195 PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3) 196 197 Collective on MPI_Comm 198 199 Input Parameters: 200 + comm - A communicator, so that the error can be collective 201 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 202 . message - error message in the printf format 203 . arg1 - argument (for example an integer, string or double) 204 . arg2 - argument (for example an integer, string or double) 205 . arg3 - argument (for example an integer, string or double) 206 - arg4 - argument (for example an integer, string or double) 207 208 Level: beginner 209 210 Notes: 211 Once the error handler is called the calling function is then returned from with the given error code. 212 213 There are also versions for 4, 5, 6 and 7 arguments. 214 215 Experienced users can set the error handler with PetscPushErrorHandler(). 216 217 Concepts: error^setting condition 218 219 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 220 M*/ 221 #define SETERRQ4(comm,ierr,s,a1,a2,a3,a4) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4) 222 223 /*MC 224 SETERRQ5 - Macro that is called when an error has been detected, 225 226 Synopsis: 227 #include <petscsys.h> 228 PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3) 229 230 Collective on MPI_COmm 231 232 Input Parameters: 233 + comm - A communicator, so that the error can be collective 234 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 235 . message - error message in the printf format 236 . arg1 - argument (for example an integer, string or double) 237 . arg2 - argument (for example an integer, string or double) 238 . arg3 - argument (for example an integer, string or double) 239 . arg4 - argument (for example an integer, string or double) 240 - arg5 - argument (for example an integer, string or double) 241 242 Level: beginner 243 244 Notes: 245 Once the error handler is called the calling function is then returned from with the given error code. 246 247 There are also versions for 4, 5, 6 and 7 arguments. 248 249 Experienced users can set the error handler with PetscPushErrorHandler(). 250 251 Concepts: error^setting condition 252 253 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 254 M*/ 255 #define SETERRQ5(comm,ierr,s,a1,a2,a3,a4,a5) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5) 256 257 /*MC 258 SETERRQ6 - Macro that is called when an error has been detected, 259 260 Synopsis: 261 #include <petscsys.h> 262 PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3) 263 264 Collective on MPI_Comm 265 266 Input Parameters: 267 + comm - A communicator, so that the error can be collective 268 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 269 . message - error message in the printf format 270 . arg1 - argument (for example an integer, string or double) 271 . arg2 - argument (for example an integer, string or double) 272 . arg3 - argument (for example an integer, string or double) 273 . arg4 - argument (for example an integer, string or double) 274 . arg5 - argument (for example an integer, string or double) 275 - arg6 - argument (for example an integer, string or double) 276 277 Level: beginner 278 279 Notes: 280 Once the error handler is called the calling function is then returned from with the given error code. 281 282 There are also versions for 4, 5, 6 and 7 arguments. 283 284 Experienced users can set the error handler with PetscPushErrorHandler(). 285 286 Concepts: error^setting condition 287 288 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 289 M*/ 290 #define SETERRQ6(comm,ierr,s,a1,a2,a3,a4,a5,a6) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6) 291 292 /*MC 293 SETERRQ7 - Macro that is called when an error has been detected, 294 295 Synopsis: 296 #include <petscsys.h> 297 PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3) 298 299 Collective on MPI_Comm 300 301 Input Parameters: 302 + comm - A communicator, so that the error can be collective 303 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 304 . message - error message in the printf format 305 . arg1 - argument (for example an integer, string or double) 306 . arg2 - argument (for example an integer, string or double) 307 . arg3 - argument (for example an integer, string or double) 308 . arg4 - argument (for example an integer, string or double) 309 . arg5 - argument (for example an integer, string or double) 310 . arg6 - argument (for example an integer, string or double) 311 - arg7 - argument (for example an integer, string or double) 312 313 Level: beginner 314 315 Notes: 316 Once the error handler is called the calling function is then returned from with the given error code. 317 318 There are also versions for 4, 5, 6 and 7 arguments. 319 320 Experienced users can set the error handler with PetscPushErrorHandler(). 321 322 Concepts: error^setting condition 323 324 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 325 M*/ 326 #define SETERRQ7(comm,ierr,s,a1,a2,a3,a4,a5,a6,a7) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7) 327 328 /*MC 329 SETERRQ8 - Macro that is called when an error has been detected, 330 331 Synopsis: 332 #include <petscsys.h> 333 PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3) 334 335 Collective on MPI_Comm 336 337 Input Parameters: 338 + comm - A communicator, so that the error can be collective 339 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 340 . message - error message in the printf format 341 . arg1 - argument (for example an integer, string or double) 342 . arg2 - argument (for example an integer, string or double) 343 . arg3 - argument (for example an integer, string or double) 344 . arg4 - argument (for example an integer, string or double) 345 . arg5 - argument (for example an integer, string or double) 346 . arg6 - argument (for example an integer, string or double) 347 . arg7 - argument (for example an integer, string or double) 348 - arg8 - argument (for example an integer, string or double) 349 350 Level: beginner 351 352 Notes: 353 Once the error handler is called the calling function is then returned from with the given error code. 354 355 There are also versions for 4, 5, 6 and 7 arguments. 356 357 Experienced users can set the error handler with PetscPushErrorHandler(). 358 359 Concepts: error^setting condition 360 361 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 362 M*/ 363 #define SETERRQ8(comm,ierr,s,a1,a2,a3,a4,a5,a6,a7,a8) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7,a8) 364 365 /*MC 366 SETERRABORT - Macro that can be called when an error has been detected, 367 368 Synopsis: 369 #include <petscsys.h> 370 PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message) 371 372 Collective on MPI_Comm 373 374 Input Parameters: 375 + comm - A communicator, so that the error can be collective 376 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 377 - message - error message in the printf format 378 379 Level: beginner 380 381 Notes: 382 This function just calls MPI_Abort(). 383 384 Concepts: error^setting condition 385 386 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 387 M*/ 388 #define SETERRABORT(comm,ierr,s) do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,ierr);} while (0) 389 390 /*MC 391 CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns 392 393 Synopsis: 394 #include <petscsys.h> 395 PetscErrorCode CHKERRQ(PetscErrorCode ierr) 396 397 Not Collective 398 399 Input Parameters: 400 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 401 402 Level: beginner 403 404 Notes: 405 Once the error handler is called the calling function is then returned from with the given error code. 406 407 Experienced users can set the error handler with PetscPushErrorHandler(). 408 409 CHKERRQ(ierr) is fundamentally a macro replacement for 410 if (ierr) return(PetscError(...,ierr,...)); 411 412 Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is 413 highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular, 414 it cannot be used in functions which return(void) or any other datatype. In these types of functions, 415 you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or 416 if (ierr) {PetscError(....); return(YourReturnType);} 417 where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have 418 MPI_Abort() returned immediately. 419 420 In Fortran MPI_Abort() is always called 421 422 Concepts: error^setting condition 423 424 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2() 425 M*/ 426 #define CHKERRQ(ierr) do {if (PetscUnlikely(ierr)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");} while (0) 427 #define CHKERRV(ierr) do {if (PetscUnlikely(ierr)) {ierr = PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");return;}} while(0) 428 #define CHKERRABORT(comm,ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");MPI_Abort(comm,ierr);}} while (0) 429 #define CHKERRCONTINUE(ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");}} while (0) 430 #define CHKERRMPI(ierr) do {if (PetscUnlikely(ierr)) return (PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," "),PETSC_MPI_ERROR_CODE);} while (0) 431 432 #ifdef PETSC_CLANGUAGE_CXX 433 434 /*MC 435 CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception 436 437 Synopsis: 438 #include <petscsys.h> 439 void CHKERRXX(PetscErrorCode ierr) 440 441 Not Collective 442 443 Input Parameters: 444 . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 445 446 Level: beginner 447 448 Notes: 449 Once the error handler throws a ??? exception. 450 451 You can use CHKERRV() which returns without an error code (bad idea since the error is ignored) 452 or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately. 453 454 Concepts: error^setting condition 455 456 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ 457 M*/ 458 #define CHKERRXX(ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_IN_CXX,0);}} while(0) 459 460 #endif 461 462 #define CHKERRCUDA(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUDA error %d",err);} while(0) 463 #define CHKERRCUBLAS(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUBLAS error %d",err);} while(0) 464 465 /*MC 466 CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected 467 468 Synopsis: 469 #include <petscsys.h> 470 CHKMEMQ; 471 472 Not Collective 473 474 Level: beginner 475 476 Notes: 477 We highly recommend using valgrind http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful 478 on systems that do not have valgrind, but much much less useful. 479 480 Must run with the option -malloc_debug to enable this option 481 482 Once the error handler is called the calling function is then returned from with the given error code. 483 484 By defaults prints location where memory that is corrupted was allocated. 485 486 Use CHKMEMA for functions that return void 487 488 Concepts: memory corruption 489 490 .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), 491 PetscMallocValidate() 492 M*/ 493 #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while(0) 494 495 #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__) 496 497 #else /* PETSC_USE_ERRORCHECKING */ 498 499 /* 500 These are defined to be empty for when error checking is turned off, with ./configure --with-errorchecking=0 501 */ 502 503 #define SETERRQ(c,ierr,s) 504 #define SETERRMPI(comm,ierr,s) 505 #define SETERRQ1(c,ierr,s,a1) 506 #define SETERRQ2(c,ierr,s,a1,a2) 507 #define SETERRQ3(c,ierr,s,a1,a2,a3) 508 #define SETERRQ4(c,ierr,s,a1,a2,a3,a4) 509 #define SETERRQ5(c,ierr,s,a1,a2,a3,a4,a5) 510 #define SETERRQ6(c,ierr,s,a1,a2,a3,a4,a5,a6) 511 #define SETERRQ7(c,ierr,s,a1,a2,a3,a4,a5,a6,a7) 512 #define SETERRQ8(c,ierr,s,a1,a2,a3,a4,a5,a6,a7,a8) 513 #define SETERRABORT(comm,ierr,s) 514 515 #define CHKERRQ(ierr) ; 516 #define CHKERRV(ierr) ; 517 #define CHKERRABORT(comm,n) ; 518 #define CHKERRCONTINUE(ierr) ; 519 #define CHKERRMPI(ierr) ; 520 #define CHKMEMQ ; 521 #define CHKERRCUDA(err) ; 522 #define CHKERRCUBLAS(err) ; 523 524 #ifdef PETSC_CLANGUAGE_CXX 525 #define CHKERRXX(ierr) ; 526 #endif 527 528 #endif /* PETSC_USE_ERRORCHECKING */ 529 530 /*E 531 PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers 532 533 Level: advanced 534 535 PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated 536 537 Developer Notes: 538 This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler() 539 540 .seealso: PetscError(), SETERRXX() 541 E*/ 542 typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType; 543 544 #if defined(__clang_analyzer__) 545 __attribute__((analyzer_noreturn)) 546 #endif 547 PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...); 548 549 PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void); 550 PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **); 551 PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 552 PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 553 PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 554 PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 555 PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 556 PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 557 PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 558 PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*); 559 PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void); 560 PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*); 561 PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*); 562 PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void); 563 PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt); 564 565 /*MC 566 PetscErrorPrintf - Prints error messages. 567 568 Synopsis: 569 #include <petscsys.h> 570 PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 571 572 Not Collective 573 574 Input Parameters: 575 . format - the usual printf() format string 576 577 Options Database Keys: 578 + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr 579 - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.) 580 581 Notes: 582 Use 583 $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 584 $ error is handled.) and 585 $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function 586 587 Use 588 PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file. 589 PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file. 590 591 Use 592 PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print 593 594 Level: developer 595 596 Fortran Note: 597 This routine is not supported in Fortran. 598 599 Concepts: error messages^printing 600 Concepts: printing^error messages 601 602 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush(), PetscVFPrintf(), PetscHelpPrintf() 603 M*/ 604 PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...); 605 606 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 607 PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap); 608 PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap); 609 PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void); 610 611 /* 612 Allows the code to build a stack frame as it runs 613 */ 614 615 #define PETSCSTACKSIZE 64 616 617 typedef struct { 618 const char *function[PETSCSTACKSIZE]; 619 const char *file[PETSCSTACKSIZE]; 620 int line[PETSCSTACKSIZE]; 621 PetscBool petscroutine[PETSCSTACKSIZE]; 622 int currentsize; 623 int hotdepth; 624 } PetscStack; 625 626 PETSC_EXTERN PetscStack *petscstack; 627 628 PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*); 629 PetscErrorCode PetscStackPrint(PetscStack *,FILE*); 630 #if defined(PETSC_SERIALIZE_FUNCTIONS) 631 #include <petsc/private/petscfptimpl.h> 632 /* 633 Registers the current function into the global function pointer to function name table 634 635 Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc 636 */ 637 #define PetscRegister__FUNCT__() do { \ 638 static PetscBool __chked = PETSC_FALSE; \ 639 if (!__chked) {\ 640 void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\ 641 __chked = PETSC_TRUE;\ 642 }} while (0) 643 #else 644 #define PetscRegister__FUNCT__() 645 #endif 646 647 #if defined(PETSC_USE_DEBUG) 648 PETSC_STATIC_INLINE PetscBool PetscStackActive(void) 649 { 650 return(petscstack ? PETSC_TRUE : PETSC_FALSE); 651 } 652 653 /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error 654 * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at 655 * least more useful than "unknown" because it can distinguish multiple calls from the same function. 656 */ 657 658 #define PetscStackPushNoCheck(funct,petsc_routine,hot) \ 659 do { \ 660 PetscStackSAWsTakeAccess(); \ 661 if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 662 petscstack->function[petscstack->currentsize] = funct; \ 663 petscstack->file[petscstack->currentsize] = __FILE__; \ 664 petscstack->line[petscstack->currentsize] = __LINE__; \ 665 petscstack->petscroutine[petscstack->currentsize] = petsc_routine; \ 666 petscstack->currentsize++; \ 667 } \ 668 if (petscstack) { \ 669 petscstack->hotdepth += (hot || petscstack->hotdepth); \ 670 } \ 671 PetscStackSAWsGrantAccess(); \ 672 } while (0) 673 674 #define PetscStackPopNoCheck \ 675 do { \ 676 PetscStackSAWsTakeAccess(); \ 677 if (petscstack && petscstack->currentsize > 0) { \ 678 petscstack->currentsize--; \ 679 petscstack->function[petscstack->currentsize] = 0; \ 680 petscstack->file[petscstack->currentsize] = 0; \ 681 petscstack->line[petscstack->currentsize] = 0; \ 682 petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\ 683 } \ 684 if (petscstack) { \ 685 petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0); \ 686 } \ 687 PetscStackSAWsGrantAccess(); \ 688 } while (0) 689 690 /*MC 691 PetscFunctionBegin - First executable line of each PETSc function, used for error handling. Final 692 line of PETSc functions should be PetscFunctionReturn(0); 693 694 Synopsis: 695 #include <petscsys.h> 696 void PetscFunctionBegin; 697 698 Not Collective 699 700 Usage: 701 .vb 702 int something; 703 704 PetscFunctionBegin; 705 .ve 706 707 Notes: 708 Use PetscFunctionBeginUser for application codes. 709 710 Not available in Fortran 711 712 Level: developer 713 714 .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser() 715 716 .keywords: traceback, error handling 717 M*/ 718 #define PetscFunctionBegin do { \ 719 PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \ 720 PetscRegister__FUNCT__(); \ 721 } while (0) 722 723 /*MC 724 PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in 725 performance-critical circumstances. Use of this function allows for lighter profiling by default. 726 727 Synopsis: 728 #include <petscsys.h> 729 void PetscFunctionBeginHot; 730 731 Not Collective 732 733 Usage: 734 .vb 735 int something; 736 737 PetscFunctionBeginHot; 738 .ve 739 740 Notes: 741 Not available in Fortran 742 743 Level: developer 744 745 .seealso: PetscFunctionBegin, PetscFunctionReturn() 746 747 .keywords: traceback, error handling 748 M*/ 749 #define PetscFunctionBeginHot do { \ 750 PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE); \ 751 PetscRegister__FUNCT__(); \ 752 } while (0) 753 754 /*MC 755 PetscFunctionBeginUser - First executable line of user provided PETSc routine 756 757 Synopsis: 758 #include <petscsys.h> 759 void PetscFunctionBeginUser; 760 761 Not Collective 762 763 Usage: 764 .vb 765 int something; 766 767 PetscFunctionBeginUser; 768 .ve 769 770 Notes: 771 Final line of PETSc functions should be PetscFunctionReturn(0) except for main(). 772 773 Not available in Fortran 774 775 This is identical to PetscFunctionBegin except it labels the routine as a user 776 routine instead of as a PETSc library routine. 777 778 Level: intermediate 779 780 .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot 781 782 .keywords: traceback, error handling 783 M*/ 784 #define PetscFunctionBeginUser \ 785 do { \ 786 PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \ 787 PetscRegister__FUNCT__(); \ 788 } while (0) 789 790 791 #define PetscStackPush(n) \ 792 do { \ 793 PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE); \ 794 CHKMEMQ; \ 795 } while (0) 796 797 #define PetscStackPop \ 798 do { \ 799 CHKMEMQ; \ 800 PetscStackPopNoCheck; \ 801 } while (0) 802 803 /*MC 804 PetscFunctionReturn - Last executable line of each PETSc function 805 used for error handling. Replaces return() 806 807 Synopsis: 808 #include <petscsys.h> 809 void PetscFunctionReturn(0); 810 811 Not Collective 812 813 Usage: 814 .vb 815 .... 816 PetscFunctionReturn(0); 817 } 818 .ve 819 820 Notes: 821 Not available in Fortran 822 823 Level: developer 824 825 .seealso: PetscFunctionBegin() 826 827 .keywords: traceback, error handling 828 M*/ 829 #define PetscFunctionReturn(a) \ 830 do { \ 831 PetscStackPopNoCheck; \ 832 return(a);} while (0) 833 834 #define PetscFunctionReturnVoid() \ 835 do { \ 836 PetscStackPopNoCheck; \ 837 return;} while (0) 838 839 #else 840 841 PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;} 842 #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0) 843 #define PetscStackPopNoCheck do {} while (0) 844 #define PetscFunctionBegin 845 #define PetscFunctionBeginUser 846 #define PetscFunctionBeginHot 847 #define PetscFunctionReturn(a) return(a) 848 #define PetscFunctionReturnVoid() return 849 #define PetscStackPop CHKMEMQ 850 #define PetscStackPush(f) CHKMEMQ 851 852 #endif 853 854 /* 855 PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack. 856 857 Input Parameters: 858 + name - string that gives the name of the function being called 859 - routine - actual call to the routine, including ierr = and CHKERRQ(ierr); 860 861 Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes 862 863 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. 864 865 866 867 */ 868 #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while(0) 869 870 /* 871 PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack. 872 873 Input Parameters: 874 + func- name of the routine 875 - args - arguments to the routine surrounded by () 876 877 Notes: 878 This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not. 879 880 Developer Note: this is so that when an external packge routine results in a crash or corrupts memory, they get blamed instead of PETSc. 881 882 */ 883 #define PetscStackCallStandard(func,args) do { \ 884 PetscStackPush(#func);ierr = func args;PetscStackPop; if (ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)ierr); \ 885 } while (0) 886 887 PETSC_EXTERN PetscErrorCode PetscStackCreate(void); 888 PETSC_EXTERN PetscErrorCode PetscStackView(FILE*); 889 PETSC_EXTERN PetscErrorCode PetscStackDestroy(void); 890 891 #endif 892