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 /* 84f227f7cSBarry Smith Defines the function where the compiled source is located; used 9f621e05eSBarry Smith in printing error messages. This is defined here in case the user 10f621e05eSBarry Smith does not declare it. 114f227f7cSBarry Smith */ 124a2ae208SSatish Balay #if !defined(__FUNCT__) 13da9b6338SBarry Smith #define __FUNCT__ "User provided function" 144f227f7cSBarry Smith #endif 154f227f7cSBarry Smith 164f227f7cSBarry Smith /* 17329ffe3dSLois Curfman McInnes These are the generic error codes. These error codes are used 18e2d1d2b7SBarry Smith many different places in the PETSc source code. The string versions are 190e5e90baSSatish Balay at src/sys/error/err.c any changes here must also be made there 20af0996ceSBarry Smith These are also define in include/petsc/finclude/petscerror.h any CHANGES here 210f9cf654SBarry Smith must be also made there. 2245d48df9SBarry Smith 2354a8ef01SBarry Smith */ 242a6744ebSBarry Smith #define PETSC_ERR_MIN_VALUE 54 /* should always be one less then the smallest value */ 252a6744ebSBarry Smith 2645d48df9SBarry Smith #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 2747794344SBarry Smith #define PETSC_ERR_SUP 56 /* no support for requested operation */ 28e2d1d2b7SBarry Smith #define PETSC_ERR_SUP_SYS 57 /* no support for requested operation on this computer system */ 29e2d1d2b7SBarry Smith #define PETSC_ERR_ORDER 58 /* operation done in wrong order */ 3045d48df9SBarry Smith #define PETSC_ERR_SIG 59 /* signal received */ 31f1caa5a4SBarry Smith #define PETSC_ERR_FP 72 /* floating point exception */ 32a8c6a408SBarry Smith #define PETSC_ERR_COR 74 /* corrupted PETSc object */ 33a8c6a408SBarry Smith #define PETSC_ERR_LIB 76 /* error in library called by PETSc */ 34329ffe3dSLois Curfman McInnes #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */ 35329ffe3dSLois Curfman McInnes #define PETSC_ERR_MEMC 78 /* memory corruption */ 36b3cc6726SBarry Smith #define PETSC_ERR_CONV_FAILED 82 /* iterative method (KSP or SNES) failed */ 371302d50aSBarry Smith #define PETSC_ERR_USER 83 /* user has not provided needed function */ 384e2ffeddSBarry Smith #define PETSC_ERR_SYS 88 /* error in system call */ 39a8b45ee7SBarry Smith #define PETSC_ERR_POINTER 70 /* pointer does not point to valid address */ 4045d48df9SBarry Smith 4145d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */ 4245d48df9SBarry Smith #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */ 43a8c6a408SBarry Smith #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */ 4445d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */ 4545d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */ 464f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */ 474f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */ 486831982aSBarry Smith #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */ 49d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */ 508cda6cd7SBarry Smith #define PETSC_ERR_ARG_TYPENOTSET 89 /* the type of the object has not yet been set */ 51a8c6a408SBarry Smith #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ 524482741eSBarry Smith #define PETSC_ERR_ARG_NULL 85 /* argument is null that should not be */ 53958c9bccSBarry Smith #define PETSC_ERR_ARG_UNKNOWN_TYPE 86 /* type name doesn't match any registered type */ 544f227f7cSBarry Smith 554f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ 564f227f7cSBarry Smith #define PETSC_ERR_FILE_READ 66 /* unable to read from file */ 574f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */ 58a8c6a408SBarry Smith #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */ 5945d48df9SBarry Smith 60329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */ 619e3b2f23SBarry Smith #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */ 6254a8ef01SBarry Smith 6368e69593SBarry Smith #define PETSC_ERR_INT_OVERFLOW 84 643855c12bSBarry Smith 65bf3909cdSBarry Smith #define PETSC_ERR_FLOP_COUNT 90 66e113a28aSBarry Smith #define PETSC_ERR_NOT_CONVERGED 91 /* solver did not converge */ 6792e8f287SBarry Smith #define PETSC_ERR_MISSING_FACTOR 92 /* MatGetFactor() failed */ 6892e8f287SBarry Smith #define PETSC_ERR_MAX_VALUE 93 /* this is always the one more than the largest error code */ 692a6744ebSBarry Smith 7059aaf355SLisandro Dalcin #define PetscStringizeArg(a) #a 7159aaf355SLisandro Dalcin #define PetscStringize(a) PetscStringizeArg(a) 72330cf3c9SBarry Smith 73e8b7e333SSatish Balay #if defined(PETSC_USE_ERRORCHECKING) 74e8b7e333SSatish Balay 7530de9b25SBarry Smith /*MC 761957e957SBarry Smith SETERRQ - Macro to be called when an error has been detected, 7730de9b25SBarry Smith 7830de9b25SBarry Smith Synopsis: 79aaa7dc30SBarry Smith #include <petscsys.h> 80e7e72b3dSBarry Smith PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode errorcode,char *message) 8130de9b25SBarry Smith 82eca87e8dSBarry Smith Not Collective 8330de9b25SBarry Smith 8430de9b25SBarry Smith Input Parameters: 8530de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 8630de9b25SBarry Smith - message - error message 8730de9b25SBarry Smith 8830de9b25SBarry Smith Level: beginner 8930de9b25SBarry Smith 9030de9b25SBarry Smith Notes: 9130de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 9230de9b25SBarry Smith 9330de9b25SBarry Smith See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments 9430de9b25SBarry Smith 9558ebbce7SBarry Smith In Fortran MPI_Abort() is always called 9630de9b25SBarry Smith 9730de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 9830de9b25SBarry Smith 9930de9b25SBarry Smith Concepts: error^setting condition 10030de9b25SBarry Smith 10191d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3() 10230de9b25SBarry Smith M*/ 103efca3c55SSatish Balay #define SETERRQ(comm,n,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s) 10430de9b25SBarry Smith 10530de9b25SBarry Smith /*MC 10630de9b25SBarry Smith SETERRQ1 - Macro that is called when an error has been detected, 10730de9b25SBarry Smith 10830de9b25SBarry Smith Synopsis: 109aaa7dc30SBarry Smith #include <petscsys.h> 110e32f2f54SBarry Smith PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg) 11130de9b25SBarry Smith 112eca87e8dSBarry Smith Not Collective 11330de9b25SBarry Smith 11430de9b25SBarry Smith Input Parameters: 11530de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 11630de9b25SBarry Smith . message - error message in the printf format 11730de9b25SBarry Smith - arg - argument (for example an integer, string or double) 11830de9b25SBarry Smith 11930de9b25SBarry Smith Level: beginner 12030de9b25SBarry Smith 12130de9b25SBarry Smith Notes: 12230de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 12330de9b25SBarry Smith 12430de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 12530de9b25SBarry Smith 12630de9b25SBarry Smith Concepts: error^setting condition 12730de9b25SBarry Smith 12891d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3() 12930de9b25SBarry Smith M*/ 130efca3c55SSatish Balay #define SETERRQ1(comm,n,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1) 13130de9b25SBarry Smith 13230de9b25SBarry Smith /*MC 13330de9b25SBarry Smith SETERRQ2 - Macro that is called when an error has been detected, 13430de9b25SBarry Smith 13530de9b25SBarry Smith Synopsis: 136aaa7dc30SBarry Smith #include <petscsys.h> 137f4442326SMatthew Knepley PetscErrorCode SETERRQ2(PetscErrorCode errorcode,char *formatmessage,arg1,arg2) 13830de9b25SBarry Smith 139eca87e8dSBarry Smith Not Collective 14030de9b25SBarry Smith 14130de9b25SBarry Smith Input Parameters: 14230de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 14330de9b25SBarry Smith . message - error message in the printf format 14430de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 14530de9b25SBarry Smith - arg2 - argument (for example an integer, string or double) 14630de9b25SBarry Smith 14730de9b25SBarry Smith Level: beginner 14830de9b25SBarry Smith 14930de9b25SBarry Smith Notes: 15030de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 15130de9b25SBarry Smith 15230de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 15330de9b25SBarry Smith 15430de9b25SBarry Smith Concepts: error^setting condition 15530de9b25SBarry Smith 1566024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3() 15730de9b25SBarry Smith M*/ 158efca3c55SSatish Balay #define SETERRQ2(comm,n,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2) 15930de9b25SBarry Smith 16030de9b25SBarry Smith /*MC 16130de9b25SBarry Smith SETERRQ3 - Macro that is called when an error has been detected, 16230de9b25SBarry Smith 16330de9b25SBarry Smith Synopsis: 164aaa7dc30SBarry Smith #include <petscsys.h> 165f4442326SMatthew Knepley PetscErrorCode SETERRQ3(PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 16630de9b25SBarry Smith 167eca87e8dSBarry Smith Not Collective 16830de9b25SBarry Smith 16930de9b25SBarry Smith Input Parameters: 17030de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 17130de9b25SBarry Smith . message - error message in the printf format 17230de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 17330de9b25SBarry Smith . arg2 - argument (for example an integer, string or double) 17430de9b25SBarry Smith - arg3 - argument (for example an integer, string or double) 17530de9b25SBarry Smith 17630de9b25SBarry Smith Level: beginner 17730de9b25SBarry Smith 17830de9b25SBarry Smith Notes: 17930de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 18030de9b25SBarry Smith 181f621e05eSBarry Smith There are also versions for 4, 5, 6 and 7 arguments. 182f621e05eSBarry Smith 18330de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 18430de9b25SBarry Smith 18530de9b25SBarry Smith Concepts: error^setting condition 18630de9b25SBarry Smith 1876024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 18830de9b25SBarry Smith M*/ 189efca3c55SSatish Balay #define SETERRQ3(comm,n,s,a1,a2,a3) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3) 19030de9b25SBarry Smith 191efca3c55SSatish Balay #define SETERRQ4(comm,n,s,a1,a2,a3,a4) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4) 192efca3c55SSatish Balay #define SETERRQ5(comm,n,s,a1,a2,a3,a4,a5) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5) 193efca3c55SSatish Balay #define SETERRQ6(comm,n,s,a1,a2,a3,a4,a5,a6) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6) 194efca3c55SSatish Balay #define SETERRQ7(comm,n,s,a1,a2,a3,a4,a5,a6,a7) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7) 195efca3c55SSatish Balay #define SETERRQ8(comm,n,s,a1,a2,a3,a4,a5,a6,a7,a8) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7,a8) 196efca3c55SSatish Balay #define SETERRABORT(comm,n,s) do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,n);} while (0) 1979a00fa46SSatish Balay 19830de9b25SBarry Smith /*MC 19930de9b25SBarry Smith CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns 20030de9b25SBarry Smith 20130de9b25SBarry Smith Synopsis: 202aaa7dc30SBarry Smith #include <petscsys.h> 203f4442326SMatthew Knepley PetscErrorCode CHKERRQ(PetscErrorCode errorcode) 20430de9b25SBarry Smith 205eca87e8dSBarry Smith Not Collective 20630de9b25SBarry Smith 20730de9b25SBarry Smith Input Parameters: 20830de9b25SBarry Smith . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 20930de9b25SBarry Smith 21030de9b25SBarry Smith Level: beginner 21130de9b25SBarry Smith 21230de9b25SBarry Smith Notes: 21330de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 21430de9b25SBarry Smith 21530de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 2165324ea47SKris Buschelman 217fcecf507SKris Buschelman CHKERRQ(n) is fundamentally a macro replacement for 2185324ea47SKris Buschelman if (n) return(PetscError(...,n,...)); 2195324ea47SKris Buschelman 2205324ea47SKris Buschelman Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is 2215324ea47SKris Buschelman highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular, 2225324ea47SKris Buschelman it cannot be used in functions which return(void) or any other datatype. In these types of functions, 22358ebbce7SBarry Smith you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or 2245324ea47SKris Buschelman if (n) {PetscError(....); return(YourReturnType);} 2250298fd71SBarry Smith where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have 22658ebbce7SBarry Smith MPI_Abort() returned immediately. 22758ebbce7SBarry Smith 22858ebbce7SBarry Smith In Fortran MPI_Abort() is always called 22930de9b25SBarry Smith 23030de9b25SBarry Smith Concepts: error^setting condition 23130de9b25SBarry Smith 23291d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2() 23330de9b25SBarry Smith M*/ 234efca3c55SSatish Balay #define CHKERRQ(n) do {if (PetscUnlikely(n)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_REPEAT," ");} while (0) 23530de9b25SBarry Smith 236efca3c55SSatish Balay #define CHKERRV(n) do {if (PetscUnlikely(n)) {n = PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_REPEAT," ");return;}} while(0) 237efca3c55SSatish Balay #define CHKERRABORT(comm,n) do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_REPEAT," ");MPI_Abort(comm,n);}} while (0) 238efca3c55SSatish Balay #define CHKERRCONTINUE(n) do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_REPEAT," ");}} while (0) 23985614651SBarry Smith 240fd705b32SMatthew Knepley #ifdef PETSC_CLANGUAGE_CXX 241fd705b32SMatthew Knepley 242cc26af49SMatthew Knepley /*MC 243cc26af49SMatthew Knepley CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception 244cc26af49SMatthew Knepley 245cc26af49SMatthew Knepley Synopsis: 246aaa7dc30SBarry Smith #include <petscsys.h> 247cc26af49SMatthew Knepley void CHKERRXX(PetscErrorCode errorcode) 248cc26af49SMatthew Knepley 249eca87e8dSBarry Smith Not Collective 250cc26af49SMatthew Knepley 251cc26af49SMatthew Knepley Input Parameters: 252cc26af49SMatthew Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 253cc26af49SMatthew Knepley 254cc26af49SMatthew Knepley Level: beginner 255cc26af49SMatthew Knepley 256cc26af49SMatthew Knepley Notes: 257cc26af49SMatthew Knepley Once the error handler throws a ??? exception. 258cc26af49SMatthew Knepley 259cc26af49SMatthew Knepley You can use CHKERRV() which returns without an error code (bad idea since the error is ignored) 260cc26af49SMatthew Knepley or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately. 261cc26af49SMatthew Knepley 262cc26af49SMatthew Knepley Concepts: error^setting condition 263cc26af49SMatthew Knepley 264cc26af49SMatthew Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ 265cc26af49SMatthew Knepley M*/ 266efca3c55SSatish Balay #define CHKERRXX(n) do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_IN_CXX,0);}} while(0) 267fd705b32SMatthew Knepley 268fd705b32SMatthew Knepley #endif 269fd705b32SMatthew Knepley 27030de9b25SBarry Smith /*MC 27130de9b25SBarry Smith CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected 27230de9b25SBarry Smith 27330de9b25SBarry Smith Synopsis: 274aaa7dc30SBarry Smith #include <petscsys.h> 27591d3bdf4SKris Buschelman CHKMEMQ; 27630de9b25SBarry Smith 277eca87e8dSBarry Smith Not Collective 278eca87e8dSBarry Smith 27930de9b25SBarry Smith Level: beginner 28030de9b25SBarry Smith 28130de9b25SBarry Smith Notes: 2821957e957SBarry Smith We highly recommend using valgrind http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful 2831957e957SBarry Smith on systems that do not have valgrind, but much much less useful. 2841957e957SBarry Smith 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*/ 298efca3c55SSatish Balay #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while(0) 29985614651SBarry Smith 300efca3c55SSatish Balay #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__) 301e68848bdSBarry Smith 302f8e50935SSatish Balay #else /* PETSC_USE_ERRORCHECKING */ 303f621e05eSBarry Smith 304f621e05eSBarry Smith /* 305e2e64c6bSBarry Smith These are defined to be empty for when error checking is turned off, with ./configure --with-errorchecking=0 306f621e05eSBarry Smith */ 307f621e05eSBarry Smith 3084b209cf6SBarry Smith #define SETERRQ(c,n,s) 3094b209cf6SBarry Smith #define SETERRQ1(c,n,s,a1) 3104b209cf6SBarry Smith #define SETERRQ2(c,n,s,a1,a2) 3114b209cf6SBarry Smith #define SETERRQ3(c,n,s,a1,a2,a3) 3124b209cf6SBarry Smith #define SETERRQ4(c,n,s,a1,a2,a3,a4) 3134b209cf6SBarry Smith #define SETERRQ5(c,n,s,a1,a2,a3,a4,a5) 3144b209cf6SBarry Smith #define SETERRQ6(c,n,s,a1,a2,a3,a4,a5,a6) 3154ef524e9SStefano Zampini #define SETERRQ7(c,n,s,a1,a2,a3,a4,a5,a6,a7) 3164ef524e9SStefano Zampini #define SETERRQ8(c,n,s,a1,a2,a3,a4,a5,a6,a7,a8) 3174b209cf6SBarry Smith #define SETERRABORT(comm,n,s) 31885614651SBarry Smith 3194f227f7cSBarry Smith #define CHKERRQ(n) ; 3201ee4faa0SMatthew Knepley #define CHKERRABORT(comm,n) ; 3211ee4faa0SMatthew Knepley #define CHKERRCONTINUE(n) ; 32285614651SBarry Smith #define CHKMEMQ ; 32385614651SBarry Smith 3248cabf42eSMatthew G Knepley #ifdef PETSC_CLANGUAGE_CXX 3258cabf42eSMatthew G Knepley #define CHKERRXX(n) ; 3268cabf42eSMatthew G Knepley #endif 3278cabf42eSMatthew G Knepley 328f8e50935SSatish Balay #endif /* PETSC_USE_ERRORCHECKING */ 32954a8ef01SBarry Smith 330668f157eSBarry Smith /*E 331668f157eSBarry Smith PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers 332668f157eSBarry Smith 333668f157eSBarry Smith Level: advanced 334668f157eSBarry Smith 335d736bfebSBarry Smith PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated 336d736bfebSBarry Smith 33761b0d812SBarry Smith Developer Notes: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler() 338668f157eSBarry Smith 339d736bfebSBarry Smith .seealso: PetscError(), SETERRXX() 340668f157eSBarry Smith E*/ 341d736bfebSBarry Smith typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType; 3424b209cf6SBarry Smith 343eb9e708aSLisandro Dalcin #if defined(__clang_analyzer__) 344eb9e708aSLisandro Dalcin __attribute__((analyzer_noreturn)) 345eb9e708aSLisandro Dalcin #endif 346eb9e708aSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...); 347eb9e708aSLisandro Dalcin 348014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void); 349014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **); 350efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 351efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 352efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 353efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 354efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 355efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 356efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 357efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*); 358014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void); 3598d359177SBarry Smith PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*); 360014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*); 361014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void); 36228559dc8SJed Brown PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt); 363329f5518SBarry Smith 364639ff905SBarry Smith /*MC 365639ff905SBarry Smith PetscErrorPrintf - Prints error messages. 366639ff905SBarry Smith 367639ff905SBarry Smith Synopsis: 368aaa7dc30SBarry Smith #include <petscsys.h> 369639ff905SBarry Smith PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 370639ff905SBarry Smith 371639ff905SBarry Smith Not Collective 372639ff905SBarry Smith 373639ff905SBarry Smith Input Parameters: 374639ff905SBarry Smith . format - the usual printf() format string 375639ff905SBarry Smith 376639ff905SBarry Smith Options Database Keys: 3771957e957SBarry Smith + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr 378e1bc860dSBarry Smith - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.) 379639ff905SBarry Smith 380639ff905SBarry Smith Notes: Use 381639ff905SBarry Smith $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 382639ff905SBarry Smith $ error is handled.) and 3831957e957SBarry Smith $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function 384639ff905SBarry Smith 385639ff905SBarry Smith Use 386639ff905SBarry Smith PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file. 387639ff905SBarry Smith PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file. 388639ff905SBarry Smith 389639ff905SBarry Smith Use 390639ff905SBarry Smith PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print 391639ff905SBarry Smith 392639ff905SBarry Smith Level: developer 393639ff905SBarry Smith 394639ff905SBarry Smith Fortran Note: 395639ff905SBarry Smith This routine is not supported in Fortran. 396639ff905SBarry Smith 397639ff905SBarry Smith Concepts: error messages^printing 398639ff905SBarry Smith Concepts: printing^error messages 399639ff905SBarry Smith 400639ff905SBarry Smith .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush(), PetscVFPrintf(), PetscHelpPrintf() 401639ff905SBarry Smith M*/ 402639ff905SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...); 403639ff905SBarry Smith 404329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 405014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap); 406014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap); 407014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void); 40854a8ef01SBarry Smith 4093a40ed3dSBarry Smith /* 4103a40ed3dSBarry Smith Allows the code to build a stack frame as it runs 4113a40ed3dSBarry Smith */ 4123a40ed3dSBarry Smith 41399cd645aSJed Brown #define PETSCSTACKSIZE 64 414184914b5SBarry Smith 4153a40ed3dSBarry Smith typedef struct { 4160e33f6ddSBarry Smith const char *function[PETSCSTACKSIZE]; 4170e33f6ddSBarry Smith const char *file[PETSCSTACKSIZE]; 418184914b5SBarry Smith int line[PETSCSTACKSIZE]; 419a8d2bbe5SBarry Smith PetscBool petscroutine[PETSCSTACKSIZE]; 420184914b5SBarry Smith int currentsize; 421a2f94806SJed Brown int hotdepth; 4223a40ed3dSBarry Smith } PetscStack; 4233a40ed3dSBarry Smith 4241f46d60fSShri Abhyankar PETSC_EXTERN PetscStack *petscstack; 425184914b5SBarry Smith 4262d7c6352SJed Brown #if defined(PETSC_USE_DEBUG) 427dbf62e16SBarry Smith PETSC_STATIC_INLINE PetscBool PetscStackActive(void) 428dbf62e16SBarry Smith { 429*5c25fcd7SBarry Smith return(petscstack ? PETSC_TRUE : PETSC_FALSE); 430dbf62e16SBarry Smith } 4313a40ed3dSBarry Smith 432441dd030SJed Brown /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error 433441dd030SJed Brown * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at 434441dd030SJed Brown * least more useful than "unknown" because it can distinguish multiple calls from the same function. 435441dd030SJed Brown */ 436441dd030SJed Brown 437a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) \ 438441dd030SJed Brown do { \ 439e04113cfSBarry Smith PetscStackSAWsTakeAccess(); \ 440*5c25fcd7SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 441*5c25fcd7SBarry Smith petscstack->function[petscstack->currentsize] = funct; \ 442*5c25fcd7SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 443*5c25fcd7SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 444*5c25fcd7SBarry Smith petscstack->petscroutine[petscstack->currentsize] = petsc_routine; \ 445*5c25fcd7SBarry Smith petscstack->currentsize++; \ 446441dd030SJed Brown } \ 447*5c25fcd7SBarry Smith if (petscstack) { \ 448*5c25fcd7SBarry Smith petscstack->hotdepth += (hot || petscstack->hotdepth); \ 449a2f94806SJed Brown } \ 450e04113cfSBarry Smith PetscStackSAWsGrantAccess(); \ 451441dd030SJed Brown } while (0) 452441dd030SJed Brown 453441dd030SJed Brown #define PetscStackPopNoCheck \ 454*5c25fcd7SBarry Smith do { \ 455e04113cfSBarry Smith PetscStackSAWsTakeAccess(); \ 456*5c25fcd7SBarry Smith if (petscstack && petscstack->currentsize > 0) { \ 457*5c25fcd7SBarry Smith petscstack->currentsize--; \ 458*5c25fcd7SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 459*5c25fcd7SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 460*5c25fcd7SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 461*5c25fcd7SBarry Smith petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\ 462441dd030SJed Brown } \ 463*5c25fcd7SBarry Smith if (petscstack) { \ 464*5c25fcd7SBarry Smith petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0); \ 465a2f94806SJed Brown } \ 466e04113cfSBarry Smith PetscStackSAWsGrantAccess(); \ 467441dd030SJed Brown } while (0) 468441dd030SJed Brown 46930de9b25SBarry Smith /*MC 4701957e957SBarry Smith PetscFunctionBegin - First executable line of each PETSc function, used for error handling. Final 4711957e957SBarry Smith line of PETSc functions should be PetscFunctionReturn(0); 47230de9b25SBarry Smith 47330de9b25SBarry Smith Synopsis: 474aaa7dc30SBarry Smith #include <petscsys.h> 47530de9b25SBarry Smith void PetscFunctionBegin; 47630de9b25SBarry Smith 477eca87e8dSBarry Smith Not Collective 478eca87e8dSBarry Smith 47930de9b25SBarry Smith Usage: 48030de9b25SBarry Smith .vb 48130de9b25SBarry Smith int something; 48230de9b25SBarry Smith 48330de9b25SBarry Smith PetscFunctionBegin; 48430de9b25SBarry Smith .ve 48530de9b25SBarry Smith 48630de9b25SBarry Smith Notes: 4871957e957SBarry Smith Use PetscFunctionBeginUser for application codes. 4881957e957SBarry Smith 48930de9b25SBarry Smith Not available in Fortran 49030de9b25SBarry Smith 49130de9b25SBarry Smith Level: developer 49230de9b25SBarry Smith 4931957e957SBarry Smith .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser() 49430de9b25SBarry Smith 49530de9b25SBarry Smith .keywords: traceback, error handling 49630de9b25SBarry Smith M*/ 497441dd030SJed Brown #define PetscFunctionBegin do { \ 498a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \ 499a2f94806SJed Brown PetscCheck__FUNCT__(); \ 500a2f94806SJed Brown PetscRegister__FUNCT__(); \ 501a2f94806SJed Brown } while (0) 502a2f94806SJed Brown 503a2f94806SJed Brown /*MC 504a2f94806SJed Brown PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in 505a2f94806SJed Brown performance-critical circumstances. Use of this function allows for lighter profiling by default. 506a2f94806SJed Brown 507a2f94806SJed Brown Synopsis: 508aaa7dc30SBarry Smith #include <petscsys.h> 509a2f94806SJed Brown void PetscFunctionBeginHot; 510a2f94806SJed Brown 511a2f94806SJed Brown Not Collective 512a2f94806SJed Brown 513a2f94806SJed Brown Usage: 514a2f94806SJed Brown .vb 515a2f94806SJed Brown int something; 516a2f94806SJed Brown 517a2f94806SJed Brown PetscFunctionBeginHot; 518a2f94806SJed Brown .ve 519a2f94806SJed Brown 520a2f94806SJed Brown Notes: 521a2f94806SJed Brown Not available in Fortran 522a2f94806SJed Brown 523a2f94806SJed Brown Level: developer 524a2f94806SJed Brown 525a2f94806SJed Brown .seealso: PetscFunctionBegin, PetscFunctionReturn() 526a2f94806SJed Brown 527a2f94806SJed Brown .keywords: traceback, error handling 528a2f94806SJed Brown M*/ 529a2f94806SJed Brown #define PetscFunctionBeginHot do { \ 530a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE); \ 53153c77d0aSJed Brown PetscCheck__FUNCT__(); \ 5322d53ad75SBarry Smith PetscRegister__FUNCT__(); \ 53353c77d0aSJed Brown } while (0) 53453c77d0aSJed Brown 535a8d2bbe5SBarry Smith /*MC 536a8d2bbe5SBarry Smith PetscFunctionBeginUser - First executable line of user provided PETSc routine 537a8d2bbe5SBarry Smith 538a8d2bbe5SBarry Smith Synopsis: 539aaa7dc30SBarry Smith #include <petscsys.h> 540a8d2bbe5SBarry Smith void PetscFunctionBeginUser; 541a8d2bbe5SBarry Smith 542a8d2bbe5SBarry Smith Not Collective 543a8d2bbe5SBarry Smith 544a8d2bbe5SBarry Smith Usage: 545a8d2bbe5SBarry Smith .vb 546a8d2bbe5SBarry Smith int something; 547a8d2bbe5SBarry Smith 548a8d2bbe5SBarry Smith PetscFunctionBegin; 549a8d2bbe5SBarry Smith .ve 550a8d2bbe5SBarry Smith 551a8d2bbe5SBarry Smith Notes: 5521957e957SBarry Smith Final line of PETSc functions should be PetscFunctionReturn(0) except for main(). 5531957e957SBarry Smith 554a8d2bbe5SBarry Smith Not available in Fortran 555a8d2bbe5SBarry Smith 556a2f94806SJed Brown Level: intermediate 557a8d2bbe5SBarry Smith 558a2f94806SJed Brown .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot 559a8d2bbe5SBarry Smith 560a8d2bbe5SBarry Smith .keywords: traceback, error handling 561a8d2bbe5SBarry Smith M*/ 562a8d2bbe5SBarry Smith #define PetscFunctionBeginUser \ 563a8d2bbe5SBarry Smith do { \ 564a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \ 565a8d2bbe5SBarry Smith PetscCheck__FUNCT__(); \ 566a8d2bbe5SBarry Smith PetscRegister__FUNCT__(); \ 567a8d2bbe5SBarry Smith } while (0) 568a8d2bbe5SBarry Smith 569a8d2bbe5SBarry Smith 5702d53ad75SBarry Smith #if defined(PETSC_SERIALIZE_FUNCTIONS) 571af0996ceSBarry Smith #include <petsc/private/petscfptimpl.h> 5722d53ad75SBarry Smith /* 5732d53ad75SBarry Smith Registers the current function into the global function pointer to function name table 5742d53ad75SBarry Smith 5752d53ad75SBarry Smith Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc 5762d53ad75SBarry Smith */ 5772d53ad75SBarry Smith #define PetscRegister__FUNCT__() do { \ 5782d53ad75SBarry Smith static PetscBool __chked = PETSC_FALSE; \ 5792d53ad75SBarry Smith if (!__chked) {\ 5800298fd71SBarry Smith void *ptr; PetscDLSym(NULL,__FUNCT__,&ptr);\ 5812d53ad75SBarry Smith __chked = PETSC_TRUE;\ 5822d53ad75SBarry Smith }} while (0) 5832d53ad75SBarry Smith #else 5842d53ad75SBarry Smith #define PetscRegister__FUNCT__() 5852d53ad75SBarry Smith #endif 5862d53ad75SBarry Smith 587573b0fb4SBarry Smith #define PetscCheck__FUNCT__() do { PetscBool _sc1,_sc2; \ 588573b0fb4SBarry Smith PetscStrcmpNoError(PETSC_FUNCTION_NAME,__FUNCT__,&_sc1);\ 589573b0fb4SBarry Smith PetscStrcmpNoError(__FUNCT__,"User provided function",&_sc2);\ 590573b0fb4SBarry Smith if (!_sc1 && !_sc2) { \ 591e9f0693fSJed Brown printf("%s:%d: __FUNCT__=\"%s\" does not agree with %s=\"%s\"\n",__FILE__,__LINE__,__FUNCT__,PetscStringize(PETSC_FUNCTION_NAME),PETSC_FUNCTION_NAME); \ 59253c77d0aSJed Brown } \ 59353c77d0aSJed Brown } while (0) 5943a40ed3dSBarry Smith 5955cd90555SBarry Smith #define PetscStackPush(n) \ 59661d886c9SShri Abhyankar do { \ 597a2f94806SJed Brown PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE); \ 59815681b3cSBarry Smith CHKMEMQ; \ 59915681b3cSBarry Smith } while (0) 6003a40ed3dSBarry Smith 601d64ed03dSBarry Smith #define PetscStackPop \ 602441dd030SJed Brown do { \ 603441dd030SJed Brown CHKMEMQ; \ 604441dd030SJed Brown PetscStackPopNoCheck; \ 60515681b3cSBarry Smith } while (0) 606d64ed03dSBarry Smith 60730de9b25SBarry Smith /*MC 60830de9b25SBarry Smith PetscFunctionReturn - Last executable line of each PETSc function 60930de9b25SBarry Smith used for error handling. Replaces return() 61030de9b25SBarry Smith 61130de9b25SBarry Smith Synopsis: 612aaa7dc30SBarry Smith #include <petscsys.h> 61330de9b25SBarry Smith void PetscFunctionReturn(0); 61430de9b25SBarry Smith 615eca87e8dSBarry Smith Not Collective 616eca87e8dSBarry Smith 61730de9b25SBarry Smith Usage: 61830de9b25SBarry Smith .vb 61930de9b25SBarry Smith .... 62030de9b25SBarry Smith PetscFunctionReturn(0); 62130de9b25SBarry Smith } 62230de9b25SBarry Smith .ve 62330de9b25SBarry Smith 62430de9b25SBarry Smith Notes: 62530de9b25SBarry Smith Not available in Fortran 62630de9b25SBarry Smith 62730de9b25SBarry Smith Level: developer 62830de9b25SBarry Smith 62930de9b25SBarry Smith .seealso: PetscFunctionBegin() 63030de9b25SBarry Smith 63130de9b25SBarry Smith .keywords: traceback, error handling 63230de9b25SBarry Smith M*/ 6335cd90555SBarry Smith #define PetscFunctionReturn(a) \ 6348246ba0dSJed Brown do { \ 635441dd030SJed Brown PetscStackPopNoCheck; \ 6368246ba0dSJed Brown return(a);} while (0) 637d64ed03dSBarry Smith 638ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 6398246ba0dSJed Brown do { \ 640441dd030SJed Brown PetscStackPopNoCheck; \ 6418246ba0dSJed Brown return;} while (0) 64276386721SLisandro Dalcin 6436d385327SIbrahima Ba #else 6446d385327SIbrahima Ba 645c82b4e47SJed Brown PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;} 646a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0) 647441dd030SJed Brown #define PetscStackPopNoCheck do {} while (0) 6483a40ed3dSBarry Smith #define PetscFunctionBegin 6490bdf7c52SPeter Brune #define PetscFunctionBeginUser 650a2f94806SJed Brown #define PetscFunctionBeginHot 6513a40ed3dSBarry Smith #define PetscFunctionReturn(a) return(a) 6525665465eSBarry Smith #define PetscFunctionReturnVoid() return 653812af9f3SBarry Smith #define PetscStackPop CHKMEMQ 654812af9f3SBarry Smith #define PetscStackPush(f) CHKMEMQ 6553a40ed3dSBarry Smith 6563a40ed3dSBarry Smith #endif 6573a40ed3dSBarry Smith 658eb6b5d47SBarry Smith /* 659eb6b5d47SBarry Smith PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack. 660eb6b5d47SBarry Smith 661eb6b5d47SBarry Smith Input Parameters: 662eb6b5d47SBarry Smith + name - string that gives the name of the function being called 663fd3f9acdSBarry Smith - routine - actual call to the routine, including ierr = and CHKERRQ(ierr); 664fd3f9acdSBarry Smith 665dbf62e16SBarry Smith Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes 666eb6b5d47SBarry Smith 667eb6b5d47SBarry 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. 668eb6b5d47SBarry Smith 669fd3f9acdSBarry Smith 670fd3f9acdSBarry Smith 671eb6b5d47SBarry Smith */ 67230ecc5abSKarl Rupp #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while(0) 673eb6b5d47SBarry Smith 674fd3f9acdSBarry Smith /* 675fd3f9acdSBarry Smith PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack. 676fd3f9acdSBarry Smith 677fd3f9acdSBarry Smith Input Parameters: 678fd3f9acdSBarry Smith + func- name of the routine 679fd3f9acdSBarry Smith - args - arguments to the routine surrounded by () 680fd3f9acdSBarry Smith 681dbf62e16SBarry Smith Notes: This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not. 682dbf62e16SBarry Smith 683dbf62e16SBarry 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. 684fd3f9acdSBarry Smith 685fd3f9acdSBarry Smith */ 686fd3f9acdSBarry Smith #define PetscStackCallStandard(func,args) do { \ 687fd3f9acdSBarry Smith PetscStackPush(#func);ierr = func args;PetscStackPop; if (ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s()",#func); \ 688fd3f9acdSBarry Smith } while (0) 689fd3f9acdSBarry Smith 690014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackCreate(void); 691639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscStackView(FILE*); 692014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackDestroy(void); 69306d1fe2cSBarry Smith 69406d1fe2cSBarry Smith #endif 695