154a8ef01SBarry Smith /* 24f227f7cSBarry Smith Contains all error handling code for PETSc. 354a8ef01SBarry Smith */ 445d48df9SBarry Smith #if !defined(__PETSCERROR_H) 545d48df9SBarry Smith #define __PETSCERROR_H 6c22c1629SBarry Smith #include "petsc.h" 7e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN 8c22c1629SBarry Smith 954a8ef01SBarry Smith /* 1054a8ef01SBarry Smith Defines the directory where the compiled source is located; used 115e97870eSBarry Smith in printing error messages. Each makefile has an entry 125e97870eSBarry Smith LOCDIR = thedirectory 130cd5afcaSLois Curfman McInnes and bmake/common_variables includes in CCPPFLAGS -D__SDIR__='"${LOCDIR}"' 145e97870eSBarry Smith which is a flag passed to the C/C++ compilers. 1554a8ef01SBarry Smith */ 16c22c1629SBarry Smith #if !defined(__SDIR__) 172ee1dbe0SBarry Smith #define __SDIR__ "unknowndirectory/" 1854a8ef01SBarry Smith #endif 1954a8ef01SBarry Smith 2054a8ef01SBarry Smith /* 214f227f7cSBarry Smith Defines the function where the compiled source is located; used 224f227f7cSBarry Smith in printing error messages. 234f227f7cSBarry Smith */ 244a2ae208SSatish Balay #if !defined(__FUNCT__) 25da9b6338SBarry Smith #define __FUNCT__ "User provided function" 264f227f7cSBarry Smith #endif 274f227f7cSBarry Smith 284f227f7cSBarry Smith /* 29329ffe3dSLois Curfman McInnes These are the generic error codes. These error codes are used 30e2d1d2b7SBarry Smith many different places in the PETSc source code. The string versions are 31e2d1d2b7SBarry Smith at src/sys/src/error/err.c any changes here must also be made there 3245d48df9SBarry Smith 3354a8ef01SBarry Smith */ 3445d48df9SBarry Smith #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 35106f7b34SBarry Smith #define PETSC_ERR_MEM_MALLOC_0 85 /* cannot malloc zero size */ 3647794344SBarry Smith #define PETSC_ERR_SUP 56 /* no support for requested operation */ 37e2d1d2b7SBarry Smith #define PETSC_ERR_SUP_SYS 57 /* no support for requested operation on this computer system */ 38e2d1d2b7SBarry Smith #define PETSC_ERR_ORDER 58 /* operation done in wrong order */ 3945d48df9SBarry Smith #define PETSC_ERR_SIG 59 /* signal received */ 40f1caa5a4SBarry Smith #define PETSC_ERR_FP 72 /* floating point exception */ 41a8c6a408SBarry Smith #define PETSC_ERR_COR 74 /* corrupted PETSc object */ 42a8c6a408SBarry Smith #define PETSC_ERR_LIB 76 /* error in library called by PETSc */ 43329ffe3dSLois Curfman McInnes #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */ 44329ffe3dSLois Curfman McInnes #define PETSC_ERR_MEMC 78 /* memory corruption */ 45b3cc6726SBarry Smith #define PETSC_ERR_CONV_FAILED 82 /* iterative method (KSP or SNES) failed */ 461302d50aSBarry Smith #define PETSC_ERR_USER 83 /* user has not provided needed function */ 4745d48df9SBarry Smith 4845d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */ 4945d48df9SBarry Smith #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */ 50a8c6a408SBarry Smith #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */ 5145d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */ 5245d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */ 534f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */ 544f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */ 556831982aSBarry Smith #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */ 56d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */ 57a8c6a408SBarry Smith #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ 584482741eSBarry Smith #define PETSC_ERR_ARG_NULL 85 /* argument is null that should not be */ 59958c9bccSBarry Smith #define PETSC_ERR_ARG_UNKNOWN_TYPE 86 /* type name doesn't match any registered type */ 604f227f7cSBarry Smith 614f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ 624f227f7cSBarry Smith #define PETSC_ERR_FILE_READ 66 /* unable to read from file */ 634f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */ 64a8c6a408SBarry Smith #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */ 6545d48df9SBarry Smith 66329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */ 679e3b2f23SBarry Smith #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */ 6854a8ef01SBarry Smith 694b55f32eSBarry Smith #if defined(PETSC_USE_ERRORCHECKING) 7030de9b25SBarry Smith 7130de9b25SBarry Smith /*MC 7230de9b25SBarry Smith SETERRQ - Macro that is called when an error has been detected, 7330de9b25SBarry Smith 7430de9b25SBarry Smith Not Collective 7530de9b25SBarry Smith 7630de9b25SBarry Smith Synopsis: 77a7cc72afSBarry Smith void SETERRQ(PetscErrorCode errorcode,char *message) 7830de9b25SBarry Smith 7930de9b25SBarry Smith 8030de9b25SBarry Smith Input Parameters: 8130de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 8230de9b25SBarry Smith - message - error message 8330de9b25SBarry Smith 8430de9b25SBarry Smith Level: beginner 8530de9b25SBarry Smith 8630de9b25SBarry Smith Notes: 8730de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 8830de9b25SBarry Smith 8930de9b25SBarry Smith See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments 9030de9b25SBarry Smith 9130de9b25SBarry Smith 9230de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 9330de9b25SBarry Smith 9430de9b25SBarry Smith Concepts: error^setting condition 9530de9b25SBarry Smith 9691d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3() 9730de9b25SBarry Smith M*/ 984a2ae208SSatish Balay #define SETERRQ(n,s) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);} 9930de9b25SBarry Smith 10030de9b25SBarry Smith /*MC 10130de9b25SBarry Smith SETERRQ1 - Macro that is called when an error has been detected, 10230de9b25SBarry Smith 10330de9b25SBarry Smith Not Collective 10430de9b25SBarry Smith 10530de9b25SBarry Smith Synopsis: 106a7cc72afSBarry Smith void SETERRQ1(PetscErrorCode errorcode,char *formatmessage,arg) 10730de9b25SBarry Smith 10830de9b25SBarry Smith 10930de9b25SBarry Smith Input Parameters: 11030de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 11130de9b25SBarry Smith . message - error message in the printf format 11230de9b25SBarry Smith - arg - argument (for example an integer, string or double) 11330de9b25SBarry Smith 11430de9b25SBarry Smith Level: beginner 11530de9b25SBarry Smith 11630de9b25SBarry Smith Notes: 11730de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 11830de9b25SBarry Smith 11930de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 12030de9b25SBarry Smith 12130de9b25SBarry Smith Concepts: error^setting condition 12230de9b25SBarry Smith 12391d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3() 12430de9b25SBarry Smith M*/ 1254a2ae208SSatish Balay #define SETERRQ1(n,s,a1) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1);} 12630de9b25SBarry Smith 12730de9b25SBarry Smith /*MC 12830de9b25SBarry Smith SETERRQ2 - Macro that is called when an error has been detected, 12930de9b25SBarry Smith 13030de9b25SBarry Smith Not Collective 13130de9b25SBarry Smith 13230de9b25SBarry Smith Synopsis: 133a7cc72afSBarry Smith void SETERRQ2(PetscErrorCode errorcode,char *formatmessage,arg1,arg2) 13430de9b25SBarry Smith 13530de9b25SBarry Smith 13630de9b25SBarry Smith Input Parameters: 13730de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 13830de9b25SBarry Smith . message - error message in the printf format 13930de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 14030de9b25SBarry Smith - arg2 - argument (for example an integer, string or double) 14130de9b25SBarry Smith 14230de9b25SBarry Smith Level: beginner 14330de9b25SBarry Smith 14430de9b25SBarry Smith Notes: 14530de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 14630de9b25SBarry Smith 14730de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 14830de9b25SBarry Smith 14930de9b25SBarry Smith Concepts: error^setting condition 15030de9b25SBarry Smith 151*6024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3() 15230de9b25SBarry Smith M*/ 1534a2ae208SSatish Balay #define SETERRQ2(n,s,a1,a2) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2);} 15430de9b25SBarry Smith 15530de9b25SBarry Smith /*MC 15630de9b25SBarry Smith SETERRQ3 - Macro that is called when an error has been detected, 15730de9b25SBarry Smith 15830de9b25SBarry Smith Not Collective 15930de9b25SBarry Smith 16030de9b25SBarry Smith Synopsis: 161a7cc72afSBarry Smith void SETERRQ3(PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 16230de9b25SBarry Smith 16330de9b25SBarry Smith 16430de9b25SBarry Smith Input Parameters: 16530de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 16630de9b25SBarry Smith . message - error message in the printf format 16730de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 16830de9b25SBarry Smith . arg2 - argument (for example an integer, string or double) 16930de9b25SBarry Smith - arg3 - argument (for example an integer, string or double) 17030de9b25SBarry Smith 17130de9b25SBarry Smith Level: beginner 17230de9b25SBarry Smith 17330de9b25SBarry Smith Notes: 17430de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 17530de9b25SBarry Smith 17630de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 17730de9b25SBarry Smith 17830de9b25SBarry Smith Concepts: error^setting condition 17930de9b25SBarry Smith 180*6024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 18130de9b25SBarry Smith M*/ 1824a2ae208SSatish Balay #define SETERRQ3(n,s,a1,a2,a3) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3);} 18330de9b25SBarry Smith 1844a2ae208SSatish Balay #define SETERRQ4(n,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4);} 185a30c184eSMatthew Knepley #define SETERRQ5(n,s,a1,a2,a3,a4,a5) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5);} 186a30c184eSMatthew Knepley #define SETERRQ6(n,s,a1,a2,a3,a4,a5,a6) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5,a6);} 187a30c184eSMatthew Knepley #define SETERRQ7(n,s,a1,a2,a3,a4,a5,a6,a7) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5,a6,a7);} 188e855a17bSBarry Smith #define SETERRABORT(comm,n,s) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);MPI_Abort(comm,n);} 1899a00fa46SSatish Balay 19030de9b25SBarry Smith /*MC 19130de9b25SBarry Smith CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns 19230de9b25SBarry Smith 19330de9b25SBarry Smith Not Collective 19430de9b25SBarry Smith 19530de9b25SBarry Smith Synopsis: 196a7cc72afSBarry Smith void CHKERRQ(PetscErrorCode errorcode) 19730de9b25SBarry Smith 19830de9b25SBarry Smith 19930de9b25SBarry Smith Input Parameters: 20030de9b25SBarry Smith . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 20130de9b25SBarry Smith 20230de9b25SBarry Smith Level: beginner 20330de9b25SBarry Smith 20430de9b25SBarry Smith Notes: 20530de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 20630de9b25SBarry Smith 20730de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 2085324ea47SKris Buschelman 209fcecf507SKris Buschelman CHKERRQ(n) is fundamentally a macro replacement for 2105324ea47SKris Buschelman if (n) return(PetscError(...,n,...)); 2115324ea47SKris Buschelman 2125324ea47SKris Buschelman Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is 2135324ea47SKris Buschelman highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular, 2145324ea47SKris Buschelman it cannot be used in functions which return(void) or any other datatype. In these types of functions, 215fcecf507SKris Buschelman a more appropriate construct for using PETSc Error Handling would be 2165324ea47SKris Buschelman if (n) {PetscError(....); return(YourReturnType);} 21730de9b25SBarry Smith 21830de9b25SBarry Smith Concepts: error^setting condition 21930de9b25SBarry Smith 22091d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2() 22130de9b25SBarry Smith M*/ 222c3be3f59SMatthew Knepley #define CHKERRQ(n) if (n) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");} 22330de9b25SBarry Smith 22494a56cdfSMatthew Knepley #define CHKERRABORT(comm,n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");MPI_Abort(comm,n);} 22594a56cdfSMatthew Knepley #define CHKERRCONTINUE(n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");} 22685614651SBarry Smith 22730de9b25SBarry Smith /*MC 22830de9b25SBarry Smith CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected 22930de9b25SBarry Smith 23030de9b25SBarry Smith Not Collective 23130de9b25SBarry Smith 23230de9b25SBarry Smith Synopsis: 23391d3bdf4SKris Buschelman CHKMEMQ; 23430de9b25SBarry Smith 23530de9b25SBarry Smith Level: beginner 23630de9b25SBarry Smith 23730de9b25SBarry Smith Notes: 238ff002950SBarry Smith Must run with the option -malloc_debug to enable this option 23930de9b25SBarry Smith 24030de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 24130de9b25SBarry Smith 24230de9b25SBarry Smith By defaults prints location where memory that is corrupted was allocated. 24330de9b25SBarry Smith 24430de9b25SBarry Smith Concepts: memory corruption 24530de9b25SBarry Smith 246*6024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), 247ff002950SBarry Smith PetscMallocValidate() 24830de9b25SBarry Smith M*/ 249ff002950SBarry Smith #define CHKMEMQ {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,__FUNCT__,__FILE__,__SDIR__);CHKERRQ(_7_ierr);} 25085614651SBarry Smith 251f1af5d2fSBarry Smith #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 2526849ba73SBarry Smith extern PetscErrorCode __gierr; 253f1af5d2fSBarry Smith #define _ __gierr = 254ac355199SBarry Smith #define ___ CHKERRQ(__gierr); 255f1af5d2fSBarry Smith #endif 256f1af5d2fSBarry Smith 257*6024bd2cSBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscExceptionPush(PetscErrorCode); 258*6024bd2cSBarry Smith EXTERN void PETSC_DLLEXPORT PetscExceptionPop(); 259*6024bd2cSBarry Smith 260*6024bd2cSBarry Smith /*MC 261*6024bd2cSBarry Smith PetscExceptionTry1 - Runs the routine, causing a particular error code to be treated as an exception, 262*6024bd2cSBarry Smith rather than an error. That is if that error code is treated the program returns to this level, 263*6024bd2cSBarry Smith but does not call the error handlers 264*6024bd2cSBarry Smith 265*6024bd2cSBarry Smith Not Collective 266*6024bd2cSBarry Smith 267*6024bd2cSBarry Smith Synopsis: 268*6024bd2cSBarry Smith PetscExceptionTry1(PetscErrorCode routine(....),PetscErrorCode); 269*6024bd2cSBarry Smith 270*6024bd2cSBarry Smith Level: advanced 271*6024bd2cSBarry Smith 272*6024bd2cSBarry Smith Notes: 273*6024bd2cSBarry Smith PETSc must not be configured using the option --with-errorchecking=0 for this to work 274*6024bd2cSBarry Smith 275*6024bd2cSBarry Smith 276*6024bd2cSBarry Smith Concepts: exceptions, exception hanlding 277*6024bd2cSBarry Smith 278*6024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), 279*6024bd2cSBarry Smith CHKERRQ() 280*6024bd2cSBarry Smith M*/ 281*6024bd2cSBarry Smith extern PetscErrorCode PetscExceptionTmp; 282*6024bd2cSBarry Smith #define PetscExceptionTry1(a,b) (PetscExceptionTmp = PetscExceptionPush(b)) ? PetscExceptionTmp : (PetscExceptionTmp = a , PetscExceptionPop(),PetscExceptionTmp) 283*6024bd2cSBarry Smith 28454a8ef01SBarry Smith #else 28590d37a7cSBarry Smith #define SETERRQ(n,s) ; 28690d37a7cSBarry Smith #define SETERRQ1(n,s,a1) ; 28790d37a7cSBarry Smith #define SETERRQ2(n,s,a1,a2) ; 28890d37a7cSBarry Smith #define SETERRQ3(n,s,a1,a2,a3) ; 28990d37a7cSBarry Smith #define SETERRQ4(n,s,a1,a2,a3,a4) ; 2909bd8d7fdSSatish Balay #define SETERRQ5(n,s,a1,a2,a3,a4,a5) ; 291742f4fedSDinesh Kaushik #define SETERRQ6(n,s,a1,a2,a3,a4,a5,a6) ; 2921ee4faa0SMatthew Knepley #define SETERRABORT(comm,n,s) ; 29385614651SBarry Smith 2944f227f7cSBarry Smith #define CHKERRQ(n) ; 2951ee4faa0SMatthew Knepley #define CHKERRABORT(comm,n) ; 2961ee4faa0SMatthew Knepley #define CHKERRCONTINUE(n) ; 29785614651SBarry Smith 29885614651SBarry Smith #define CHKMEMQ ; 29985614651SBarry Smith 300f1af5d2fSBarry Smith #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 301f1af5d2fSBarry Smith #define _ 302f1af5d2fSBarry Smith #define ___ 303f1af5d2fSBarry Smith #endif 304f1af5d2fSBarry Smith 305*6024bd2cSBarry Smith #define PetscExceptionTry1(a,b) a 30654a8ef01SBarry Smith #endif 30754a8ef01SBarry Smith 308ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscErrorPrintfInitialize(void); 309ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscErrorMessage(int,const char*[],char **); 310*6024bd2cSBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTraceBackErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*); 311*6024bd2cSBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscIgnoreErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*); 312*6024bd2cSBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscEmacsClientErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*); 313*6024bd2cSBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStopErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*); 314*6024bd2cSBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscAbortErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*); 315*6024bd2cSBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscAttachDebuggerErrorHandler(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*); 316*6024bd2cSBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscError(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,...) PETSC_PRINTF_FORMAT_CHECK(7,8); 317*6024bd2cSBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPushErrorHandler(PetscErrorCode (*handler)(int,const char*,const char*,const char*,PetscErrorCode,int,const char*,void*),void*); 318ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPopErrorHandler(void); 319ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDefaultSignalHandler(int,void*); 320ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*); 321ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPopSignalHandler(void); 322329f5518SBarry Smith 323329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 324ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetFPTrap(PetscFPTrap); 32554a8ef01SBarry Smith 3263a40ed3dSBarry Smith /* 3273a40ed3dSBarry Smith Allows the code to build a stack frame as it runs 3283a40ed3dSBarry Smith */ 32951d3a450SBarry Smith #if defined(PETSC_USE_DEBUG) 3303a40ed3dSBarry Smith 331184914b5SBarry Smith #define PETSCSTACKSIZE 15 332184914b5SBarry Smith 3333a40ed3dSBarry Smith typedef struct { 3340e33f6ddSBarry Smith const char *function[PETSCSTACKSIZE]; 3350e33f6ddSBarry Smith const char *file[PETSCSTACKSIZE]; 3360e33f6ddSBarry Smith const char *directory[PETSCSTACKSIZE]; 337184914b5SBarry Smith int line[PETSCSTACKSIZE]; 338184914b5SBarry Smith int currentsize; 3393a40ed3dSBarry Smith } PetscStack; 3403a40ed3dSBarry Smith 341ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscStack *petscstack; 342ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStackCopy(PetscStack*,PetscStack*); 343ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStackPrint(PetscStack*,FILE* fp); 344184914b5SBarry Smith 345184914b5SBarry Smith #define PetscStackActive (petscstack != 0) 3463a40ed3dSBarry Smith 3476d385327SIbrahima Ba 34830de9b25SBarry Smith /*MC 34930de9b25SBarry Smith PetscFunctionBegin - First executable line of each PETSc function 35030de9b25SBarry Smith used for error handling. 35130de9b25SBarry Smith 35230de9b25SBarry Smith Synopsis: 35330de9b25SBarry Smith void PetscFunctionBegin; 35430de9b25SBarry Smith 35530de9b25SBarry Smith Usage: 35630de9b25SBarry Smith .vb 35730de9b25SBarry Smith int something; 35830de9b25SBarry Smith 35930de9b25SBarry Smith PetscFunctionBegin; 36030de9b25SBarry Smith .ve 36130de9b25SBarry Smith 36230de9b25SBarry Smith Notes: 36330de9b25SBarry Smith Not available in Fortran 36430de9b25SBarry Smith 36530de9b25SBarry Smith Level: developer 36630de9b25SBarry Smith 36730de9b25SBarry Smith .seealso: PetscFunctionReturn() 36830de9b25SBarry Smith 36930de9b25SBarry Smith .keywords: traceback, error handling 37030de9b25SBarry Smith M*/ 3713a40ed3dSBarry Smith #define PetscFunctionBegin \ 372beb17490SBarry Smith {\ 373184914b5SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 3744a2ae208SSatish Balay petscstack->function[petscstack->currentsize] = __FUNCT__; \ 375184914b5SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 376184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = __SDIR__; \ 377184914b5SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 378184914b5SBarry Smith petscstack->currentsize++; \ 3793a40ed3dSBarry Smith }} 3803a40ed3dSBarry Smith 3815cd90555SBarry Smith #define PetscStackPush(n) \ 382184914b5SBarry Smith {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 383184914b5SBarry Smith petscstack->function[petscstack->currentsize] = n; \ 384184914b5SBarry Smith petscstack->file[petscstack->currentsize] = "unknown"; \ 385184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = "unknown"; \ 386184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 387184914b5SBarry Smith petscstack->currentsize++; \ 3885cd90555SBarry Smith }} 3893a40ed3dSBarry Smith 390d64ed03dSBarry Smith #define PetscStackPop \ 391184914b5SBarry Smith {if (petscstack && petscstack->currentsize > 0) { \ 392184914b5SBarry Smith petscstack->currentsize--; \ 393184914b5SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 394184914b5SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 395184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = 0; \ 396184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 3975cd90555SBarry Smith }}; 398d64ed03dSBarry Smith 39930de9b25SBarry Smith /*MC 40030de9b25SBarry Smith PetscFunctionReturn - Last executable line of each PETSc function 40130de9b25SBarry Smith used for error handling. Replaces return() 40230de9b25SBarry Smith 40330de9b25SBarry Smith Synopsis: 40430de9b25SBarry Smith void PetscFunctionReturn(0); 40530de9b25SBarry Smith 40630de9b25SBarry Smith Usage: 40730de9b25SBarry Smith .vb 40830de9b25SBarry Smith .... 40930de9b25SBarry Smith PetscFunctionReturn(0); 41030de9b25SBarry Smith } 41130de9b25SBarry Smith .ve 41230de9b25SBarry Smith 41330de9b25SBarry Smith Notes: 41430de9b25SBarry Smith Not available in Fortran 41530de9b25SBarry Smith 41630de9b25SBarry Smith Level: developer 41730de9b25SBarry Smith 41830de9b25SBarry Smith .seealso: PetscFunctionBegin() 41930de9b25SBarry Smith 42030de9b25SBarry Smith .keywords: traceback, error handling 42130de9b25SBarry Smith M*/ 4225cd90555SBarry Smith #define PetscFunctionReturn(a) \ 423beb17490SBarry Smith {\ 42406d1fe2cSBarry Smith PetscStackPop; \ 4255cd90555SBarry Smith return(a);} 426d64ed03dSBarry Smith 427ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 428ff94ddecSSatish Balay {\ 4291fceb228SKris Buschelman PetscStackPop; \ 4301fceb228SKris Buschelman return;} 431ff94ddecSSatish Balay 4326d385327SIbrahima Ba 4336d385327SIbrahima Ba #else 4346d385327SIbrahima Ba 4353a40ed3dSBarry Smith #define PetscFunctionBegin 4363a40ed3dSBarry Smith #define PetscFunctionReturn(a) return(a) 4375665465eSBarry Smith #define PetscFunctionReturnVoid() return 438d64ed03dSBarry Smith #define PetscStackPop 439d64ed03dSBarry Smith #define PetscStackPush(f) 440d64ed03dSBarry Smith #define PetscStackActive 0 4413a40ed3dSBarry Smith 4423a40ed3dSBarry Smith #endif 4433a40ed3dSBarry Smith 444ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStackCreate(void); 445ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStackView(PetscViewer); 446ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStackDestroy(void); 447ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStackPublish(void); 448ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStackDepublish(void); 4493a40ed3dSBarry Smith 45006d1fe2cSBarry Smith 451e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END 45206d1fe2cSBarry Smith #endif 453