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