173f4d377SMatthew Knepley /* $Id: petscerror.h,v 1.59 2001/09/07 20:13:16 bsmith Exp $ */ 254a8ef01SBarry Smith /* 34f227f7cSBarry Smith Contains all error handling code for PETSc. 454a8ef01SBarry Smith */ 545d48df9SBarry Smith #if !defined(__PETSCERROR_H) 645d48df9SBarry Smith #define __PETSCERROR_H 754a8ef01SBarry Smith 8c22c1629SBarry Smith #include "petsc.h" 9c22c1629SBarry Smith 10aa482453SBarry Smith #if defined(PETSC_HAVE_AMS) 116d385327SIbrahima Ba #include "ams.h" 126d385327SIbrahima Ba #endif 136d385327SIbrahima Ba 1454a8ef01SBarry Smith /* 1554a8ef01SBarry Smith Defines the directory where the compiled source is located; used 165e97870eSBarry Smith in printing error messages. Each makefile has an entry 175e97870eSBarry Smith LOCDIR = thedirectory 180cd5afcaSLois Curfman McInnes and bmake/common_variables includes in CCPPFLAGS -D__SDIR__='"${LOCDIR}"' 195e97870eSBarry Smith which is a flag passed to the C/C++ compilers. 2054a8ef01SBarry Smith */ 21c22c1629SBarry Smith #if !defined(__SDIR__) 222ee1dbe0SBarry Smith #define __SDIR__ "unknowndirectory/" 2354a8ef01SBarry Smith #endif 2454a8ef01SBarry Smith 2554a8ef01SBarry Smith /* 264f227f7cSBarry Smith Defines the function where the compiled source is located; used 274f227f7cSBarry Smith in printing error messages. 284f227f7cSBarry Smith */ 294a2ae208SSatish Balay #if !defined(__FUNCT__) 30da9b6338SBarry Smith #define __FUNCT__ "User provided function" 314f227f7cSBarry Smith #endif 324f227f7cSBarry Smith 334f227f7cSBarry Smith /* 34329ffe3dSLois Curfman McInnes These are the generic error codes. These error codes are used 35329ffe3dSLois Curfman McInnes many different places in the PETSc source code. 3645d48df9SBarry Smith 3754a8ef01SBarry Smith */ 3845d48df9SBarry Smith #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 39106f7b34SBarry Smith #define PETSC_ERR_MEM_MALLOC_0 85 /* cannot malloc zero size */ 4047794344SBarry Smith #define PETSC_ERR_SUP 56 /* no support for requested operation */ 4145d48df9SBarry Smith #define PETSC_ERR_SIG 59 /* signal received */ 42f1caa5a4SBarry Smith #define PETSC_ERR_FP 72 /* floating point exception */ 43a8c6a408SBarry Smith #define PETSC_ERR_COR 74 /* corrupted PETSc object */ 44a8c6a408SBarry Smith #define PETSC_ERR_LIB 76 /* error in library called by PETSc */ 45329ffe3dSLois Curfman McInnes #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */ 46329ffe3dSLois Curfman McInnes #define PETSC_ERR_MEMC 78 /* memory corruption */ 474ebda54eSMatthew Knepley #define PETSC_ERR_MAX_ITER 82 /* Maximum iterations reached */ 4845d48df9SBarry Smith 4945d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */ 5045d48df9SBarry Smith #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */ 51a8c6a408SBarry Smith #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */ 5245d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */ 5345d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */ 544f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */ 554f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */ 566831982aSBarry Smith #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */ 57d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */ 58a8c6a408SBarry Smith #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ 594f227f7cSBarry Smith 604f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ 614f227f7cSBarry Smith #define PETSC_ERR_FILE_READ 66 /* unable to read from file */ 624f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */ 63a8c6a408SBarry Smith #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */ 6445d48df9SBarry Smith 65329ffe3dSLois Curfman McInnes #define PETSC_ERR_KSP_BRKDWN 70 /* break down in a Krylov method */ 664f227f7cSBarry Smith 67329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */ 689e3b2f23SBarry Smith #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */ 6954a8ef01SBarry Smith 704ebda54eSMatthew Knepley #define PETSC_ERR_MESH_NULL_ELEM 84 /* Element had no interior */ 714ebda54eSMatthew Knepley 724ebda54eSMatthew Knepley #define PETSC_ERR_DISC_SING_JAC 83 /* Singular element Jacobian */ 734ebda54eSMatthew Knepley 74aa482453SBarry Smith #if defined(PETSC_USE_DEBUG) 75*30de9b25SBarry Smith 76*30de9b25SBarry Smith /*MC 77*30de9b25SBarry Smith SETERRQ - Macro that is called when an error has been detected, 78*30de9b25SBarry Smith 79*30de9b25SBarry Smith Not Collective 80*30de9b25SBarry Smith 81*30de9b25SBarry Smith Synopsis: 82*30de9b25SBarry Smith void SETERRQ(int errorcode,char *message) 83*30de9b25SBarry Smith 84*30de9b25SBarry Smith 85*30de9b25SBarry Smith Input Parameters: 86*30de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 87*30de9b25SBarry Smith - message - error message 88*30de9b25SBarry Smith 89*30de9b25SBarry Smith Level: beginner 90*30de9b25SBarry Smith 91*30de9b25SBarry Smith Notes: 92*30de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 93*30de9b25SBarry Smith 94*30de9b25SBarry Smith See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments 95*30de9b25SBarry Smith 96*30de9b25SBarry Smith 97*30de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 98*30de9b25SBarry Smith 99*30de9b25SBarry Smith Concepts: error^setting condition 100*30de9b25SBarry Smith 101*30de9b25SBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ(), SETERRQ1(), SETERRQ2(), SETERRQ3() 102*30de9b25SBarry Smith M*/ 1034a2ae208SSatish Balay #define SETERRQ(n,s) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);} 104*30de9b25SBarry Smith 105*30de9b25SBarry Smith /*MC 106*30de9b25SBarry Smith SETERRQ1 - Macro that is called when an error has been detected, 107*30de9b25SBarry Smith 108*30de9b25SBarry Smith Not Collective 109*30de9b25SBarry Smith 110*30de9b25SBarry Smith Synopsis: 111*30de9b25SBarry Smith void SETERRQ1(int errorcode,char *formatmessage,arg) 112*30de9b25SBarry Smith 113*30de9b25SBarry Smith 114*30de9b25SBarry Smith Input Parameters: 115*30de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 116*30de9b25SBarry Smith . message - error message in the printf format 117*30de9b25SBarry Smith - arg - argument (for example an integer, string or double) 118*30de9b25SBarry Smith 119*30de9b25SBarry Smith Level: beginner 120*30de9b25SBarry Smith 121*30de9b25SBarry Smith Notes: 122*30de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 123*30de9b25SBarry Smith 124*30de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 125*30de9b25SBarry Smith 126*30de9b25SBarry Smith Concepts: error^setting condition 127*30de9b25SBarry Smith 128*30de9b25SBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ(), SETERRQ(), SETERRQ2(), SETERRQ3() 129*30de9b25SBarry Smith M*/ 1304a2ae208SSatish Balay #define SETERRQ1(n,s,a1) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1);} 131*30de9b25SBarry Smith 132*30de9b25SBarry Smith /*MC 133*30de9b25SBarry Smith SETERRQ2 - Macro that is called when an error has been detected, 134*30de9b25SBarry Smith 135*30de9b25SBarry Smith Not Collective 136*30de9b25SBarry Smith 137*30de9b25SBarry Smith Synopsis: 138*30de9b25SBarry Smith void SETERRQ2(int errorcode,char *formatmessage,arg1,arg2) 139*30de9b25SBarry Smith 140*30de9b25SBarry Smith 141*30de9b25SBarry Smith Input Parameters: 142*30de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 143*30de9b25SBarry Smith . message - error message in the printf format 144*30de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 145*30de9b25SBarry Smith - arg2 - argument (for example an integer, string or double) 146*30de9b25SBarry Smith 147*30de9b25SBarry Smith Level: beginner 148*30de9b25SBarry Smith 149*30de9b25SBarry Smith Notes: 150*30de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 151*30de9b25SBarry Smith 152*30de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 153*30de9b25SBarry Smith 154*30de9b25SBarry Smith Concepts: error^setting condition 155*30de9b25SBarry Smith 156*30de9b25SBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ(), SETERRQ1(), SETERRQ2(), SETERRQ3() 157*30de9b25SBarry Smith M*/ 1584a2ae208SSatish Balay #define SETERRQ2(n,s,a1,a2) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2);} 159*30de9b25SBarry Smith 160*30de9b25SBarry Smith /*MC 161*30de9b25SBarry Smith SETERRQ3 - Macro that is called when an error has been detected, 162*30de9b25SBarry Smith 163*30de9b25SBarry Smith Not Collective 164*30de9b25SBarry Smith 165*30de9b25SBarry Smith Synopsis: 166*30de9b25SBarry Smith void SETERRQ3(int errorcode,char *formatmessage,arg1,arg2,arg3) 167*30de9b25SBarry Smith 168*30de9b25SBarry Smith 169*30de9b25SBarry Smith Input Parameters: 170*30de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 171*30de9b25SBarry Smith . message - error message in the printf format 172*30de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 173*30de9b25SBarry Smith . arg2 - argument (for example an integer, string or double) 174*30de9b25SBarry Smith - arg3 - argument (for example an integer, string or double) 175*30de9b25SBarry Smith 176*30de9b25SBarry Smith Level: beginner 177*30de9b25SBarry Smith 178*30de9b25SBarry Smith Notes: 179*30de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 180*30de9b25SBarry Smith 181*30de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 182*30de9b25SBarry Smith 183*30de9b25SBarry Smith Concepts: error^setting condition 184*30de9b25SBarry Smith 185*30de9b25SBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ(), SETERRQ1(), SETERRQ2(), SETERRQ2() 186*30de9b25SBarry Smith M*/ 1874a2ae208SSatish Balay #define SETERRQ3(n,s,a1,a2,a3) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3);} 188*30de9b25SBarry Smith 1894a2ae208SSatish Balay #define SETERRQ4(n,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4);} 190a30c184eSMatthew Knepley #define SETERRQ5(n,s,a1,a2,a3,a4,a5) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5);} 191a30c184eSMatthew 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);} 192a30c184eSMatthew 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);} 193e855a17bSBarry Smith #define SETERRABORT(comm,n,s) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);MPI_Abort(comm,n);} 1949a00fa46SSatish Balay 195*30de9b25SBarry Smith /*MC 196*30de9b25SBarry Smith CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns 197*30de9b25SBarry Smith 198*30de9b25SBarry Smith Not Collective 199*30de9b25SBarry Smith 200*30de9b25SBarry Smith Synopsis: 201*30de9b25SBarry Smith void CHKERRQ(int errorcode) 202*30de9b25SBarry Smith 203*30de9b25SBarry Smith 204*30de9b25SBarry Smith Input Parameters: 205*30de9b25SBarry Smith . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 206*30de9b25SBarry Smith 207*30de9b25SBarry Smith Level: beginner 208*30de9b25SBarry Smith 209*30de9b25SBarry Smith Notes: 210*30de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 211*30de9b25SBarry Smith 212*30de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 213*30de9b25SBarry Smith 214*30de9b25SBarry Smith Concepts: error^setting condition 215*30de9b25SBarry Smith 216*30de9b25SBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ(), SETERRQ1(), SETERRQ2(), SETERRQ2() 217*30de9b25SBarry Smith M*/ 218c3be3f59SMatthew Knepley #define CHKERRQ(n) if (n) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");} 219*30de9b25SBarry Smith 22094a56cdfSMatthew Knepley #define CHKERRABORT(comm,n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");MPI_Abort(comm,n);} 22194a56cdfSMatthew Knepley #define CHKERRCONTINUE(n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");} 22285614651SBarry Smith 223*30de9b25SBarry Smith /*MC 224*30de9b25SBarry Smith CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected 225*30de9b25SBarry Smith 226*30de9b25SBarry Smith Not Collective 227*30de9b25SBarry Smith 228*30de9b25SBarry Smith Synopsis: 229*30de9b25SBarry Smith void CHKMEMQ(void) 230*30de9b25SBarry Smith 231*30de9b25SBarry Smith Level: beginner 232*30de9b25SBarry Smith 233*30de9b25SBarry Smith Notes: 234*30de9b25SBarry Smith Must run with the option -trdebug to enable this option 235*30de9b25SBarry Smith 236*30de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 237*30de9b25SBarry Smith 238*30de9b25SBarry Smith By defaults prints location where memory that is corrupted was allocated. 239*30de9b25SBarry Smith 240*30de9b25SBarry Smith Concepts: memory corruption 241*30de9b25SBarry Smith 242*30de9b25SBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ(), SETERRQ1(), SETERRQ2(), SETERRQ2(), 243*30de9b25SBarry Smith PetscTrValid() 244*30de9b25SBarry Smith M*/ 245ef66eb69SBarry Smith #define CHKMEMQ {int _7_ierr = PetscTrValid(__LINE__,__FUNCT__,__FILE__,__SDIR__);CHKERRQ(_7_ierr);} 24685614651SBarry Smith 247f1af5d2fSBarry Smith #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 248f1af5d2fSBarry Smith extern int __gierr; 249f1af5d2fSBarry Smith #define _ __gierr = 250ac355199SBarry Smith #define ___ CHKERRQ(__gierr); 251f1af5d2fSBarry Smith #endif 252f1af5d2fSBarry Smith 25354a8ef01SBarry Smith #else 25490d37a7cSBarry Smith #define SETERRQ(n,s) ; 25590d37a7cSBarry Smith #define SETERRQ1(n,s,a1) ; 25690d37a7cSBarry Smith #define SETERRQ2(n,s,a1,a2) ; 25790d37a7cSBarry Smith #define SETERRQ3(n,s,a1,a2,a3) ; 25890d37a7cSBarry Smith #define SETERRQ4(n,s,a1,a2,a3,a4) ; 2591ee4faa0SMatthew Knepley #define SETERRABORT(comm,n,s) ; 26085614651SBarry Smith 2614f227f7cSBarry Smith #define CHKERRQ(n) ; 2621ee4faa0SMatthew Knepley #define CHKERRABORT(comm,n) ; 2631ee4faa0SMatthew Knepley #define CHKERRCONTINUE(n) ; 26485614651SBarry Smith 26585614651SBarry Smith #define CHKMEMQ ; 26685614651SBarry Smith 267f1af5d2fSBarry Smith #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 268f1af5d2fSBarry Smith #define _ 269f1af5d2fSBarry Smith #define ___ 270f1af5d2fSBarry Smith #endif 271f1af5d2fSBarry Smith 27254a8ef01SBarry Smith #endif 27354a8ef01SBarry Smith 2744916b209SBarry Smith EXTERN int PetscErrorMessage(int,char**,char **); 275ca44d042SBarry Smith EXTERN int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*); 2763a7fca6bSBarry Smith EXTERN int PetscIgnoreErrorHandler(int,char*,char*,char*,int,int,char*,void*); 277ca44d042SBarry Smith EXTERN int PetscEmacsClientErrorHandler(int,char*,char*,char*,int,int,char*,void*); 278ca44d042SBarry Smith EXTERN int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*); 279ca44d042SBarry Smith EXTERN int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void*); 280ca44d042SBarry Smith EXTERN int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*); 281f80b7eb0SBarry Smith EXTERN int PetscError(int,char*,char*,char*,int,int,char*,...) PETSC_PRINTF_FORMAT_CHECK(7,8); 282ca44d042SBarry Smith EXTERN int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*); 283ca44d042SBarry Smith EXTERN int PetscPopErrorHandler(void); 284ca44d042SBarry Smith EXTERN int PetscDefaultSignalHandler(int,void*); 285ca44d042SBarry Smith EXTERN int PetscPushSignalHandler(int (*)(int,void *),void*); 286ca44d042SBarry Smith EXTERN int PetscPopSignalHandler(void); 287329f5518SBarry Smith 288329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 289ca44d042SBarry Smith EXTERN int PetscSetFPTrap(PetscFPTrap); 29054a8ef01SBarry Smith 2913a40ed3dSBarry Smith /* 2923a40ed3dSBarry Smith Allows the code to build a stack frame as it runs 2933a40ed3dSBarry Smith */ 294aa482453SBarry Smith #if defined(PETSC_USE_STACK) 2953a40ed3dSBarry Smith 296184914b5SBarry Smith #define PETSCSTACKSIZE 15 297184914b5SBarry Smith 2983a40ed3dSBarry Smith typedef struct { 299184914b5SBarry Smith char *function[PETSCSTACKSIZE]; 300184914b5SBarry Smith char *file[PETSCSTACKSIZE]; 301184914b5SBarry Smith char *directory[PETSCSTACKSIZE]; 302184914b5SBarry Smith int line[PETSCSTACKSIZE]; 303184914b5SBarry Smith int currentsize; 3043a40ed3dSBarry Smith } PetscStack; 3053a40ed3dSBarry Smith 3063a40ed3dSBarry Smith extern PetscStack *petscstack; 307ca44d042SBarry Smith EXTERN int PetscStackCopy(PetscStack*,PetscStack*); 308ca44d042SBarry Smith EXTERN int PetscStackPrint(PetscStack*,FILE* fp); 309184914b5SBarry Smith 310184914b5SBarry Smith #define PetscStackActive (petscstack != 0) 3113a40ed3dSBarry Smith 312aa482453SBarry Smith #if !defined(PETSC_HAVE_AMS) 3136d385327SIbrahima Ba 314*30de9b25SBarry Smith /*MC 315*30de9b25SBarry Smith PetscFunctionBegin - First executable line of each PETSc function 316*30de9b25SBarry Smith used for error handling. 317*30de9b25SBarry Smith 318*30de9b25SBarry Smith Synopsis: 319*30de9b25SBarry Smith void PetscFunctionBegin; 320*30de9b25SBarry Smith 321*30de9b25SBarry Smith Usage: 322*30de9b25SBarry Smith .vb 323*30de9b25SBarry Smith int something; 324*30de9b25SBarry Smith 325*30de9b25SBarry Smith PetscFunctionBegin; 326*30de9b25SBarry Smith .ve 327*30de9b25SBarry Smith 328*30de9b25SBarry Smith Notes: 329*30de9b25SBarry Smith Not available in Fortran 330*30de9b25SBarry Smith 331*30de9b25SBarry Smith Level: developer 332*30de9b25SBarry Smith 333*30de9b25SBarry Smith .seealso: PetscFunctionReturn() 334*30de9b25SBarry Smith 335*30de9b25SBarry Smith .keywords: traceback, error handling 336*30de9b25SBarry Smith M*/ 3373a40ed3dSBarry Smith #define PetscFunctionBegin \ 338beb17490SBarry Smith {\ 339184914b5SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 3404a2ae208SSatish Balay petscstack->function[petscstack->currentsize] = __FUNCT__; \ 341184914b5SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 342184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = __SDIR__; \ 343184914b5SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 344184914b5SBarry Smith petscstack->currentsize++; \ 3453a40ed3dSBarry Smith }} 3463a40ed3dSBarry Smith 3475cd90555SBarry Smith #define PetscStackPush(n) \ 348184914b5SBarry Smith {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 349184914b5SBarry Smith petscstack->function[petscstack->currentsize] = n; \ 350184914b5SBarry Smith petscstack->file[petscstack->currentsize] = "unknown"; \ 351184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = "unknown"; \ 352184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 353184914b5SBarry Smith petscstack->currentsize++; \ 3545cd90555SBarry Smith }} 3553a40ed3dSBarry Smith 356d64ed03dSBarry Smith #define PetscStackPop \ 357184914b5SBarry Smith {if (petscstack && petscstack->currentsize > 0) { \ 358184914b5SBarry Smith petscstack->currentsize--; \ 359184914b5SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 360184914b5SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 361184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = 0; \ 362184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 3635cd90555SBarry Smith }}; 364d64ed03dSBarry Smith 365*30de9b25SBarry Smith /*MC 366*30de9b25SBarry Smith PetscFunctionReturn - Last executable line of each PETSc function 367*30de9b25SBarry Smith used for error handling. Replaces return() 368*30de9b25SBarry Smith 369*30de9b25SBarry Smith Synopsis: 370*30de9b25SBarry Smith void PetscFunctionReturn(0); 371*30de9b25SBarry Smith 372*30de9b25SBarry Smith Usage: 373*30de9b25SBarry Smith .vb 374*30de9b25SBarry Smith .... 375*30de9b25SBarry Smith PetscFunctionReturn(0); 376*30de9b25SBarry Smith } 377*30de9b25SBarry Smith .ve 378*30de9b25SBarry Smith 379*30de9b25SBarry Smith Notes: 380*30de9b25SBarry Smith Not available in Fortran 381*30de9b25SBarry Smith 382*30de9b25SBarry Smith Level: developer 383*30de9b25SBarry Smith 384*30de9b25SBarry Smith .seealso: PetscFunctionBegin() 385*30de9b25SBarry Smith 386*30de9b25SBarry Smith .keywords: traceback, error handling 387*30de9b25SBarry Smith M*/ 3885cd90555SBarry Smith #define PetscFunctionReturn(a) \ 389beb17490SBarry Smith {\ 39006d1fe2cSBarry Smith PetscStackPop; \ 3915cd90555SBarry Smith return(a);} 392d64ed03dSBarry Smith 393ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 394ff94ddecSSatish Balay {\ 3951fceb228SKris Buschelman PetscStackPop; \ 3961fceb228SKris Buschelman return;} 397ff94ddecSSatish Balay 3983a40ed3dSBarry Smith #else 3993a40ed3dSBarry Smith 40006d1fe2cSBarry Smith /* 40106d1fe2cSBarry Smith Duplicate Code for when the ALICE Memory Snooper (AMS) 402aa482453SBarry Smith is being used. When PETSC_HAVE_AMS is defined. 40306d1fe2cSBarry Smith 40406d1fe2cSBarry Smith stack_mem is the AMS memory that contains fields for the 40506d1fe2cSBarry Smith number of stack frames and names of the stack frames 40606d1fe2cSBarry Smith */ 40706d1fe2cSBarry Smith 4086d385327SIbrahima Ba extern AMS_Memory stack_mem; 40906d1fe2cSBarry Smith extern int stack_err; 4106d385327SIbrahima Ba 4116d385327SIbrahima Ba #define PetscFunctionBegin \ 412beb17490SBarry Smith {\ 413184914b5SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 41406d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 4154a2ae208SSatish Balay petscstack->function[petscstack->currentsize] = __FUNCT__; \ 416184914b5SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 417184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = __SDIR__; \ 418184914b5SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 419184914b5SBarry Smith petscstack->currentsize++; \ 42006d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 4216d385327SIbrahima Ba }} 4226d385327SIbrahima Ba 4236d385327SIbrahima Ba #define PetscStackPush(n) \ 424184914b5SBarry Smith {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 42506d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 426184914b5SBarry Smith petscstack->function[petscstack->currentsize] = n; \ 427184914b5SBarry Smith petscstack->file[petscstack->currentsize] = "unknown"; \ 428184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = "unknown"; \ 429184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 430184914b5SBarry Smith petscstack->currentsize++; \ 43106d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 4326d385327SIbrahima Ba }} 4336d385327SIbrahima Ba 4346d385327SIbrahima Ba #define PetscStackPop \ 435184914b5SBarry Smith {if (petscstack && petscstack->currentsize > 0) { \ 43606d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 437184914b5SBarry Smith petscstack->currentsize--; \ 438184914b5SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 439184914b5SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 440184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = 0; \ 441184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 44206d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 4436d385327SIbrahima Ba }}; 4446d385327SIbrahima Ba 4456d385327SIbrahima Ba #define PetscFunctionReturn(a) \ 446beb17490SBarry Smith {\ 44706d1fe2cSBarry Smith PetscStackPop; \ 4486d385327SIbrahima Ba return(a);} 4496d385327SIbrahima Ba 450ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 451ff94ddecSSatish Balay {\ 4521fceb228SKris Buschelman PetscStackPop; \ 4531fceb228SKris Buschelman return;} 454ff94ddecSSatish Balay 455ff94ddecSSatish Balay 4566d385327SIbrahima Ba #endif 4576d385327SIbrahima Ba 4586d385327SIbrahima Ba #else 4596d385327SIbrahima Ba 4603a40ed3dSBarry Smith #define PetscFunctionBegin 4613a40ed3dSBarry Smith #define PetscFunctionReturn(a) return(a) 4621fceb228SKris Buschelman #define PetscFunctionReturnVoid() return() 463d64ed03dSBarry Smith #define PetscStackPop 464d64ed03dSBarry Smith #define PetscStackPush(f) 465d64ed03dSBarry Smith #define PetscStackActive 0 4663a40ed3dSBarry Smith 4673a40ed3dSBarry Smith #endif 4683a40ed3dSBarry Smith 469ca44d042SBarry Smith EXTERN int PetscStackCreate(void); 470b0a32e0cSBarry Smith EXTERN int PetscStackView(PetscViewer); 471ca44d042SBarry Smith EXTERN int PetscStackDestroy(void); 472ca44d042SBarry Smith EXTERN int PetscStackPublish(void); 473ca44d042SBarry Smith EXTERN int PetscStackDepublish(void); 4743a40ed3dSBarry Smith 47506d1fe2cSBarry Smith 47606d1fe2cSBarry Smith #endif 47706d1fe2cSBarry Smith 478329f5518SBarry Smith 479*30de9b25SBarry Smith 480*30de9b25SBarry Smith 481*30de9b25SBarry Smith 482*30de9b25SBarry Smith 483*30de9b25SBarry Smith 484*30de9b25SBarry Smith 485*30de9b25SBarry Smith 486