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 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 13330cf3c9SBarry Smith and bmake/common_variables includes in CCPPFLAGS -D__SDIR__=${LOCDIR} 14f621e05eSBarry Smith which is a flag passed to the C/C++ compilers. This declaration below 15f621e05eSBarry Smith is only needed if some code is compiled without the -D__SDIR__ 1654a8ef01SBarry Smith */ 17330cf3c9SBarry Smith #if !defined(__INSDIR__) 18330cf3c9SBarry Smith #define __INSDIR__ "unknowndirectory/" 1954a8ef01SBarry Smith #endif 2054a8ef01SBarry Smith 2154a8ef01SBarry Smith /* 224f227f7cSBarry Smith Defines the function where the compiled source is located; used 23f621e05eSBarry Smith in printing error messages. This is defined here in case the user 24f621e05eSBarry Smith does not declare it. 254f227f7cSBarry Smith */ 264a2ae208SSatish Balay #if !defined(__FUNCT__) 27da9b6338SBarry Smith #define __FUNCT__ "User provided function" 284f227f7cSBarry Smith #endif 294f227f7cSBarry Smith 304f227f7cSBarry Smith /* 31329ffe3dSLois Curfman McInnes These are the generic error codes. These error codes are used 32e2d1d2b7SBarry Smith many different places in the PETSc source code. The string versions are 330e5e90baSSatish Balay at src/sys/error/err.c any changes here must also be made there 340f9cf654SBarry Smith These are also define in include/finclude/petscerror.h any CHANGES here 350f9cf654SBarry Smith must be also made there. 3645d48df9SBarry Smith 3754a8ef01SBarry Smith */ 382a6744ebSBarry Smith #define PETSC_ERR_MIN_VALUE 54 /* should always be one less then the smallest value */ 392a6744ebSBarry Smith 4045d48df9SBarry Smith #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 4147794344SBarry Smith #define PETSC_ERR_SUP 56 /* no support for requested operation */ 42e2d1d2b7SBarry Smith #define PETSC_ERR_SUP_SYS 57 /* no support for requested operation on this computer system */ 43e2d1d2b7SBarry Smith #define PETSC_ERR_ORDER 58 /* operation done in wrong order */ 4445d48df9SBarry Smith #define PETSC_ERR_SIG 59 /* signal received */ 45f1caa5a4SBarry Smith #define PETSC_ERR_FP 72 /* floating point exception */ 46a8c6a408SBarry Smith #define PETSC_ERR_COR 74 /* corrupted PETSc object */ 47a8c6a408SBarry Smith #define PETSC_ERR_LIB 76 /* error in library called by PETSc */ 48329ffe3dSLois Curfman McInnes #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */ 49329ffe3dSLois Curfman McInnes #define PETSC_ERR_MEMC 78 /* memory corruption */ 50b3cc6726SBarry Smith #define PETSC_ERR_CONV_FAILED 82 /* iterative method (KSP or SNES) failed */ 511302d50aSBarry Smith #define PETSC_ERR_USER 83 /* user has not provided needed function */ 524e2ffeddSBarry Smith #define PETSC_ERR_SYS 88 /* error in system call */ 5345d48df9SBarry Smith 5445d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */ 5545d48df9SBarry Smith #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */ 56a8c6a408SBarry Smith #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */ 5745d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */ 5845d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */ 594f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */ 604f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */ 616831982aSBarry Smith #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */ 62d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */ 638cda6cd7SBarry Smith #define PETSC_ERR_ARG_TYPENOTSET 89 /* the type of the object has not yet been set */ 64a8c6a408SBarry Smith #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ 654482741eSBarry Smith #define PETSC_ERR_ARG_NULL 85 /* argument is null that should not be */ 66958c9bccSBarry Smith #define PETSC_ERR_ARG_UNKNOWN_TYPE 86 /* type name doesn't match any registered type */ 674f227f7cSBarry Smith 684f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ 694f227f7cSBarry Smith #define PETSC_ERR_FILE_READ 66 /* unable to read from file */ 704f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */ 71a8c6a408SBarry Smith #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */ 7245d48df9SBarry Smith 73329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */ 749e3b2f23SBarry Smith #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */ 7554a8ef01SBarry Smith 76bf3909cdSBarry Smith #define PETSC_ERR_FLOP_COUNT 90 77e113a28aSBarry Smith #define PETSC_ERR_NOT_CONVERGED 91 /* solver did not converge */ 78e113a28aSBarry Smith #define PETSC_ERR_MAX_VALUE 92 /* this is always the one more than the largest error code */ 792a6744ebSBarry Smith 8059aaf355SLisandro Dalcin #define PetscStringizeArg(a) #a 8159aaf355SLisandro Dalcin #define PetscStringize(a) PetscStringizeArg(a) 82330cf3c9SBarry Smith #define __SDIR__ PetscStringize(__INSDIR__) 83330cf3c9SBarry Smith 84e8b7e333SSatish Balay #if defined(PETSC_USE_ERRORCHECKING) 85e8b7e333SSatish Balay 8630de9b25SBarry Smith /*MC 8730de9b25SBarry Smith SETERRQ - Macro that is called when an error has been detected, 8830de9b25SBarry Smith 8930de9b25SBarry Smith Synopsis: 90e7e72b3dSBarry Smith PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode errorcode,char *message) 9130de9b25SBarry Smith 92eca87e8dSBarry Smith Not Collective 9330de9b25SBarry Smith 9430de9b25SBarry Smith Input Parameters: 9530de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 9630de9b25SBarry Smith - message - error message 9730de9b25SBarry Smith 9830de9b25SBarry Smith Level: beginner 9930de9b25SBarry Smith 10030de9b25SBarry Smith Notes: 10130de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 10230de9b25SBarry Smith 10330de9b25SBarry Smith See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments 10430de9b25SBarry Smith 10558ebbce7SBarry Smith In Fortran MPI_Abort() is always called 10630de9b25SBarry Smith 10730de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 10830de9b25SBarry Smith 10930de9b25SBarry Smith Concepts: error^setting condition 11030de9b25SBarry Smith 11191d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3() 11230de9b25SBarry Smith M*/ 11353c77d0aSJed Brown #define SETERRQ(comm,n,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s) 11430de9b25SBarry Smith 11530de9b25SBarry Smith /*MC 11630de9b25SBarry Smith SETERRQ1 - Macro that is called when an error has been detected, 11730de9b25SBarry Smith 11830de9b25SBarry Smith Synopsis: 119e32f2f54SBarry Smith PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg) 12030de9b25SBarry Smith 121eca87e8dSBarry Smith Not Collective 12230de9b25SBarry Smith 12330de9b25SBarry Smith Input Parameters: 12430de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 12530de9b25SBarry Smith . message - error message in the printf format 12630de9b25SBarry Smith - arg - argument (for example an integer, string or double) 12730de9b25SBarry Smith 12830de9b25SBarry Smith Level: beginner 12930de9b25SBarry Smith 13030de9b25SBarry Smith Notes: 13130de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 13230de9b25SBarry Smith 13330de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 13430de9b25SBarry Smith 13530de9b25SBarry Smith Concepts: error^setting condition 13630de9b25SBarry Smith 13791d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3() 13830de9b25SBarry Smith M*/ 13953c77d0aSJed Brown #define SETERRQ1(comm,n,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1) 14030de9b25SBarry Smith 14130de9b25SBarry Smith /*MC 14230de9b25SBarry Smith SETERRQ2 - Macro that is called when an error has been detected, 14330de9b25SBarry Smith 14430de9b25SBarry Smith Synopsis: 145f4442326SMatthew Knepley PetscErrorCode SETERRQ2(PetscErrorCode errorcode,char *formatmessage,arg1,arg2) 14630de9b25SBarry Smith 147eca87e8dSBarry Smith Not Collective 14830de9b25SBarry Smith 14930de9b25SBarry Smith Input Parameters: 15030de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 15130de9b25SBarry Smith . message - error message in the printf format 15230de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 15330de9b25SBarry Smith - arg2 - argument (for example an integer, string or double) 15430de9b25SBarry Smith 15530de9b25SBarry Smith Level: beginner 15630de9b25SBarry Smith 15730de9b25SBarry Smith Notes: 15830de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 15930de9b25SBarry Smith 16030de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 16130de9b25SBarry Smith 16230de9b25SBarry Smith Concepts: error^setting condition 16330de9b25SBarry Smith 1646024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3() 16530de9b25SBarry Smith M*/ 16653c77d0aSJed Brown #define SETERRQ2(comm,n,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2) 16730de9b25SBarry Smith 16830de9b25SBarry Smith /*MC 16930de9b25SBarry Smith SETERRQ3 - Macro that is called when an error has been detected, 17030de9b25SBarry Smith 17130de9b25SBarry Smith Synopsis: 172f4442326SMatthew Knepley PetscErrorCode SETERRQ3(PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 17330de9b25SBarry Smith 174eca87e8dSBarry Smith Not Collective 17530de9b25SBarry Smith 17630de9b25SBarry Smith Input Parameters: 17730de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 17830de9b25SBarry Smith . message - error message in the printf format 17930de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 18030de9b25SBarry Smith . arg2 - argument (for example an integer, string or double) 18130de9b25SBarry Smith - arg3 - argument (for example an integer, string or double) 18230de9b25SBarry Smith 18330de9b25SBarry Smith Level: beginner 18430de9b25SBarry Smith 18530de9b25SBarry Smith Notes: 18630de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 18730de9b25SBarry Smith 188f621e05eSBarry Smith There are also versions for 4, 5, 6 and 7 arguments. 189f621e05eSBarry Smith 19030de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 19130de9b25SBarry Smith 19230de9b25SBarry Smith Concepts: error^setting condition 19330de9b25SBarry Smith 1946024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 19530de9b25SBarry Smith M*/ 19653c77d0aSJed Brown #define SETERRQ3(comm,n,s,a1,a2,a3) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3) 19730de9b25SBarry Smith 19853c77d0aSJed Brown #define SETERRQ4(comm,n,s,a1,a2,a3,a4) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4) 19953c77d0aSJed Brown #define SETERRQ5(comm,n,s,a1,a2,a3,a4,a5) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5) 20053c77d0aSJed Brown #define SETERRQ6(comm,n,s,a1,a2,a3,a4,a5,a6) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6) 20153c77d0aSJed Brown #define SETERRQ7(comm,n,s,a1,a2,a3,a4,a5,a6,a7) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7) 20253c77d0aSJed Brown #define SETERRABORT(comm,n,s) do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,n);} while (0) 2039a00fa46SSatish Balay 20430de9b25SBarry Smith /*MC 20530de9b25SBarry Smith CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns 20630de9b25SBarry Smith 20730de9b25SBarry Smith Synopsis: 208f4442326SMatthew Knepley PetscErrorCode CHKERRQ(PetscErrorCode errorcode) 20930de9b25SBarry Smith 210eca87e8dSBarry Smith Not Collective 21130de9b25SBarry Smith 21230de9b25SBarry Smith Input Parameters: 21330de9b25SBarry Smith . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 21430de9b25SBarry Smith 21530de9b25SBarry Smith Level: beginner 21630de9b25SBarry Smith 21730de9b25SBarry Smith Notes: 21830de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 21930de9b25SBarry Smith 22030de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 2215324ea47SKris Buschelman 222fcecf507SKris Buschelman CHKERRQ(n) is fundamentally a macro replacement for 2235324ea47SKris Buschelman if (n) return(PetscError(...,n,...)); 2245324ea47SKris Buschelman 2255324ea47SKris Buschelman Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is 2265324ea47SKris Buschelman highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular, 2275324ea47SKris Buschelman it cannot be used in functions which return(void) or any other datatype. In these types of functions, 22858ebbce7SBarry Smith you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or 2295324ea47SKris Buschelman if (n) {PetscError(....); return(YourReturnType);} 23058ebbce7SBarry Smith where you may pass back a PETSC_NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have 23158ebbce7SBarry Smith MPI_Abort() returned immediately. 23258ebbce7SBarry Smith 23358ebbce7SBarry Smith In Fortran MPI_Abort() is always called 23430de9b25SBarry Smith 23530de9b25SBarry Smith Concepts: error^setting condition 23630de9b25SBarry Smith 23791d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2() 23830de9b25SBarry Smith M*/ 23953c77d0aSJed Brown #define CHKERRQ(n) do {if (PetscUnlikely(n)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");} while (0) 24030de9b25SBarry Smith 24153c77d0aSJed Brown #define CHKERRV(n) do {if (PetscUnlikely(n)) {n = PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");return;}} while(0) 24253c77d0aSJed Brown #define CHKERRABORT(comm,n) do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");MPI_Abort(comm,n);}} while (0) 24353c77d0aSJed Brown #define CHKERRCONTINUE(n) do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," ");}} while (0) 24485614651SBarry Smith 245fd705b32SMatthew Knepley #ifdef PETSC_CLANGUAGE_CXX 246fd705b32SMatthew Knepley 247cc26af49SMatthew Knepley /*MC 248cc26af49SMatthew Knepley CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception 249cc26af49SMatthew Knepley 250cc26af49SMatthew Knepley Synopsis: 251cc26af49SMatthew Knepley void CHKERRXX(PetscErrorCode errorcode) 252cc26af49SMatthew Knepley 253eca87e8dSBarry Smith Not Collective 254cc26af49SMatthew Knepley 255cc26af49SMatthew Knepley Input Parameters: 256cc26af49SMatthew Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 257cc26af49SMatthew Knepley 258cc26af49SMatthew Knepley Level: beginner 259cc26af49SMatthew Knepley 260cc26af49SMatthew Knepley Notes: 261cc26af49SMatthew Knepley Once the error handler throws a ??? exception. 262cc26af49SMatthew Knepley 263cc26af49SMatthew Knepley You can use CHKERRV() which returns without an error code (bad idea since the error is ignored) 264cc26af49SMatthew Knepley or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately. 265cc26af49SMatthew Knepley 266cc26af49SMatthew Knepley Concepts: error^setting condition 267cc26af49SMatthew Knepley 268cc26af49SMatthew Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ 269cc26af49SMatthew Knepley M*/ 27053c77d0aSJed Brown #define CHKERRXX(n) do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_IN_CXX,0);}} while(0) 271fd705b32SMatthew Knepley 272fd705b32SMatthew Knepley #endif 273fd705b32SMatthew Knepley 27430de9b25SBarry Smith /*MC 27530de9b25SBarry Smith CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected 27630de9b25SBarry Smith 27730de9b25SBarry Smith Synopsis: 27891d3bdf4SKris Buschelman CHKMEMQ; 27930de9b25SBarry Smith 280eca87e8dSBarry Smith Not Collective 281eca87e8dSBarry Smith 28230de9b25SBarry Smith Level: beginner 28330de9b25SBarry Smith 28430de9b25SBarry Smith Notes: 285ff002950SBarry Smith Must run with the option -malloc_debug to enable this option 28630de9b25SBarry Smith 28730de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 28830de9b25SBarry Smith 28930de9b25SBarry Smith By defaults prints location where memory that is corrupted was allocated. 29030de9b25SBarry Smith 291f621e05eSBarry Smith Use CHKMEMA for functions that return void 292f621e05eSBarry Smith 29330de9b25SBarry Smith Concepts: memory corruption 29430de9b25SBarry Smith 2956024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), 296ff002950SBarry Smith PetscMallocValidate() 29730de9b25SBarry Smith M*/ 29853c77d0aSJed Brown #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__);CHKERRQ(_7_ierr);} while(0) 29985614651SBarry Smith 30053c77d0aSJed Brown #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__) 301e68848bdSBarry Smith 3029dd39edbSMatthew Knepley #if defined(PETSC_UNDERSCORE_CHKERR) 3036849ba73SBarry Smith extern PetscErrorCode __gierr; 304f1af5d2fSBarry Smith #define _ __gierr = 305ac355199SBarry Smith #define ___ CHKERRQ(__gierr); 306f1af5d2fSBarry Smith #endif 307f1af5d2fSBarry Smith 308d5e45103SBarry Smith #define PETSC_EXCEPTIONS_MAX 256 309d5e45103SBarry Smith extern PetscErrorCode PetscErrorUncatchable[PETSC_EXCEPTIONS_MAX]; 310d5e45103SBarry Smith extern PetscInt PetscErrorUncatchableCount; 311d5e45103SBarry Smith extern PetscErrorCode PetscExceptions[PETSC_EXCEPTIONS_MAX]; 312d5e45103SBarry Smith extern PetscInt PetscExceptionsCount; 313d5e45103SBarry Smith 314*7087cfbeSBarry Smith extern PetscErrorCode PetscExceptionPush(PetscErrorCode); 315*7087cfbeSBarry Smith extern PetscErrorCode PetscExceptionPop(PetscErrorCode); 316d5e45103SBarry Smith 317*7087cfbeSBarry Smith extern PetscErrorCode PetscErrorSetCatchable(PetscErrorCode,PetscBool ); 318*7087cfbeSBarry Smith extern PetscBool PetscErrorIsCatchable(PetscErrorCode); 31975febeb1SBarry Smith /*MC 32021dd7e22SBarry Smith PetscExceptionCaught - Indicates if a specific exception zierr was caught. 32175febeb1SBarry Smith 32275febeb1SBarry Smith Synopsis: 323ace3abfcSBarry Smith PetscBool PetscExceptionCaught(PetscErrorCode xierr,PetscErrorCode zierr); 32475febeb1SBarry Smith 325eca87e8dSBarry Smith Not Collective 326eca87e8dSBarry Smith 32775febeb1SBarry Smith Input Parameters: 3281853238fSBarry Smith + xierr - error code returned from PetscExceptionTry1() or other PETSc routine 32975febeb1SBarry Smith - zierr - error code you want it to be 33075febeb1SBarry Smith 33175febeb1SBarry Smith Level: advanced 33275febeb1SBarry Smith 33375febeb1SBarry Smith Notes: 33475febeb1SBarry Smith PETSc must not be configured using the option --with-errorchecking=0 for this to work 33575febeb1SBarry Smith 3361853238fSBarry Smith Use PetscExceptionValue() to see if an error code is being "tried" 33721dd7e22SBarry Smith 3381853238fSBarry Smith Concepts: exceptions, exception handling 33975febeb1SBarry Smith 34075febeb1SBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), 34175febeb1SBarry Smith CHKERRQ(), PetscExceptionTry1(), PetscExceptionValue() 34275febeb1SBarry Smith M*/ 343ace3abfcSBarry Smith PETSC_STATIC_INLINE PetscBool PetscExceptionCaught(PetscErrorCode xierr,PetscErrorCode zierr) 344d0f46423SBarry Smith { 345d5e45103SBarry Smith PetscInt i; 346d5e45103SBarry Smith if (xierr != zierr) return PETSC_FALSE; 347d5e45103SBarry Smith for (i=0; i<PetscErrorUncatchableCount; i++) { 348d5e45103SBarry Smith if (PetscErrorUncatchable[i] == zierr) { 349d5e45103SBarry Smith return PETSC_FALSE; 350d5e45103SBarry Smith } 351d5e45103SBarry Smith } 352d5e45103SBarry Smith return PETSC_TRUE; 353d5e45103SBarry Smith } 354d5e45103SBarry Smith 35575febeb1SBarry Smith /*MC 35675febeb1SBarry Smith PetscExceptionValue - Indicates if the error code is one that is currently being tried 357d5e45103SBarry Smith 35875febeb1SBarry Smith Synopsis: 359ace3abfcSBarry Smith PetscBool PetscExceptionValue(PetscErrorCode xierr); 36075febeb1SBarry Smith 361eca87e8dSBarry Smith Not Collective 362eca87e8dSBarry Smith 36375febeb1SBarry Smith Input Parameters: 36475febeb1SBarry Smith . xierr - error code 36575febeb1SBarry Smith 36675febeb1SBarry Smith Level: developer 36775febeb1SBarry Smith 36875febeb1SBarry Smith Notes: 36975febeb1SBarry Smith PETSc must not be configured using the option --with-errorchecking=0 for this to work 37075febeb1SBarry Smith 37121dd7e22SBarry Smith Use PetscExceptionCaught() to see if the current error code is EXACTLY the one you want 37221dd7e22SBarry Smith 37375febeb1SBarry Smith Concepts: exceptions, exception hanlding 37475febeb1SBarry Smith 37575febeb1SBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), 37675febeb1SBarry Smith CHKERRQ(), PetscExceptionTry1(), PetscExceptionCaught() 37775febeb1SBarry Smith M*/ 378ace3abfcSBarry Smith PETSC_STATIC_INLINE PetscBool PetscExceptionValue(PetscErrorCode zierr) 379d0f46423SBarry Smith { 380d5e45103SBarry Smith PetscInt i; 381d5e45103SBarry Smith for (i=0; i<PetscExceptionsCount; i++) { 382d5e45103SBarry Smith if (PetscExceptions[i] == zierr) { 383d5e45103SBarry Smith return PETSC_TRUE; 384d5e45103SBarry Smith } 385d5e45103SBarry Smith } 386d5e45103SBarry Smith return PETSC_FALSE; 387d5e45103SBarry Smith } 3886024bd2cSBarry Smith 3896024bd2cSBarry Smith /*MC 3906024bd2cSBarry Smith PetscExceptionTry1 - Runs the routine, causing a particular error code to be treated as an exception, 3916024bd2cSBarry Smith rather than an error. That is if that error code is treated the program returns to this level, 3926024bd2cSBarry Smith but does not call the error handlers 3936024bd2cSBarry Smith 3946024bd2cSBarry Smith Synopsis: 3951853238fSBarry Smith PetscErrorCode PetscExceptionTry1(PetscErrorCode routine(....),PetscErrorCode); 3966024bd2cSBarry Smith 397eca87e8dSBarry Smith Not Collective 398eca87e8dSBarry Smith 3996024bd2cSBarry Smith Level: advanced 4006024bd2cSBarry Smith 4011853238fSBarry Smith No Fortran Equivalent (see PetscExceptionPush() for Fortran) 4021853238fSBarry Smith 4036024bd2cSBarry Smith Notes: 4046024bd2cSBarry Smith PETSc must not be configured using the option --with-errorchecking=0 for this to work 4056024bd2cSBarry Smith 40675febeb1SBarry Smith Note: In general, the outer most try on an exception is the one that will be caught (that is trys down in 40775febeb1SBarry Smith PETSc code will not usually handle an exception that was issued above). See SNESSolve() for an example 40875febeb1SBarry Smith of how the local try is ignored if a higher (in the stack) one is also in effect. 4096024bd2cSBarry Smith 4106024bd2cSBarry Smith Concepts: exceptions, exception hanlding 4116024bd2cSBarry Smith 4126024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), 41321dd7e22SBarry Smith CHKERRQ(), PetscExceptionCaught(), PetscExceptionPush(), PetscExceptionPop() 4146024bd2cSBarry Smith M*/ 4157b0215c6SHong Zhang extern PetscErrorCode PetscExceptionTmp,PetscExceptionTmp1; 4167b0215c6SHong Zhang #define PetscExceptionTry1(a,b) (PetscExceptionTmp1 = PetscExceptionPush(b)) ? PetscExceptionTmp1 : (PetscExceptionTmp1 = a, (PetscExceptionTmp = PetscExceptionPop(b)) ? PetscExceptionTmp : PetscExceptionTmp1) 4176024bd2cSBarry Smith 418f70662edSBarry Smith /* 419f70662edSBarry Smith Used by PetscExceptionTrySync(). Returns zierr on ALL processes in comm iff xierr is zierr on at least one process and zero on all others. 420f70662edSBarry Smith */ 421f70662edSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscExceptionTrySync_Private(MPI_Comm comm,PetscErrorCode xierr,PetscErrorCode zierr) 422f70662edSBarry Smith { 423f70662edSBarry Smith PetscReal in[2],out[2]; 424f70662edSBarry Smith PetscErrorCode ierr; 425f70662edSBarry Smith 426f70662edSBarry Smith if (xierr != zierr) return xierr; 427f70662edSBarry Smith 428f70662edSBarry Smith in[0] = xierr; 429f70662edSBarry Smith in[1] = 0.0; /* dummy value */ 430f70662edSBarry Smith 431f70662edSBarry Smith ierr = MPI_Allreduce(in,out,2,MPIU_REAL,0,comm); if (ierr) {;} 432f70662edSBarry Smith return xierr; 433f70662edSBarry Smith } 434f70662edSBarry Smith 435f70662edSBarry Smith /*MC 436f70662edSBarry Smith PetscExceptionTrySyncNorm - Runs the routine, causing a particular error code to be treated as an exception, 437f70662edSBarry Smith rather than an error. That is if that error code is treated the program returns to this level, 438f70662edSBarry Smith but does not call the error handlers 439f70662edSBarry Smith 440f70662edSBarry Smith Synopsis: 441f70662edSBarry Smith PetscExceptionTrySyncNorm(MPI_Comm comm,PetscErrorCode routine(....),PetscErrorCode); 442f70662edSBarry Smith 443eca87e8dSBarry Smith Collective on Comm 444eca87e8dSBarry Smith 445f70662edSBarry Smith Level: advanced 446f70662edSBarry Smith 447f70662edSBarry Smith Notes: This synchronizes the error code across all processes in the communicator IF the code matches PetscErrorCode. The next 448f70662edSBarry Smith call with an MPI_Reduce()/MPI_Allreduce() MUST be VecNorm() [We can added VecDot() and maybe others as needed]. 449f70662edSBarry Smith 450f70662edSBarry Smith PETSc must not be configured using the option --with-errorchecking=0 for this to work 451f70662edSBarry Smith 452f70662edSBarry Smith Note: In general, the outer most try on an exception is the one that will be caught (that is trys down in 453f70662edSBarry Smith PETSc code will not usually handle an exception that was issued above). See SNESSolve() for an example 454f70662edSBarry Smith of how the local try is ignored if a higher (in the stack) one is also in effect. 455f70662edSBarry Smith 456f70662edSBarry Smith Concepts: exceptions, exception hanlding 457f70662edSBarry Smith 458f70662edSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), 459f70662edSBarry Smith CHKERRQ(), PetscExceptionCaught(), PetscExceptionPush(), PetscExceptionPop(), PetscExceptionTry1() 460f70662edSBarry Smith M*/ 461f70662edSBarry Smith #define PetscExceptionTrySyncNorm(comm,a,b) (PetscExceptionTmp = PetscExceptionPush(b)) ? PetscExceptionTmp : \ 462f70662edSBarry Smith (PetscExceptionTmp = a , PetscExceptionPop(b),PetscExceptionTrySyncNorm_Private(comm,PetscExceptionTmp,b)) 463f70662edSBarry Smith 46454a8ef01SBarry Smith #else 465f621e05eSBarry Smith 466f621e05eSBarry Smith /* 467e2e64c6bSBarry Smith These are defined to be empty for when error checking is turned off, with ./configure --with-errorchecking=0 468f621e05eSBarry Smith */ 469f621e05eSBarry Smith 4704b209cf6SBarry Smith #define SETERRQ(c,n,s) 4714b209cf6SBarry Smith #define SETERRQ1(c,n,s,a1) 4724b209cf6SBarry Smith #define SETERRQ2(c,n,s,a1,a2) 4734b209cf6SBarry Smith #define SETERRQ3(c,n,s,a1,a2,a3) 4744b209cf6SBarry Smith #define SETERRQ4(c,n,s,a1,a2,a3,a4) 4754b209cf6SBarry Smith #define SETERRQ5(c,n,s,a1,a2,a3,a4,a5) 4764b209cf6SBarry Smith #define SETERRQ6(c,n,s,a1,a2,a3,a4,a5,a6) 4774b209cf6SBarry Smith #define SETERRABORT(comm,n,s) 47885614651SBarry Smith 4794f227f7cSBarry Smith #define CHKERRQ(n) ; 4801ee4faa0SMatthew Knepley #define CHKERRABORT(comm,n) ; 4811ee4faa0SMatthew Knepley #define CHKERRCONTINUE(n) ; 48285614651SBarry Smith #define CHKMEMQ ; 48385614651SBarry Smith 4848cabf42eSMatthew G Knepley #ifdef PETSC_CLANGUAGE_CXX 4858cabf42eSMatthew G Knepley #define CHKERRXX(n) ; 4868cabf42eSMatthew G Knepley #endif 4878cabf42eSMatthew G Knepley 488f1af5d2fSBarry Smith #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 489f1af5d2fSBarry Smith #define _ 490f1af5d2fSBarry Smith #define ___ 491f1af5d2fSBarry Smith #endif 492f1af5d2fSBarry Smith 4938da67ba8SSatish Balay #define PetscExceptionPush(a) 0 4941853238fSBarry Smith #define PetscExceptionPop(a) 0 495c132512eSBarry Smith #define PetscErrorSetCatchable(a,b) 0 4968da67ba8SSatish Balay #define PetscErrorIsCatchable(a) PETSC_FALSE 4978da67ba8SSatish Balay 498c132512eSBarry Smith #define PetscExceptionCaught(a,b) PETSC_FALSE 499c132512eSBarry Smith #define PetscExceptionValue(a) PETSC_FALSE 5006024bd2cSBarry Smith #define PetscExceptionTry1(a,b) a 501f70662edSBarry Smith #define PetscExceptionTrySyncNorm(comm,a,b) a 502f70662edSBarry Smith 50354a8ef01SBarry Smith #endif 50454a8ef01SBarry Smith 505668f157eSBarry Smith /*E 506668f157eSBarry Smith PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers 507668f157eSBarry Smith 508668f157eSBarry Smith Level: advanced 509668f157eSBarry Smith 510d736bfebSBarry Smith PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated 511d736bfebSBarry Smith 512668f157eSBarry Smith Developer Notes: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandling() 513668f157eSBarry Smith 514d736bfebSBarry Smith .seealso: PetscError(), SETERRXX() 515668f157eSBarry Smith E*/ 516d736bfebSBarry Smith typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType; 5174b209cf6SBarry Smith 518*7087cfbeSBarry Smith extern PetscErrorCode PetscErrorPrintfInitialize(void); 519*7087cfbeSBarry Smith extern PetscErrorCode PetscErrorMessage(int,const char*[],char **); 520*7087cfbeSBarry Smith extern PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 5210577ce7cSSatish Balay #if defined(PETSC_CLANGUAGE_CXX) && !defined(PETSC_USE_EXTERN_CXX) 522fd705b32SMatthew Knepley #include <sstream> 523*7087cfbeSBarry Smith extern PetscErrorCode PetscTraceBackErrorHandlerCxx(MPI_Comm,int,const char *,const char *,const char *,PetscErrorCode,PetscErrorType,const char*,void*); 524fd705b32SMatthew Knepley #endif 525*7087cfbeSBarry Smith extern PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 526*7087cfbeSBarry Smith extern PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 527*7087cfbeSBarry Smith extern PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 528*7087cfbeSBarry Smith extern PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 529*7087cfbeSBarry Smith extern PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 530*7087cfbeSBarry Smith extern PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 531*7087cfbeSBarry Smith extern PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...); 532*7087cfbeSBarry Smith extern PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*); 533*7087cfbeSBarry Smith extern PetscErrorCode PetscPopErrorHandler(void); 534*7087cfbeSBarry Smith extern PetscErrorCode PetscDefaultSignalHandler(int,void*); 535*7087cfbeSBarry Smith extern PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*); 536*7087cfbeSBarry Smith extern PetscErrorCode PetscPopSignalHandler(void); 537329f5518SBarry Smith 538329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 539*7087cfbeSBarry Smith extern PetscErrorCode PetscSetFPTrap(PetscFPTrap); 54054a8ef01SBarry Smith 5413a40ed3dSBarry Smith /* 5423a40ed3dSBarry Smith Allows the code to build a stack frame as it runs 5433a40ed3dSBarry Smith */ 54463d6bff0SBarry Smith #if defined(PETSC_USE_DEBUG) && !defined(PETSC_USE_PTHREAD) 5453a40ed3dSBarry Smith 54699cd645aSJed Brown #define PETSCSTACKSIZE 64 547184914b5SBarry Smith 5483a40ed3dSBarry Smith typedef struct { 5490e33f6ddSBarry Smith const char *function[PETSCSTACKSIZE]; 5500e33f6ddSBarry Smith const char *file[PETSCSTACKSIZE]; 5510e33f6ddSBarry Smith const char *directory[PETSCSTACKSIZE]; 552184914b5SBarry Smith int line[PETSCSTACKSIZE]; 553184914b5SBarry Smith int currentsize; 5543a40ed3dSBarry Smith } PetscStack; 5553a40ed3dSBarry Smith 556*7087cfbeSBarry Smith extern PetscStack *petscstack; 557*7087cfbeSBarry Smith extern PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*); 558*7087cfbeSBarry Smith extern PetscErrorCode PetscStackPrint(PetscStack*,FILE* fp); 559184914b5SBarry Smith 560184914b5SBarry Smith #define PetscStackActive (petscstack != 0) 5613a40ed3dSBarry Smith 56230de9b25SBarry Smith /*MC 56330de9b25SBarry Smith PetscFunctionBegin - First executable line of each PETSc function 56430de9b25SBarry Smith used for error handling. 56530de9b25SBarry Smith 56630de9b25SBarry Smith Synopsis: 56730de9b25SBarry Smith void PetscFunctionBegin; 56830de9b25SBarry Smith 569eca87e8dSBarry Smith Not Collective 570eca87e8dSBarry Smith 57130de9b25SBarry Smith Usage: 57230de9b25SBarry Smith .vb 57330de9b25SBarry Smith int something; 57430de9b25SBarry Smith 57530de9b25SBarry Smith PetscFunctionBegin; 57630de9b25SBarry Smith .ve 57730de9b25SBarry Smith 57830de9b25SBarry Smith Notes: 57930de9b25SBarry Smith Not available in Fortran 58030de9b25SBarry Smith 58130de9b25SBarry Smith Level: developer 58230de9b25SBarry Smith 58330de9b25SBarry Smith .seealso: PetscFunctionReturn() 58430de9b25SBarry Smith 58530de9b25SBarry Smith .keywords: traceback, error handling 58630de9b25SBarry Smith M*/ 5873a40ed3dSBarry Smith #define PetscFunctionBegin \ 5888246ba0dSJed Brown do { \ 589184914b5SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 59053c77d0aSJed Brown petscstack->function[petscstack->currentsize] = PETSC_FUNCTION_NAME; \ 591184914b5SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 592184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = __SDIR__; \ 593184914b5SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 594184914b5SBarry Smith petscstack->currentsize++; \ 59553c77d0aSJed Brown } \ 59653c77d0aSJed Brown PetscCheck__FUNCT__(); \ 59753c77d0aSJed Brown } while (0) 59853c77d0aSJed Brown 59953c77d0aSJed Brown #define PetscCheck__FUNCT__() do { \ 60053c77d0aSJed Brown if (strcmp(PETSC_FUNCTION_NAME,__FUNCT__) && strcmp(__FUNCT__,"User provided function")) { \ 60153c77d0aSJed Brown (*PetscErrorPrintf)("%s%s:%d: __FUNCT__=\"%s\" does not agree with %s=\"%s\"\n",__SDIR__,__FILE__,__LINE__,__FUNCT__,PetscStringize(PETSC_FUNCTION_NAME),PETSC_FUNCTION_NAME); \ 60253c77d0aSJed Brown } \ 60353c77d0aSJed Brown } while (0) 6043a40ed3dSBarry Smith 6055cd90555SBarry Smith #define PetscStackPush(n) \ 6068246ba0dSJed Brown do {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 607184914b5SBarry Smith petscstack->function[petscstack->currentsize] = n; \ 608184914b5SBarry Smith petscstack->file[petscstack->currentsize] = "unknown"; \ 609184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = "unknown"; \ 610184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 611184914b5SBarry Smith petscstack->currentsize++; \ 612812af9f3SBarry Smith } CHKMEMQ;} while (0) 6133a40ed3dSBarry Smith 614d64ed03dSBarry Smith #define PetscStackPop \ 615812af9f3SBarry Smith do {CHKMEMQ; if (petscstack && petscstack->currentsize > 0) { \ 616184914b5SBarry Smith petscstack->currentsize--; \ 617184914b5SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 618184914b5SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 619184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = 0; \ 620184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 6218246ba0dSJed Brown }} while (0) 622d64ed03dSBarry Smith 62330de9b25SBarry Smith /*MC 62430de9b25SBarry Smith PetscFunctionReturn - Last executable line of each PETSc function 62530de9b25SBarry Smith used for error handling. Replaces return() 62630de9b25SBarry Smith 62730de9b25SBarry Smith Synopsis: 62830de9b25SBarry Smith void PetscFunctionReturn(0); 62930de9b25SBarry Smith 630eca87e8dSBarry Smith Not Collective 631eca87e8dSBarry Smith 63230de9b25SBarry Smith Usage: 63330de9b25SBarry Smith .vb 63430de9b25SBarry Smith .... 63530de9b25SBarry Smith PetscFunctionReturn(0); 63630de9b25SBarry Smith } 63730de9b25SBarry Smith .ve 63830de9b25SBarry Smith 63930de9b25SBarry Smith Notes: 64030de9b25SBarry Smith Not available in Fortran 64130de9b25SBarry Smith 64230de9b25SBarry Smith Level: developer 64330de9b25SBarry Smith 64430de9b25SBarry Smith .seealso: PetscFunctionBegin() 64530de9b25SBarry Smith 64630de9b25SBarry Smith .keywords: traceback, error handling 64730de9b25SBarry Smith M*/ 6485cd90555SBarry Smith #define PetscFunctionReturn(a) \ 6498246ba0dSJed Brown do {\ 650812af9f3SBarry Smith if (petscstack && petscstack->currentsize > 0) { \ 651812af9f3SBarry Smith petscstack->currentsize--; \ 652812af9f3SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 653812af9f3SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 654812af9f3SBarry Smith petscstack->directory[petscstack->currentsize] = 0; \ 655812af9f3SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 656812af9f3SBarry Smith }\ 6578246ba0dSJed Brown return(a);} while (0) 658d64ed03dSBarry Smith 659ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 6608246ba0dSJed Brown do {\ 661812af9f3SBarry Smith if (petscstack && petscstack->currentsize > 0) { \ 662812af9f3SBarry Smith petscstack->currentsize--; \ 663812af9f3SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 664812af9f3SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 665812af9f3SBarry Smith petscstack->directory[petscstack->currentsize] = 0; \ 666812af9f3SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 667812af9f3SBarry Smith }\ 6688246ba0dSJed Brown return;} while (0) 669ff94ddecSSatish Balay 6706d385327SIbrahima Ba #else 6716d385327SIbrahima Ba 6723a40ed3dSBarry Smith #define PetscFunctionBegin 6733a40ed3dSBarry Smith #define PetscFunctionReturn(a) return(a) 6745665465eSBarry Smith #define PetscFunctionReturnVoid() return 675812af9f3SBarry Smith #define PetscStackPop CHKMEMQ 676812af9f3SBarry Smith #define PetscStackPush(f) CHKMEMQ 677d64ed03dSBarry Smith #define PetscStackActive 0 6783a40ed3dSBarry Smith 6793a40ed3dSBarry Smith #endif 6803a40ed3dSBarry Smith 681eb6b5d47SBarry Smith /* 682eb6b5d47SBarry Smith PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack. 683eb6b5d47SBarry Smith 684eb6b5d47SBarry Smith Input Parameters: 685eb6b5d47SBarry Smith + name - string that gives the name of the function being called 686eb6b5d47SBarry Smith - routine - actual call to the routine 687eb6b5d47SBarry Smith 688eb6b5d47SBarry 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. 689eb6b5d47SBarry Smith 690eb6b5d47SBarry Smith */ 691eb6b5d47SBarry Smith #define PetscStackCall(name,routine) PetscStackPush(name);routine;PetscStackPop; 692eb6b5d47SBarry Smith 693*7087cfbeSBarry Smith extern PetscErrorCode PetscStackCreate(void); 694*7087cfbeSBarry Smith extern PetscErrorCode PetscStackView(PetscViewer); 695*7087cfbeSBarry Smith extern PetscErrorCode PetscStackDestroy(void); 696*7087cfbeSBarry Smith extern PetscErrorCode PetscStackPublish(void); 697*7087cfbeSBarry Smith extern PetscErrorCode PetscStackDepublish(void); 6983a40ed3dSBarry Smith 69906d1fe2cSBarry Smith 700e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END 70106d1fe2cSBarry Smith #endif 702