154a8ef01SBarry Smith /* 2f621e05eSBarry Smith Contains all error handling interfaces for PETSc. 354a8ef01SBarry Smith */ 445d48df9SBarry Smith #if !defined(__PETSCERROR_H) 545d48df9SBarry Smith #define __PETSCERROR_H 66c7e564aSBarry Smith 754a8ef01SBarry Smith /* 8329ffe3dSLois Curfman McInnes These are the generic error codes. These error codes are used 9e2d1d2b7SBarry Smith many different places in the PETSc source code. The string versions are 100e5e90baSSatish Balay at src/sys/error/err.c any changes here must also be made there 11af0996ceSBarry Smith These are also define in include/petsc/finclude/petscerror.h any CHANGES here 120f9cf654SBarry Smith must be also made there. 1345d48df9SBarry Smith 1454a8ef01SBarry Smith */ 152a6744ebSBarry Smith #define PETSC_ERR_MIN_VALUE 54 /* should always be one less then the smallest value */ 162a6744ebSBarry Smith 1745d48df9SBarry Smith #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 1847794344SBarry Smith #define PETSC_ERR_SUP 56 /* no support for requested operation */ 19e2d1d2b7SBarry Smith #define PETSC_ERR_SUP_SYS 57 /* no support for requested operation on this computer system */ 20e2d1d2b7SBarry Smith #define PETSC_ERR_ORDER 58 /* operation done in wrong order */ 2145d48df9SBarry Smith #define PETSC_ERR_SIG 59 /* signal received */ 22f1caa5a4SBarry Smith #define PETSC_ERR_FP 72 /* floating point exception */ 23a8c6a408SBarry Smith #define PETSC_ERR_COR 74 /* corrupted PETSc object */ 24a8c6a408SBarry Smith #define PETSC_ERR_LIB 76 /* error in library called by PETSc */ 25329ffe3dSLois Curfman McInnes #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */ 26329ffe3dSLois Curfman McInnes #define PETSC_ERR_MEMC 78 /* memory corruption */ 27b3cc6726SBarry Smith #define PETSC_ERR_CONV_FAILED 82 /* iterative method (KSP or SNES) failed */ 281302d50aSBarry Smith #define PETSC_ERR_USER 83 /* user has not provided needed function */ 294e2ffeddSBarry Smith #define PETSC_ERR_SYS 88 /* error in system call */ 30a8b45ee7SBarry Smith #define PETSC_ERR_POINTER 70 /* pointer does not point to valid address */ 313d96e996SBarry Smith #define PETSC_ERR_MPI_LIB_INCOMP 87 /* MPI library at runtime is not compatible with MPI user compiled with */ 3245d48df9SBarry Smith 3345d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */ 3445d48df9SBarry Smith #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */ 35a8c6a408SBarry Smith #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */ 3645d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */ 3745d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */ 384f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */ 394f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */ 406831982aSBarry Smith #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */ 41d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */ 428cda6cd7SBarry Smith #define PETSC_ERR_ARG_TYPENOTSET 89 /* the type of the object has not yet been set */ 43a8c6a408SBarry Smith #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ 444482741eSBarry Smith #define PETSC_ERR_ARG_NULL 85 /* argument is null that should not be */ 45958c9bccSBarry Smith #define PETSC_ERR_ARG_UNKNOWN_TYPE 86 /* type name doesn't match any registered type */ 464f227f7cSBarry Smith 474f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ 484f227f7cSBarry Smith #define PETSC_ERR_FILE_READ 66 /* unable to read from file */ 494f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */ 50a8c6a408SBarry Smith #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */ 5145d48df9SBarry Smith 52329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */ 539e3b2f23SBarry Smith #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */ 5454a8ef01SBarry Smith 5568e69593SBarry Smith #define PETSC_ERR_INT_OVERFLOW 84 563855c12bSBarry Smith 57bf3909cdSBarry Smith #define PETSC_ERR_FLOP_COUNT 90 58e113a28aSBarry Smith #define PETSC_ERR_NOT_CONVERGED 91 /* solver did not converge */ 5992e8f287SBarry Smith #define PETSC_ERR_MISSING_FACTOR 92 /* MatGetFactor() failed */ 60c5a392abSBarry Smith #define PETSC_ERR_OPT_OVERWRITE 93 /* attempted to over wrote options which should not be changed */ 612a6744ebSBarry Smith 62c5a392abSBarry Smith #define PETSC_ERR_MAX_VALUE 94 /* this is always the one more than the largest error code */ 63b9eb5ee8SHong Zhang 6459aaf355SLisandro Dalcin #define PetscStringizeArg(a) #a 6559aaf355SLisandro Dalcin #define PetscStringize(a) PetscStringizeArg(a) 66330cf3c9SBarry Smith 67e8b7e333SSatish Balay 6830de9b25SBarry Smith /*MC 691957e957SBarry Smith SETERRQ - Macro to be called when an error has been detected, 7030de9b25SBarry Smith 7130de9b25SBarry Smith Synopsis: 72aaa7dc30SBarry Smith #include <petscsys.h> 733af045c5SBarry Smith PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message) 7430de9b25SBarry Smith 753af045c5SBarry Smith Collective on MPI_Comm 7630de9b25SBarry Smith 7730de9b25SBarry Smith Input Parameters: 783af045c5SBarry Smith + comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error 793af045c5SBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 8030de9b25SBarry Smith - message - error message 8130de9b25SBarry Smith 8230de9b25SBarry Smith Level: beginner 8330de9b25SBarry Smith 8430de9b25SBarry Smith Notes: 8530de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 8630de9b25SBarry Smith 8730de9b25SBarry Smith See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments 8830de9b25SBarry Smith 8930de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 9030de9b25SBarry Smith 9130de9b25SBarry Smith Concepts: error^setting condition 9230de9b25SBarry Smith 9391d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3() 9430de9b25SBarry Smith M*/ 953af045c5SBarry Smith #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s) 96*986eef2eSBarry Smith 97*986eef2eSBarry Smith /*MC 98*986eef2eSBarry Smith SETERRMPI - Macro to be called when an error has been detected within an MPI callback function 99*986eef2eSBarry Smith 100*986eef2eSBarry Smith Synopsis: 101*986eef2eSBarry Smith #include <petscsys.h> 102*986eef2eSBarry Smith PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message) 103*986eef2eSBarry Smith 104*986eef2eSBarry Smith Collective on MPI_Comm 105*986eef2eSBarry Smith 106*986eef2eSBarry Smith Input Parameters: 107*986eef2eSBarry Smith + comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error 108*986eef2eSBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 109*986eef2eSBarry Smith - message - error message 110*986eef2eSBarry Smith 111*986eef2eSBarry Smith Level: developer 112*986eef2eSBarry Smith 113*986eef2eSBarry Smith Notes: 114*986eef2eSBarry Smith 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 115*986eef2eSBarry Smith which is registered with MPI_Add_error_code() when PETSc is initialized. 116*986eef2eSBarry Smith 117*986eef2eSBarry Smith Concepts: error^setting condition 118*986eef2eSBarry Smith 119*986eef2eSBarry Smith .seealso: SETERRQ(), CHKERRQ(), CHKERRMPI(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3() 120*986eef2eSBarry Smith M*/ 12112801b39SBarry Smith #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE) 12230de9b25SBarry Smith 12330de9b25SBarry Smith /*MC 12430de9b25SBarry Smith SETERRQ1 - Macro that is called when an error has been detected, 12530de9b25SBarry Smith 12630de9b25SBarry Smith Synopsis: 127aaa7dc30SBarry Smith #include <petscsys.h> 1283af045c5SBarry Smith PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg) 12930de9b25SBarry Smith 1303af045c5SBarry Smith Collective on MPI_Comm 13130de9b25SBarry Smith 13230de9b25SBarry Smith Input Parameters: 133fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 1343af045c5SBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 13530de9b25SBarry Smith . message - error message in the printf format 13630de9b25SBarry Smith - arg - argument (for example an integer, string or double) 13730de9b25SBarry Smith 13830de9b25SBarry Smith Level: beginner 13930de9b25SBarry Smith 14030de9b25SBarry Smith Notes: 14130de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 14230de9b25SBarry Smith 14330de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 14430de9b25SBarry Smith 14530de9b25SBarry Smith Concepts: error^setting condition 14630de9b25SBarry Smith 14791d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3() 14830de9b25SBarry Smith M*/ 1493af045c5SBarry Smith #define SETERRQ1(comm,ierr,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1) 15030de9b25SBarry Smith 15130de9b25SBarry Smith /*MC 15230de9b25SBarry Smith SETERRQ2 - Macro that is called when an error has been detected, 15330de9b25SBarry Smith 15430de9b25SBarry Smith Synopsis: 155aaa7dc30SBarry Smith #include <petscsys.h> 1563af045c5SBarry Smith PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2) 15730de9b25SBarry Smith 1583af045c5SBarry Smith Collective on MPI_Comm 15930de9b25SBarry Smith 16030de9b25SBarry Smith Input Parameters: 161fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 1623af045c5SBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 16330de9b25SBarry Smith . message - error message in the printf format 16430de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 16530de9b25SBarry Smith - arg2 - argument (for example an integer, string or double) 16630de9b25SBarry Smith 16730de9b25SBarry Smith Level: beginner 16830de9b25SBarry Smith 16930de9b25SBarry Smith Notes: 17030de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 17130de9b25SBarry Smith 17230de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 17330de9b25SBarry Smith 17430de9b25SBarry Smith Concepts: error^setting condition 17530de9b25SBarry Smith 1766024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3() 17730de9b25SBarry Smith M*/ 1783af045c5SBarry Smith #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2) 17930de9b25SBarry Smith 18030de9b25SBarry Smith /*MC 18130de9b25SBarry Smith SETERRQ3 - Macro that is called when an error has been detected, 18230de9b25SBarry Smith 18330de9b25SBarry Smith Synopsis: 184aaa7dc30SBarry Smith #include <petscsys.h> 1853af045c5SBarry Smith PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3) 18630de9b25SBarry Smith 1873af045c5SBarry Smith Collective on MPI_Comm 18830de9b25SBarry Smith 18930de9b25SBarry Smith Input Parameters: 190fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 1913af045c5SBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 19230de9b25SBarry Smith . message - error message in the printf format 19330de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 19430de9b25SBarry Smith . arg2 - argument (for example an integer, string or double) 19530de9b25SBarry Smith - arg3 - argument (for example an integer, string or double) 19630de9b25SBarry Smith 19730de9b25SBarry Smith Level: beginner 19830de9b25SBarry Smith 19930de9b25SBarry Smith Notes: 20030de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 20130de9b25SBarry Smith 202f621e05eSBarry Smith There are also versions for 4, 5, 6 and 7 arguments. 203f621e05eSBarry Smith 20430de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 20530de9b25SBarry Smith 20630de9b25SBarry Smith Concepts: error^setting condition 20730de9b25SBarry Smith 2086024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 20930de9b25SBarry Smith M*/ 2103af045c5SBarry Smith #define SETERRQ3(comm,ierr,s,a1,a2,a3) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3) 21130de9b25SBarry Smith 212fa190f98SMatthew G. Knepley /*MC 213fa190f98SMatthew G. Knepley SETERRQ4 - Macro that is called when an error has been detected, 214fa190f98SMatthew G. Knepley 215fa190f98SMatthew G. Knepley Synopsis: 216fa190f98SMatthew G. Knepley #include <petscsys.h> 2173af045c5SBarry Smith PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3) 218fa190f98SMatthew G. Knepley 2193af045c5SBarry Smith Collective on MPI_Comm 220fa190f98SMatthew G. Knepley 221fa190f98SMatthew G. Knepley Input Parameters: 222fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 2233af045c5SBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 224fa190f98SMatthew G. Knepley . message - error message in the printf format 225fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 226fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 227fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 228fa190f98SMatthew G. Knepley - arg4 - argument (for example an integer, string or double) 229fa190f98SMatthew G. Knepley 230fa190f98SMatthew G. Knepley Level: beginner 231fa190f98SMatthew G. Knepley 232fa190f98SMatthew G. Knepley Notes: 233fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 234fa190f98SMatthew G. Knepley 235fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 236fa190f98SMatthew G. Knepley 237fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 238fa190f98SMatthew G. Knepley 239fa190f98SMatthew G. Knepley Concepts: error^setting condition 240fa190f98SMatthew G. Knepley 241fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 242fa190f98SMatthew G. Knepley M*/ 2433af045c5SBarry Smith #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) 244fa190f98SMatthew G. Knepley 245fa190f98SMatthew G. Knepley /*MC 246fa190f98SMatthew G. Knepley SETERRQ5 - Macro that is called when an error has been detected, 247fa190f98SMatthew G. Knepley 248fa190f98SMatthew G. Knepley Synopsis: 249fa190f98SMatthew G. Knepley #include <petscsys.h> 2503af045c5SBarry Smith PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3) 251fa190f98SMatthew G. Knepley 2523af045c5SBarry Smith Collective on MPI_COmm 253fa190f98SMatthew G. Knepley 254fa190f98SMatthew G. Knepley Input Parameters: 255fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 2563af045c5SBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 257fa190f98SMatthew G. Knepley . message - error message in the printf format 258fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 259fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 260fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 261fa190f98SMatthew G. Knepley . arg4 - argument (for example an integer, string or double) 262fa190f98SMatthew G. Knepley - arg5 - argument (for example an integer, string or double) 263fa190f98SMatthew G. Knepley 264fa190f98SMatthew G. Knepley Level: beginner 265fa190f98SMatthew G. Knepley 266fa190f98SMatthew G. Knepley Notes: 267fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 268fa190f98SMatthew G. Knepley 269fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 270fa190f98SMatthew G. Knepley 271fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 272fa190f98SMatthew G. Knepley 273fa190f98SMatthew G. Knepley Concepts: error^setting condition 274fa190f98SMatthew G. Knepley 275fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 276fa190f98SMatthew G. Knepley M*/ 2773af045c5SBarry Smith #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) 278fa190f98SMatthew G. Knepley 279fa190f98SMatthew G. Knepley /*MC 280fa190f98SMatthew G. Knepley SETERRQ6 - Macro that is called when an error has been detected, 281fa190f98SMatthew G. Knepley 282fa190f98SMatthew G. Knepley Synopsis: 283fa190f98SMatthew G. Knepley #include <petscsys.h> 2843af045c5SBarry Smith PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3) 285fa190f98SMatthew G. Knepley 2863af045c5SBarry Smith Collective on MPI_Comm 287fa190f98SMatthew G. Knepley 288fa190f98SMatthew G. Knepley Input Parameters: 289fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 2903af045c5SBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 291fa190f98SMatthew G. Knepley . message - error message in the printf format 292fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 293fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 294fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 295fa190f98SMatthew G. Knepley . arg4 - argument (for example an integer, string or double) 296fa190f98SMatthew G. Knepley . arg5 - argument (for example an integer, string or double) 297fa190f98SMatthew G. Knepley - arg6 - argument (for example an integer, string or double) 298fa190f98SMatthew G. Knepley 299fa190f98SMatthew G. Knepley Level: beginner 300fa190f98SMatthew G. Knepley 301fa190f98SMatthew G. Knepley Notes: 302fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 303fa190f98SMatthew G. Knepley 304fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 305fa190f98SMatthew G. Knepley 306fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 307fa190f98SMatthew G. Knepley 308fa190f98SMatthew G. Knepley Concepts: error^setting condition 309fa190f98SMatthew G. Knepley 310fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 311fa190f98SMatthew G. Knepley M*/ 3123af045c5SBarry Smith #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) 313fa190f98SMatthew G. Knepley 314fa190f98SMatthew G. Knepley /*MC 315fa190f98SMatthew G. Knepley SETERRQ7 - Macro that is called when an error has been detected, 316fa190f98SMatthew G. Knepley 317fa190f98SMatthew G. Knepley Synopsis: 318fa190f98SMatthew G. Knepley #include <petscsys.h> 3193af045c5SBarry Smith PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3) 320fa190f98SMatthew G. Knepley 3213af045c5SBarry Smith Collective on MPI_Comm 322fa190f98SMatthew G. Knepley 323fa190f98SMatthew G. Knepley Input Parameters: 324fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 3253af045c5SBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 326fa190f98SMatthew G. Knepley . message - error message in the printf format 327fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 328fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 329fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 330fa190f98SMatthew G. Knepley . arg4 - argument (for example an integer, string or double) 331fa190f98SMatthew G. Knepley . arg5 - argument (for example an integer, string or double) 332fa190f98SMatthew G. Knepley . arg6 - argument (for example an integer, string or double) 333fa190f98SMatthew G. Knepley - arg7 - argument (for example an integer, string or double) 334fa190f98SMatthew G. Knepley 335fa190f98SMatthew G. Knepley Level: beginner 336fa190f98SMatthew G. Knepley 337fa190f98SMatthew G. Knepley Notes: 338fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 339fa190f98SMatthew G. Knepley 340fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 341fa190f98SMatthew G. Knepley 342fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 343fa190f98SMatthew G. Knepley 344fa190f98SMatthew G. Knepley Concepts: error^setting condition 345fa190f98SMatthew G. Knepley 346fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 347fa190f98SMatthew G. Knepley M*/ 3483af045c5SBarry Smith #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) 349fa190f98SMatthew G. Knepley 350fa190f98SMatthew G. Knepley /*MC 351fa190f98SMatthew G. Knepley SETERRQ8 - Macro that is called when an error has been detected, 352fa190f98SMatthew G. Knepley 353fa190f98SMatthew G. Knepley Synopsis: 354fa190f98SMatthew G. Knepley #include <petscsys.h> 3553af045c5SBarry Smith PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3) 356fa190f98SMatthew G. Knepley 3573af045c5SBarry Smith Collective on MPI_Comm 358fa190f98SMatthew G. Knepley 359fa190f98SMatthew G. Knepley Input Parameters: 360fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 3613af045c5SBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 362fa190f98SMatthew G. Knepley . message - error message in the printf format 363fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 364fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 365fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 366fa190f98SMatthew G. Knepley . arg4 - argument (for example an integer, string or double) 367fa190f98SMatthew G. Knepley . arg5 - argument (for example an integer, string or double) 368fa190f98SMatthew G. Knepley . arg6 - argument (for example an integer, string or double) 369fa190f98SMatthew G. Knepley . arg7 - argument (for example an integer, string or double) 370fa190f98SMatthew G. Knepley - arg8 - argument (for example an integer, string or double) 371fa190f98SMatthew G. Knepley 372fa190f98SMatthew G. Knepley Level: beginner 373fa190f98SMatthew G. Knepley 374fa190f98SMatthew G. Knepley Notes: 375fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 376fa190f98SMatthew G. Knepley 377fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 378fa190f98SMatthew G. Knepley 379fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 380fa190f98SMatthew G. Knepley 381fa190f98SMatthew G. Knepley Concepts: error^setting condition 382fa190f98SMatthew G. Knepley 383fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 384fa190f98SMatthew G. Knepley M*/ 3853af045c5SBarry Smith #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) 386fa190f98SMatthew G. Knepley 387fa190f98SMatthew G. Knepley /*MC 388fa190f98SMatthew G. Knepley SETERRABORT - Macro that can be called when an error has been detected, 389fa190f98SMatthew G. Knepley 390fa190f98SMatthew G. Knepley Synopsis: 391fa190f98SMatthew G. Knepley #include <petscsys.h> 3923af045c5SBarry Smith PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message) 393fa190f98SMatthew G. Knepley 3943af045c5SBarry Smith Collective on MPI_Comm 395fa190f98SMatthew G. Knepley 396fa190f98SMatthew G. Knepley Input Parameters: 397fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 3983af045c5SBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 399fa190f98SMatthew G. Knepley - message - error message in the printf format 400fa190f98SMatthew G. Knepley 401fa190f98SMatthew G. Knepley Level: beginner 402fa190f98SMatthew G. Knepley 403fa190f98SMatthew G. Knepley Notes: 404fa190f98SMatthew G. Knepley This function just calls MPI_Abort(). 405fa190f98SMatthew G. Knepley 406fa190f98SMatthew G. Knepley Concepts: error^setting condition 407fa190f98SMatthew G. Knepley 408fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 409fa190f98SMatthew G. Knepley M*/ 4103af045c5SBarry Smith #define SETERRABORT(comm,ierr,s) do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,ierr);} while (0) 4119a00fa46SSatish Balay 41230de9b25SBarry Smith /*MC 41330de9b25SBarry Smith CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns 41430de9b25SBarry Smith 41530de9b25SBarry Smith Synopsis: 416aaa7dc30SBarry Smith #include <petscsys.h> 4173af045c5SBarry Smith PetscErrorCode CHKERRQ(PetscErrorCode ierr) 41830de9b25SBarry Smith 419eca87e8dSBarry Smith Not Collective 42030de9b25SBarry Smith 42130de9b25SBarry Smith Input Parameters: 4223af045c5SBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 42330de9b25SBarry Smith 42430de9b25SBarry Smith Level: beginner 42530de9b25SBarry Smith 42630de9b25SBarry Smith Notes: 42730de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 42830de9b25SBarry Smith 42930de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 4305324ea47SKris Buschelman 4313af045c5SBarry Smith CHKERRQ(ierr) is fundamentally a macro replacement for 4323af045c5SBarry Smith if (ierr) return(PetscError(...,ierr,...)); 4335324ea47SKris Buschelman 4345324ea47SKris Buschelman Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is 4355324ea47SKris Buschelman highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular, 4365324ea47SKris Buschelman it cannot be used in functions which return(void) or any other datatype. In these types of functions, 43758ebbce7SBarry Smith you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or 4383af045c5SBarry Smith if (ierr) {PetscError(....); return(YourReturnType);} 4390298fd71SBarry Smith where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have 44058ebbce7SBarry Smith MPI_Abort() returned immediately. 44158ebbce7SBarry Smith 44230de9b25SBarry Smith Concepts: error^setting condition 44330de9b25SBarry Smith 44491d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2() 44530de9b25SBarry Smith M*/ 4463af045c5SBarry Smith #define CHKERRQ(ierr) do {if (PetscUnlikely(ierr)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");} while (0) 447f01fac0dSBarry Smith #define CHKERRV(ierr) do {if (PetscUnlikely(ierr)) {ierr = PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");return;}} while(0) 4483af045c5SBarry Smith #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) 449*986eef2eSBarry Smith 450*986eef2eSBarry Smith 451*986eef2eSBarry Smith /*MC 452*986eef2eSBarry Smith CHKERRMPI - Checks error code, if non-zero it calls the error handler and then returns 453*986eef2eSBarry Smith 454*986eef2eSBarry Smith Synopsis: 455*986eef2eSBarry Smith #include <petscsys.h> 456*986eef2eSBarry Smith PetscErrorCode CHKERRMPI(PetscErrorCode ierr) 457*986eef2eSBarry Smith 458*986eef2eSBarry Smith Not Collective 459*986eef2eSBarry Smith 460*986eef2eSBarry Smith Input Parameters: 461*986eef2eSBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 462*986eef2eSBarry Smith 463*986eef2eSBarry Smith Level: developer 464*986eef2eSBarry Smith 465*986eef2eSBarry Smith Notes: 466*986eef2eSBarry Smith 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 467*986eef2eSBarry Smith which is registered with MPI_Add_error_code() when PETSc is initialized. 468*986eef2eSBarry Smith 469*986eef2eSBarry Smith Concepts: error^setting condition 470*986eef2eSBarry Smith 471*986eef2eSBarry Smith .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2() 472*986eef2eSBarry Smith M*/ 47312801b39SBarry Smith #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) 47485614651SBarry Smith 475fd705b32SMatthew Knepley #ifdef PETSC_CLANGUAGE_CXX 476fd705b32SMatthew Knepley 477cc26af49SMatthew Knepley /*MC 478cc26af49SMatthew Knepley CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception 479cc26af49SMatthew Knepley 480cc26af49SMatthew Knepley Synopsis: 481aaa7dc30SBarry Smith #include <petscsys.h> 4823af045c5SBarry Smith void CHKERRXX(PetscErrorCode ierr) 483cc26af49SMatthew Knepley 484eca87e8dSBarry Smith Not Collective 485cc26af49SMatthew Knepley 486cc26af49SMatthew Knepley Input Parameters: 4873af045c5SBarry Smith . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h 488cc26af49SMatthew Knepley 489cc26af49SMatthew Knepley Level: beginner 490cc26af49SMatthew Knepley 491cc26af49SMatthew Knepley Notes: 492cc26af49SMatthew Knepley Once the error handler throws a ??? exception. 493cc26af49SMatthew Knepley 494cc26af49SMatthew Knepley You can use CHKERRV() which returns without an error code (bad idea since the error is ignored) 495cc26af49SMatthew Knepley or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately. 496cc26af49SMatthew Knepley 497cc26af49SMatthew Knepley Concepts: error^setting condition 498cc26af49SMatthew Knepley 499cc26af49SMatthew Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ 500cc26af49SMatthew Knepley M*/ 5013af045c5SBarry Smith #define CHKERRXX(ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_IN_CXX,0);}} while(0) 502fd705b32SMatthew Knepley 503fd705b32SMatthew Knepley #endif 504fd705b32SMatthew Knepley 5055be1650bSAlejandro Lamas Daviña #define CHKERRCUDA(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUDA error %d",err);} while(0) 5065be1650bSAlejandro Lamas Daviña #define CHKERRCUBLAS(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUBLAS error %d",err);} while(0) 50782f73ecaSAlejandro Lamas Daviña 50830de9b25SBarry Smith /*MC 50930de9b25SBarry Smith CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected 51030de9b25SBarry Smith 51130de9b25SBarry Smith Synopsis: 512aaa7dc30SBarry Smith #include <petscsys.h> 51391d3bdf4SKris Buschelman CHKMEMQ; 51430de9b25SBarry Smith 515eca87e8dSBarry Smith Not Collective 516eca87e8dSBarry Smith 51730de9b25SBarry Smith Level: beginner 51830de9b25SBarry Smith 51930de9b25SBarry Smith Notes: 5201957e957SBarry Smith We highly recommend using valgrind http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful 5211957e957SBarry Smith on systems that do not have valgrind, but much much less useful. 5221957e957SBarry Smith 523ff002950SBarry Smith Must run with the option -malloc_debug to enable this option 52430de9b25SBarry Smith 52530de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 52630de9b25SBarry Smith 52730de9b25SBarry Smith By defaults prints location where memory that is corrupted was allocated. 52830de9b25SBarry Smith 529f621e05eSBarry Smith Use CHKMEMA for functions that return void 530f621e05eSBarry Smith 53130de9b25SBarry Smith Concepts: memory corruption 53230de9b25SBarry Smith 5336024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), 534ff002950SBarry Smith PetscMallocValidate() 53530de9b25SBarry Smith M*/ 536efca3c55SSatish Balay #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while(0) 53785614651SBarry Smith 538efca3c55SSatish Balay #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__) 539e68848bdSBarry Smith 540668f157eSBarry Smith /*E 541668f157eSBarry Smith PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers 542668f157eSBarry Smith 543668f157eSBarry Smith Level: advanced 544668f157eSBarry Smith 545d736bfebSBarry Smith PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated 546d736bfebSBarry Smith 54795452b02SPatrick Sanan Developer Notes: 54895452b02SPatrick Sanan This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler() 549668f157eSBarry Smith 550d736bfebSBarry Smith .seealso: PetscError(), SETERRXX() 551668f157eSBarry Smith E*/ 552d736bfebSBarry Smith typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType; 5534b209cf6SBarry Smith 554eb9e708aSLisandro Dalcin #if defined(__clang_analyzer__) 555eb9e708aSLisandro Dalcin __attribute__((analyzer_noreturn)) 556eb9e708aSLisandro Dalcin #endif 557eb9e708aSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...); 558eb9e708aSLisandro Dalcin 559014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void); 560014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **); 561efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 562efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 563efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 564efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 565efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 566efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 567efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 568efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*); 569014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void); 5708d359177SBarry Smith PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*); 571014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*); 572014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void); 57328559dc8SJed Brown PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt); 574329f5518SBarry Smith 575639ff905SBarry Smith /*MC 576639ff905SBarry Smith PetscErrorPrintf - Prints error messages. 577639ff905SBarry Smith 578639ff905SBarry Smith Synopsis: 579aaa7dc30SBarry Smith #include <petscsys.h> 580639ff905SBarry Smith PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 581639ff905SBarry Smith 582639ff905SBarry Smith Not Collective 583639ff905SBarry Smith 584639ff905SBarry Smith Input Parameters: 585639ff905SBarry Smith . format - the usual printf() format string 586639ff905SBarry Smith 587639ff905SBarry Smith Options Database Keys: 5881957e957SBarry Smith + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr 589e1bc860dSBarry Smith - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.) 590639ff905SBarry Smith 59195452b02SPatrick Sanan Notes: 59295452b02SPatrick Sanan Use 593639ff905SBarry Smith $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 594639ff905SBarry Smith $ error is handled.) and 5951957e957SBarry Smith $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function 596639ff905SBarry Smith 597639ff905SBarry Smith Use 598639ff905SBarry Smith PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file. 599639ff905SBarry Smith PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file. 600639ff905SBarry Smith 601639ff905SBarry Smith Use 602639ff905SBarry Smith PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print 603639ff905SBarry Smith 604639ff905SBarry Smith Level: developer 605639ff905SBarry Smith 606639ff905SBarry Smith Fortran Note: 607639ff905SBarry Smith This routine is not supported in Fortran. 608639ff905SBarry Smith 609639ff905SBarry Smith Concepts: error messages^printing 610639ff905SBarry Smith Concepts: printing^error messages 611639ff905SBarry Smith 612639ff905SBarry Smith .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush(), PetscVFPrintf(), PetscHelpPrintf() 613639ff905SBarry Smith M*/ 614639ff905SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...); 615639ff905SBarry Smith 616329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 617014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap); 618014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap); 619014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void); 62054a8ef01SBarry Smith 6213a40ed3dSBarry Smith /* 6223a40ed3dSBarry Smith Allows the code to build a stack frame as it runs 6233a40ed3dSBarry Smith */ 6243a40ed3dSBarry Smith 62599cd645aSJed Brown #define PETSCSTACKSIZE 64 626184914b5SBarry Smith 6273a40ed3dSBarry Smith typedef struct { 6280e33f6ddSBarry Smith const char *function[PETSCSTACKSIZE]; 6290e33f6ddSBarry Smith const char *file[PETSCSTACKSIZE]; 630184914b5SBarry Smith int line[PETSCSTACKSIZE]; 631a8d2bbe5SBarry Smith PetscBool petscroutine[PETSCSTACKSIZE]; 632184914b5SBarry Smith int currentsize; 633a2f94806SJed Brown int hotdepth; 6343a40ed3dSBarry Smith } PetscStack; 6353a40ed3dSBarry Smith 6361f46d60fSShri Abhyankar PETSC_EXTERN PetscStack *petscstack; 637184914b5SBarry Smith 6386f5c2d7aSBarry Smith PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*); 6396f5c2d7aSBarry Smith PetscErrorCode PetscStackPrint(PetscStack *,FILE*); 6405d12eec7SSatish Balay #if defined(PETSC_SERIALIZE_FUNCTIONS) 6415d12eec7SSatish Balay #include <petsc/private/petscfptimpl.h> 6425d12eec7SSatish Balay /* 6435d12eec7SSatish Balay Registers the current function into the global function pointer to function name table 6445d12eec7SSatish Balay 6455d12eec7SSatish Balay Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc 6465d12eec7SSatish Balay */ 6475d12eec7SSatish Balay #define PetscRegister__FUNCT__() do { \ 6485d12eec7SSatish Balay static PetscBool __chked = PETSC_FALSE; \ 6495d12eec7SSatish Balay if (!__chked) {\ 6505d12eec7SSatish Balay void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\ 6515d12eec7SSatish Balay __chked = PETSC_TRUE;\ 6525d12eec7SSatish Balay }} while (0) 6535d12eec7SSatish Balay #else 6545d12eec7SSatish Balay #define PetscRegister__FUNCT__() 6555d12eec7SSatish Balay #endif 6565d12eec7SSatish Balay 6572d7c6352SJed Brown #if defined(PETSC_USE_DEBUG) 658dbf62e16SBarry Smith PETSC_STATIC_INLINE PetscBool PetscStackActive(void) 659dbf62e16SBarry Smith { 6605c25fcd7SBarry Smith return(petscstack ? PETSC_TRUE : PETSC_FALSE); 661dbf62e16SBarry Smith } 6623a40ed3dSBarry Smith 663441dd030SJed Brown /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error 664441dd030SJed Brown * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at 665441dd030SJed Brown * least more useful than "unknown" because it can distinguish multiple calls from the same function. 666441dd030SJed Brown */ 667441dd030SJed Brown 668a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) \ 669441dd030SJed Brown do { \ 670e04113cfSBarry Smith PetscStackSAWsTakeAccess(); \ 6715c25fcd7SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 6725c25fcd7SBarry Smith petscstack->function[petscstack->currentsize] = funct; \ 6735c25fcd7SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 6745c25fcd7SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 6755c25fcd7SBarry Smith petscstack->petscroutine[petscstack->currentsize] = petsc_routine; \ 6765c25fcd7SBarry Smith petscstack->currentsize++; \ 677441dd030SJed Brown } \ 6785c25fcd7SBarry Smith if (petscstack) { \ 6795c25fcd7SBarry Smith petscstack->hotdepth += (hot || petscstack->hotdepth); \ 680a2f94806SJed Brown } \ 681e04113cfSBarry Smith PetscStackSAWsGrantAccess(); \ 682441dd030SJed Brown } while (0) 683441dd030SJed Brown 684441dd030SJed Brown #define PetscStackPopNoCheck \ 6855c25fcd7SBarry Smith do { \ 686e04113cfSBarry Smith PetscStackSAWsTakeAccess(); \ 6875c25fcd7SBarry Smith if (petscstack && petscstack->currentsize > 0) { \ 6885c25fcd7SBarry Smith petscstack->currentsize--; \ 6895c25fcd7SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 6905c25fcd7SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 6915c25fcd7SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 6925c25fcd7SBarry Smith petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\ 693441dd030SJed Brown } \ 6945c25fcd7SBarry Smith if (petscstack) { \ 6955c25fcd7SBarry Smith petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0); \ 696a2f94806SJed Brown } \ 697e04113cfSBarry Smith PetscStackSAWsGrantAccess(); \ 698441dd030SJed Brown } while (0) 699441dd030SJed Brown 70030de9b25SBarry Smith /*MC 7011957e957SBarry Smith PetscFunctionBegin - First executable line of each PETSc function, used for error handling. Final 7021957e957SBarry Smith line of PETSc functions should be PetscFunctionReturn(0); 70330de9b25SBarry Smith 70430de9b25SBarry Smith Synopsis: 705aaa7dc30SBarry Smith #include <petscsys.h> 70630de9b25SBarry Smith void PetscFunctionBegin; 70730de9b25SBarry Smith 708eca87e8dSBarry Smith Not Collective 709eca87e8dSBarry Smith 71030de9b25SBarry Smith Usage: 71130de9b25SBarry Smith .vb 71230de9b25SBarry Smith int something; 71330de9b25SBarry Smith 71430de9b25SBarry Smith PetscFunctionBegin; 71530de9b25SBarry Smith .ve 71630de9b25SBarry Smith 71730de9b25SBarry Smith Notes: 7181957e957SBarry Smith Use PetscFunctionBeginUser for application codes. 7191957e957SBarry Smith 72030de9b25SBarry Smith Not available in Fortran 72130de9b25SBarry Smith 72230de9b25SBarry Smith Level: developer 72330de9b25SBarry Smith 7241957e957SBarry Smith .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser() 72530de9b25SBarry Smith 72630de9b25SBarry Smith .keywords: traceback, error handling 72730de9b25SBarry Smith M*/ 728441dd030SJed Brown #define PetscFunctionBegin do { \ 729a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \ 730a2f94806SJed Brown PetscRegister__FUNCT__(); \ 731a2f94806SJed Brown } while (0) 732a2f94806SJed Brown 733a2f94806SJed Brown /*MC 734a2f94806SJed Brown PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in 735a2f94806SJed Brown performance-critical circumstances. Use of this function allows for lighter profiling by default. 736a2f94806SJed Brown 737a2f94806SJed Brown Synopsis: 738aaa7dc30SBarry Smith #include <petscsys.h> 739a2f94806SJed Brown void PetscFunctionBeginHot; 740a2f94806SJed Brown 741a2f94806SJed Brown Not Collective 742a2f94806SJed Brown 743a2f94806SJed Brown Usage: 744a2f94806SJed Brown .vb 745a2f94806SJed Brown int something; 746a2f94806SJed Brown 747a2f94806SJed Brown PetscFunctionBeginHot; 748a2f94806SJed Brown .ve 749a2f94806SJed Brown 750a2f94806SJed Brown Notes: 751a2f94806SJed Brown Not available in Fortran 752a2f94806SJed Brown 753a2f94806SJed Brown Level: developer 754a2f94806SJed Brown 755a2f94806SJed Brown .seealso: PetscFunctionBegin, PetscFunctionReturn() 756a2f94806SJed Brown 757a2f94806SJed Brown .keywords: traceback, error handling 758a2f94806SJed Brown M*/ 759a2f94806SJed Brown #define PetscFunctionBeginHot do { \ 760a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE); \ 7612d53ad75SBarry Smith PetscRegister__FUNCT__(); \ 76253c77d0aSJed Brown } while (0) 76353c77d0aSJed Brown 764a8d2bbe5SBarry Smith /*MC 765a8d2bbe5SBarry Smith PetscFunctionBeginUser - First executable line of user provided PETSc routine 766a8d2bbe5SBarry Smith 767a8d2bbe5SBarry Smith Synopsis: 768aaa7dc30SBarry Smith #include <petscsys.h> 769a8d2bbe5SBarry Smith void PetscFunctionBeginUser; 770a8d2bbe5SBarry Smith 771a8d2bbe5SBarry Smith Not Collective 772a8d2bbe5SBarry Smith 773a8d2bbe5SBarry Smith Usage: 774a8d2bbe5SBarry Smith .vb 775a8d2bbe5SBarry Smith int something; 776a8d2bbe5SBarry Smith 777ac285190SBarry Smith PetscFunctionBeginUser; 778a8d2bbe5SBarry Smith .ve 779a8d2bbe5SBarry Smith 780a8d2bbe5SBarry Smith Notes: 7811957e957SBarry Smith Final line of PETSc functions should be PetscFunctionReturn(0) except for main(). 7821957e957SBarry Smith 783a8d2bbe5SBarry Smith Not available in Fortran 784a8d2bbe5SBarry Smith 785ac285190SBarry Smith This is identical to PetscFunctionBegin except it labels the routine as a user 786ac285190SBarry Smith routine instead of as a PETSc library routine. 787ac285190SBarry Smith 788a2f94806SJed Brown Level: intermediate 789a8d2bbe5SBarry Smith 790a2f94806SJed Brown .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot 791a8d2bbe5SBarry Smith 792a8d2bbe5SBarry Smith .keywords: traceback, error handling 793a8d2bbe5SBarry Smith M*/ 794a8d2bbe5SBarry Smith #define PetscFunctionBeginUser \ 795a8d2bbe5SBarry Smith do { \ 796a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \ 797a8d2bbe5SBarry Smith PetscRegister__FUNCT__(); \ 798a8d2bbe5SBarry Smith } while (0) 799a8d2bbe5SBarry Smith 800a8d2bbe5SBarry Smith 8015cd90555SBarry Smith #define PetscStackPush(n) \ 80261d886c9SShri Abhyankar do { \ 803a2f94806SJed Brown PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE); \ 80415681b3cSBarry Smith CHKMEMQ; \ 80515681b3cSBarry Smith } while (0) 8063a40ed3dSBarry Smith 807d64ed03dSBarry Smith #define PetscStackPop \ 808441dd030SJed Brown do { \ 809441dd030SJed Brown CHKMEMQ; \ 810441dd030SJed Brown PetscStackPopNoCheck; \ 81115681b3cSBarry Smith } while (0) 812d64ed03dSBarry Smith 81330de9b25SBarry Smith /*MC 81430de9b25SBarry Smith PetscFunctionReturn - Last executable line of each PETSc function 81530de9b25SBarry Smith used for error handling. Replaces return() 81630de9b25SBarry Smith 81730de9b25SBarry Smith Synopsis: 818aaa7dc30SBarry Smith #include <petscsys.h> 81930de9b25SBarry Smith void PetscFunctionReturn(0); 82030de9b25SBarry Smith 821eca87e8dSBarry Smith Not Collective 822eca87e8dSBarry Smith 82330de9b25SBarry Smith Usage: 82430de9b25SBarry Smith .vb 82530de9b25SBarry Smith .... 82630de9b25SBarry Smith PetscFunctionReturn(0); 82730de9b25SBarry Smith } 82830de9b25SBarry Smith .ve 82930de9b25SBarry Smith 83030de9b25SBarry Smith Notes: 83130de9b25SBarry Smith Not available in Fortran 83230de9b25SBarry Smith 83330de9b25SBarry Smith Level: developer 83430de9b25SBarry Smith 83530de9b25SBarry Smith .seealso: PetscFunctionBegin() 83630de9b25SBarry Smith 83730de9b25SBarry Smith .keywords: traceback, error handling 83830de9b25SBarry Smith M*/ 8395cd90555SBarry Smith #define PetscFunctionReturn(a) \ 8408246ba0dSJed Brown do { \ 841441dd030SJed Brown PetscStackPopNoCheck; \ 8428246ba0dSJed Brown return(a);} while (0) 843d64ed03dSBarry Smith 844ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 8458246ba0dSJed Brown do { \ 846441dd030SJed Brown PetscStackPopNoCheck; \ 8478246ba0dSJed Brown return;} while (0) 84876386721SLisandro Dalcin 8496d385327SIbrahima Ba #else 8506d385327SIbrahima Ba 851c82b4e47SJed Brown PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;} 852a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0) 853441dd030SJed Brown #define PetscStackPopNoCheck do {} while (0) 8543a40ed3dSBarry Smith #define PetscFunctionBegin 8550bdf7c52SPeter Brune #define PetscFunctionBeginUser 856a2f94806SJed Brown #define PetscFunctionBeginHot 8573a40ed3dSBarry Smith #define PetscFunctionReturn(a) return(a) 8585665465eSBarry Smith #define PetscFunctionReturnVoid() return 859812af9f3SBarry Smith #define PetscStackPop CHKMEMQ 860812af9f3SBarry Smith #define PetscStackPush(f) CHKMEMQ 8613a40ed3dSBarry Smith 8623a40ed3dSBarry Smith #endif 8633a40ed3dSBarry Smith 864eb6b5d47SBarry Smith /* 865eb6b5d47SBarry Smith PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack. 866eb6b5d47SBarry Smith 867eb6b5d47SBarry Smith Input Parameters: 868eb6b5d47SBarry Smith + name - string that gives the name of the function being called 869fd3f9acdSBarry Smith - routine - actual call to the routine, including ierr = and CHKERRQ(ierr); 870fd3f9acdSBarry Smith 871dbf62e16SBarry Smith Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes 872eb6b5d47SBarry Smith 873eb6b5d47SBarry Smith 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. 874eb6b5d47SBarry Smith 875fd3f9acdSBarry Smith 876fd3f9acdSBarry Smith 877eb6b5d47SBarry Smith */ 87830ecc5abSKarl Rupp #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while(0) 879eb6b5d47SBarry Smith 880fd3f9acdSBarry Smith /* 881fd3f9acdSBarry Smith PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack. 882fd3f9acdSBarry Smith 883fd3f9acdSBarry Smith Input Parameters: 884fd3f9acdSBarry Smith + func- name of the routine 885fd3f9acdSBarry Smith - args - arguments to the routine surrounded by () 886fd3f9acdSBarry Smith 88795452b02SPatrick Sanan Notes: 88895452b02SPatrick Sanan This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not. 889dbf62e16SBarry Smith 890dbf62e16SBarry Smith Developer Note: this is so that when an external packge routine results in a crash or corrupts memory, they get blamed instead of PETSc. 891fd3f9acdSBarry Smith 892fd3f9acdSBarry Smith */ 893fd3f9acdSBarry Smith #define PetscStackCallStandard(func,args) do { \ 8947afcd97cSStefano Zampini PetscStackPush(#func);ierr = func args;PetscStackPop; if (ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)ierr); \ 895fd3f9acdSBarry Smith } while (0) 896fd3f9acdSBarry Smith 897014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackCreate(void); 898639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscStackView(FILE*); 899014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackDestroy(void); 90006d1fe2cSBarry Smith 90106d1fe2cSBarry Smith #endif 902