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 7c22c1629SBarry Smith #include "petsc.h" 8e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN 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) 7530de9b25SBarry Smith 7630de9b25SBarry Smith /*MC 7730de9b25SBarry Smith SETERRQ - Macro that is called when an error has been detected, 7830de9b25SBarry Smith 7930de9b25SBarry Smith Not Collective 8030de9b25SBarry Smith 8130de9b25SBarry Smith Synopsis: 8230de9b25SBarry Smith void SETERRQ(int errorcode,char *message) 8330de9b25SBarry Smith 8430de9b25SBarry Smith 8530de9b25SBarry Smith Input Parameters: 8630de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 8730de9b25SBarry Smith - message - error message 8830de9b25SBarry Smith 8930de9b25SBarry Smith Level: beginner 9030de9b25SBarry Smith 9130de9b25SBarry Smith Notes: 9230de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 9330de9b25SBarry Smith 9430de9b25SBarry Smith See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments 9530de9b25SBarry Smith 9630de9b25SBarry Smith 9730de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 9830de9b25SBarry Smith 9930de9b25SBarry Smith Concepts: error^setting condition 10030de9b25SBarry Smith 101*91d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3() 10230de9b25SBarry Smith M*/ 1034a2ae208SSatish Balay #define SETERRQ(n,s) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);} 10430de9b25SBarry Smith 10530de9b25SBarry Smith /*MC 10630de9b25SBarry Smith SETERRQ1 - Macro that is called when an error has been detected, 10730de9b25SBarry Smith 10830de9b25SBarry Smith Not Collective 10930de9b25SBarry Smith 11030de9b25SBarry Smith Synopsis: 11130de9b25SBarry Smith void SETERRQ1(int errorcode,char *formatmessage,arg) 11230de9b25SBarry Smith 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 128*91d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3() 12930de9b25SBarry Smith M*/ 1304a2ae208SSatish Balay #define SETERRQ1(n,s,a1) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1);} 13130de9b25SBarry Smith 13230de9b25SBarry Smith /*MC 13330de9b25SBarry Smith SETERRQ2 - Macro that is called when an error has been detected, 13430de9b25SBarry Smith 13530de9b25SBarry Smith Not Collective 13630de9b25SBarry Smith 13730de9b25SBarry Smith Synopsis: 13830de9b25SBarry Smith void SETERRQ2(int errorcode,char *formatmessage,arg1,arg2) 13930de9b25SBarry Smith 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 156*91d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3() 15730de9b25SBarry Smith M*/ 1584a2ae208SSatish Balay #define SETERRQ2(n,s,a1,a2) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,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 Not Collective 16430de9b25SBarry Smith 16530de9b25SBarry Smith Synopsis: 16630de9b25SBarry Smith void SETERRQ3(int errorcode,char *formatmessage,arg1,arg2,arg3) 16730de9b25SBarry Smith 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 18130de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 18230de9b25SBarry Smith 18330de9b25SBarry Smith Concepts: error^setting condition 18430de9b25SBarry Smith 185*91d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2() 18630de9b25SBarry Smith M*/ 1874a2ae208SSatish Balay #define SETERRQ3(n,s,a1,a2,a3) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3);} 18830de9b25SBarry 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 19530de9b25SBarry Smith /*MC 19630de9b25SBarry Smith CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns 19730de9b25SBarry Smith 19830de9b25SBarry Smith Not Collective 19930de9b25SBarry Smith 20030de9b25SBarry Smith Synopsis: 20130de9b25SBarry Smith void CHKERRQ(int errorcode) 20230de9b25SBarry Smith 20330de9b25SBarry Smith 20430de9b25SBarry Smith Input Parameters: 20530de9b25SBarry Smith . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 20630de9b25SBarry Smith 20730de9b25SBarry Smith Level: beginner 20830de9b25SBarry Smith 20930de9b25SBarry Smith Notes: 21030de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 21130de9b25SBarry Smith 21230de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 21330de9b25SBarry Smith 21430de9b25SBarry Smith Concepts: error^setting condition 21530de9b25SBarry Smith 216*91d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2() 21730de9b25SBarry Smith M*/ 218c3be3f59SMatthew Knepley #define CHKERRQ(n) if (n) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");} 21930de9b25SBarry 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 22330de9b25SBarry Smith /*MC 22430de9b25SBarry Smith CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected 22530de9b25SBarry Smith 22630de9b25SBarry Smith Not Collective 22730de9b25SBarry Smith 22830de9b25SBarry Smith Synopsis: 229*91d3bdf4SKris Buschelman CHKMEMQ; 23030de9b25SBarry Smith 23130de9b25SBarry Smith Level: beginner 23230de9b25SBarry Smith 23330de9b25SBarry Smith Notes: 23430de9b25SBarry Smith Must run with the option -trdebug to enable this option 23530de9b25SBarry Smith 23630de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 23730de9b25SBarry Smith 23830de9b25SBarry Smith By defaults prints location where memory that is corrupted was allocated. 23930de9b25SBarry Smith 24030de9b25SBarry Smith Concepts: memory corruption 24130de9b25SBarry Smith 242*91d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2(), 24330de9b25SBarry Smith PetscTrValid() 24430de9b25SBarry 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 **); 2754c39959dSBarry Smith EXTERN int PetscTraceBackErrorHandler(int,const char*,const char*,const char*,int,int,const char*,void*); 2764c39959dSBarry Smith EXTERN int PetscIgnoreErrorHandler(int,const char*,const char*,const char*,int,int,const char*,void*); 2774c39959dSBarry Smith EXTERN int PetscEmacsClientErrorHandler(int,const char*,const char*,const char*,int,int,const char*,void*); 2784c39959dSBarry Smith EXTERN int PetscStopErrorHandler(int,const char*,const char*,const char*,int,int,const char*,void*); 2794c39959dSBarry Smith EXTERN int PetscAbortErrorHandler(int,const char*,const char*,const char*,int,int,const char*,void*); 2804c39959dSBarry Smith EXTERN int PetscAttachDebuggerErrorHandler(int,const char*,const char*,const char*,int,int,const char*,void*); 2814c39959dSBarry Smith EXTERN int PetscError(int,const char*,const char*,const char*,int,int,const char*,...) PETSC_PRINTF_FORMAT_CHECK(7,8); 2824c39959dSBarry Smith EXTERN int PetscPushErrorHandler(int (*handler)(int,const char*,const char*,const char*,int,int,const 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 31430de9b25SBarry Smith /*MC 31530de9b25SBarry Smith PetscFunctionBegin - First executable line of each PETSc function 31630de9b25SBarry Smith used for error handling. 31730de9b25SBarry Smith 31830de9b25SBarry Smith Synopsis: 31930de9b25SBarry Smith void PetscFunctionBegin; 32030de9b25SBarry Smith 32130de9b25SBarry Smith Usage: 32230de9b25SBarry Smith .vb 32330de9b25SBarry Smith int something; 32430de9b25SBarry Smith 32530de9b25SBarry Smith PetscFunctionBegin; 32630de9b25SBarry Smith .ve 32730de9b25SBarry Smith 32830de9b25SBarry Smith Notes: 32930de9b25SBarry Smith Not available in Fortran 33030de9b25SBarry Smith 33130de9b25SBarry Smith Level: developer 33230de9b25SBarry Smith 33330de9b25SBarry Smith .seealso: PetscFunctionReturn() 33430de9b25SBarry Smith 33530de9b25SBarry Smith .keywords: traceback, error handling 33630de9b25SBarry 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 36530de9b25SBarry Smith /*MC 36630de9b25SBarry Smith PetscFunctionReturn - Last executable line of each PETSc function 36730de9b25SBarry Smith used for error handling. Replaces return() 36830de9b25SBarry Smith 36930de9b25SBarry Smith Synopsis: 37030de9b25SBarry Smith void PetscFunctionReturn(0); 37130de9b25SBarry Smith 37230de9b25SBarry Smith Usage: 37330de9b25SBarry Smith .vb 37430de9b25SBarry Smith .... 37530de9b25SBarry Smith PetscFunctionReturn(0); 37630de9b25SBarry Smith } 37730de9b25SBarry Smith .ve 37830de9b25SBarry Smith 37930de9b25SBarry Smith Notes: 38030de9b25SBarry Smith Not available in Fortran 38130de9b25SBarry Smith 38230de9b25SBarry Smith Level: developer 38330de9b25SBarry Smith 38430de9b25SBarry Smith .seealso: PetscFunctionBegin() 38530de9b25SBarry Smith 38630de9b25SBarry Smith .keywords: traceback, error handling 38730de9b25SBarry 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 476e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END 47706d1fe2cSBarry Smith #endif 478