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