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