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