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 SETERRQ1(c,ierr,s,a1) 505 #define SETERRQ2(c,ierr,s,a1,a2) 506 #define SETERRQ3(c,ierr,s,a1,a2,a3) 507 #define SETERRQ4(c,ierr,s,a1,a2,a3,a4) 508 #define SETERRQ5(c,ierr,s,a1,a2,a3,a4,a5) 509 #define SETERRQ6(c,ierr,s,a1,a2,a3,a4,a5,a6) 510 #define SETERRQ7(c,ierr,s,a1,a2,a3,a4,a5,a6,a7) 511 #define SETERRQ8(c,ierr,s,a1,a2,a3,a4,a5,a6,a7,a8) 512 #define SETERRABORT(comm,ierr,s) 513 514 #define CHKERRQ(ierr) ; 515 #define CHKERRV(ierr) ; 516 #define CHKERRABORT(comm,n) ; 517 #define CHKERRCONTINUE(ierr) ; 518 #define CHKMEMQ ; 519 #define CHKERRCUDA(err) ; 520 #define CHKERRCUBLAS(err) ; 521 522 #ifdef PETSC_CLANGUAGE_CXX 523 #define CHKERRXX(ierr) ; 524 #endif 525 526 #endif /* PETSC_USE_ERRORCHECKING */ 527 528 /*E 529 PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers 530 531 Level: advanced 532 533 PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated 534 535 Developer Notes: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler() 536 537 .seealso: PetscError(), SETERRXX() 538 E*/ 539 typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType; 540 541 #if defined(__clang_analyzer__) 542 __attribute__((analyzer_noreturn)) 543 #endif 544 PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...); 545 546 PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void); 547 PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **); 548 PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 549 PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 550 PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 551 PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 552 PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 553 PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 554 PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 555 PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*); 556 PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void); 557 PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*); 558 PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*); 559 PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void); 560 PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt); 561 562 /*MC 563 PetscErrorPrintf - Prints error messages. 564 565 Synopsis: 566 #include <petscsys.h> 567 PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 568 569 Not Collective 570 571 Input Parameters: 572 . format - the usual printf() format string 573 574 Options Database Keys: 575 + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr 576 - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.) 577 578 Notes: Use 579 $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 580 $ error is handled.) and 581 $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function 582 583 Use 584 PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file. 585 PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file. 586 587 Use 588 PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print 589 590 Level: developer 591 592 Fortran Note: 593 This routine is not supported in Fortran. 594 595 Concepts: error messages^printing 596 Concepts: printing^error messages 597 598 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush(), PetscVFPrintf(), PetscHelpPrintf() 599 M*/ 600 PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...); 601 602 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 603 PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap); 604 PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap); 605 PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void); 606 607 /* 608 Allows the code to build a stack frame as it runs 609 */ 610 611 #define PETSCSTACKSIZE 64 612 613 typedef struct { 614 const char *function[PETSCSTACKSIZE]; 615 const char *file[PETSCSTACKSIZE]; 616 int line[PETSCSTACKSIZE]; 617 PetscBool petscroutine[PETSCSTACKSIZE]; 618 int currentsize; 619 int hotdepth; 620 } PetscStack; 621 622 PETSC_EXTERN PetscStack *petscstack; 623 624 PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*); 625 PetscErrorCode PetscStackPrint(PetscStack *,FILE*); 626 #if defined(PETSC_SERIALIZE_FUNCTIONS) 627 #include <petsc/private/petscfptimpl.h> 628 /* 629 Registers the current function into the global function pointer to function name table 630 631 Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc 632 */ 633 #define PetscRegister__FUNCT__() do { \ 634 static PetscBool __chked = PETSC_FALSE; \ 635 if (!__chked) {\ 636 void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\ 637 __chked = PETSC_TRUE;\ 638 }} while (0) 639 #else 640 #define PetscRegister__FUNCT__() 641 #endif 642 643 #if defined(PETSC_USE_DEBUG) 644 PETSC_STATIC_INLINE PetscBool PetscStackActive(void) 645 { 646 return(petscstack ? PETSC_TRUE : PETSC_FALSE); 647 } 648 649 /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error 650 * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at 651 * least more useful than "unknown" because it can distinguish multiple calls from the same function. 652 */ 653 654 #define PetscStackPushNoCheck(funct,petsc_routine,hot) \ 655 do { \ 656 PetscStackSAWsTakeAccess(); \ 657 if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 658 petscstack->function[petscstack->currentsize] = funct; \ 659 petscstack->file[petscstack->currentsize] = __FILE__; \ 660 petscstack->line[petscstack->currentsize] = __LINE__; \ 661 petscstack->petscroutine[petscstack->currentsize] = petsc_routine; \ 662 petscstack->currentsize++; \ 663 } \ 664 if (petscstack) { \ 665 petscstack->hotdepth += (hot || petscstack->hotdepth); \ 666 } \ 667 PetscStackSAWsGrantAccess(); \ 668 } while (0) 669 670 #define PetscStackPopNoCheck \ 671 do { \ 672 PetscStackSAWsTakeAccess(); \ 673 if (petscstack && petscstack->currentsize > 0) { \ 674 petscstack->currentsize--; \ 675 petscstack->function[petscstack->currentsize] = 0; \ 676 petscstack->file[petscstack->currentsize] = 0; \ 677 petscstack->line[petscstack->currentsize] = 0; \ 678 petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\ 679 } \ 680 if (petscstack) { \ 681 petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0); \ 682 } \ 683 PetscStackSAWsGrantAccess(); \ 684 } while (0) 685 686 /*MC 687 PetscFunctionBegin - First executable line of each PETSc function, used for error handling. Final 688 line of PETSc functions should be PetscFunctionReturn(0); 689 690 Synopsis: 691 #include <petscsys.h> 692 void PetscFunctionBegin; 693 694 Not Collective 695 696 Usage: 697 .vb 698 int something; 699 700 PetscFunctionBegin; 701 .ve 702 703 Notes: 704 Use PetscFunctionBeginUser for application codes. 705 706 Not available in Fortran 707 708 Level: developer 709 710 .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser() 711 712 .keywords: traceback, error handling 713 M*/ 714 #define PetscFunctionBegin do { \ 715 PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \ 716 PetscRegister__FUNCT__(); \ 717 } while (0) 718 719 /*MC 720 PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in 721 performance-critical circumstances. Use of this function allows for lighter profiling by default. 722 723 Synopsis: 724 #include <petscsys.h> 725 void PetscFunctionBeginHot; 726 727 Not Collective 728 729 Usage: 730 .vb 731 int something; 732 733 PetscFunctionBeginHot; 734 .ve 735 736 Notes: 737 Not available in Fortran 738 739 Level: developer 740 741 .seealso: PetscFunctionBegin, PetscFunctionReturn() 742 743 .keywords: traceback, error handling 744 M*/ 745 #define PetscFunctionBeginHot do { \ 746 PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE); \ 747 PetscRegister__FUNCT__(); \ 748 } while (0) 749 750 /*MC 751 PetscFunctionBeginUser - First executable line of user provided PETSc routine 752 753 Synopsis: 754 #include <petscsys.h> 755 void PetscFunctionBeginUser; 756 757 Not Collective 758 759 Usage: 760 .vb 761 int something; 762 763 PetscFunctionBeginUser; 764 .ve 765 766 Notes: 767 Final line of PETSc functions should be PetscFunctionReturn(0) except for main(). 768 769 Not available in Fortran 770 771 This is identical to PetscFunctionBegin except it labels the routine as a user 772 routine instead of as a PETSc library routine. 773 774 Level: intermediate 775 776 .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot 777 778 .keywords: traceback, error handling 779 M*/ 780 #define PetscFunctionBeginUser \ 781 do { \ 782 PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \ 783 PetscRegister__FUNCT__(); \ 784 } while (0) 785 786 787 #define PetscStackPush(n) \ 788 do { \ 789 PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE); \ 790 CHKMEMQ; \ 791 } while (0) 792 793 #define PetscStackPop \ 794 do { \ 795 CHKMEMQ; \ 796 PetscStackPopNoCheck; \ 797 } while (0) 798 799 /*MC 800 PetscFunctionReturn - Last executable line of each PETSc function 801 used for error handling. Replaces return() 802 803 Synopsis: 804 #include <petscsys.h> 805 void PetscFunctionReturn(0); 806 807 Not Collective 808 809 Usage: 810 .vb 811 .... 812 PetscFunctionReturn(0); 813 } 814 .ve 815 816 Notes: 817 Not available in Fortran 818 819 Level: developer 820 821 .seealso: PetscFunctionBegin() 822 823 .keywords: traceback, error handling 824 M*/ 825 #define PetscFunctionReturn(a) \ 826 do { \ 827 PetscStackPopNoCheck; \ 828 return(a);} while (0) 829 830 #define PetscFunctionReturnVoid() \ 831 do { \ 832 PetscStackPopNoCheck; \ 833 return;} while (0) 834 835 #else 836 837 PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;} 838 #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0) 839 #define PetscStackPopNoCheck do {} while (0) 840 #define PetscFunctionBegin 841 #define PetscFunctionBeginUser 842 #define PetscFunctionBeginHot 843 #define PetscFunctionReturn(a) return(a) 844 #define PetscFunctionReturnVoid() return 845 #define PetscStackPop CHKMEMQ 846 #define PetscStackPush(f) CHKMEMQ 847 848 #endif 849 850 /* 851 PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack. 852 853 Input Parameters: 854 + name - string that gives the name of the function being called 855 - routine - actual call to the routine, including ierr = and CHKERRQ(ierr); 856 857 Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes 858 859 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. 860 861 862 863 */ 864 #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while(0) 865 866 /* 867 PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack. 868 869 Input Parameters: 870 + func- name of the routine 871 - args - arguments to the routine surrounded by () 872 873 Notes: This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not. 874 875 Developer Note: this is so that when an external packge routine results in a crash or corrupts memory, they get blamed instead of PETSc. 876 877 */ 878 #define PetscStackCallStandard(func,args) do { \ 879 PetscStackPush(#func);ierr = func args;PetscStackPop; if (ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)ierr); \ 880 } while (0) 881 882 PETSC_EXTERN PetscErrorCode PetscStackCreate(void); 883 PETSC_EXTERN PetscErrorCode PetscStackView(FILE*); 884 PETSC_EXTERN PetscErrorCode PetscStackDestroy(void); 885 886 #endif 887