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