154a8ef01SBarry Smith /* 24f227f7cSBarry Smith Contains all error handling code for PETSc. 354a8ef01SBarry Smith */ 445d48df9SBarry Smith #if !defined(__PETSCERROR_H) 545d48df9SBarry Smith #define __PETSCERROR_H 6c22c1629SBarry Smith #include "petsc.h" 7e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN 8c22c1629SBarry Smith 9aa482453SBarry Smith #if defined(PETSC_HAVE_AMS) 106d385327SIbrahima Ba #include "ams.h" 116d385327SIbrahima Ba #endif 126d385327SIbrahima Ba 1354a8ef01SBarry Smith /* 1454a8ef01SBarry Smith Defines the directory where the compiled source is located; used 155e97870eSBarry Smith in printing error messages. Each makefile has an entry 165e97870eSBarry Smith LOCDIR = thedirectory 170cd5afcaSLois Curfman McInnes and bmake/common_variables includes in CCPPFLAGS -D__SDIR__='"${LOCDIR}"' 185e97870eSBarry Smith which is a flag passed to the C/C++ compilers. 1954a8ef01SBarry Smith */ 20c22c1629SBarry Smith #if !defined(__SDIR__) 212ee1dbe0SBarry Smith #define __SDIR__ "unknowndirectory/" 2254a8ef01SBarry Smith #endif 2354a8ef01SBarry Smith 2454a8ef01SBarry Smith /* 254f227f7cSBarry Smith Defines the function where the compiled source is located; used 264f227f7cSBarry Smith in printing error messages. 274f227f7cSBarry Smith */ 284a2ae208SSatish Balay #if !defined(__FUNCT__) 29da9b6338SBarry Smith #define __FUNCT__ "User provided function" 304f227f7cSBarry Smith #endif 314f227f7cSBarry Smith 324f227f7cSBarry Smith /* 33329ffe3dSLois Curfman McInnes These are the generic error codes. These error codes are used 34*e2d1d2b7SBarry Smith many different places in the PETSc source code. The string versions are 35*e2d1d2b7SBarry Smith at src/sys/src/error/err.c any changes here must also be made there 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 */ 41*e2d1d2b7SBarry Smith #define PETSC_ERR_SUP_SYS 57 /* no support for requested operation on this computer system */ 42*e2d1d2b7SBarry Smith #define PETSC_ERR_ORDER 58 /* operation done in wrong order */ 4345d48df9SBarry Smith #define PETSC_ERR_SIG 59 /* signal received */ 44f1caa5a4SBarry Smith #define PETSC_ERR_FP 72 /* floating point exception */ 45a8c6a408SBarry Smith #define PETSC_ERR_COR 74 /* corrupted PETSc object */ 46a8c6a408SBarry Smith #define PETSC_ERR_LIB 76 /* error in library called by PETSc */ 47329ffe3dSLois Curfman McInnes #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */ 48329ffe3dSLois Curfman McInnes #define PETSC_ERR_MEMC 78 /* memory corruption */ 49b3cc6726SBarry Smith #define PETSC_ERR_CONV_FAILED 82 /* iterative method (KSP or SNES) failed */ 5045d48df9SBarry Smith 5145d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */ 5245d48df9SBarry Smith #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */ 53a8c6a408SBarry Smith #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */ 5445d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */ 5545d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */ 564f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */ 574f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */ 586831982aSBarry Smith #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */ 59d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */ 60a8c6a408SBarry Smith #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ 614482741eSBarry Smith #define PETSC_ERR_ARG_NULL 85 /* argument is null that should not be */ 624f227f7cSBarry Smith 634f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ 644f227f7cSBarry Smith #define PETSC_ERR_FILE_READ 66 /* unable to read from file */ 654f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */ 66a8c6a408SBarry Smith #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */ 6745d48df9SBarry Smith 68329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */ 699e3b2f23SBarry Smith #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */ 7054a8ef01SBarry Smith 71aa482453SBarry Smith #if defined(PETSC_USE_DEBUG) 7230de9b25SBarry Smith 7330de9b25SBarry Smith /*MC 7430de9b25SBarry Smith SETERRQ - Macro that is called when an error has been detected, 7530de9b25SBarry Smith 7630de9b25SBarry Smith Not Collective 7730de9b25SBarry Smith 7830de9b25SBarry Smith Synopsis: 7930de9b25SBarry Smith void SETERRQ(int errorcode,char *message) 8030de9b25SBarry Smith 8130de9b25SBarry Smith 8230de9b25SBarry Smith Input Parameters: 8330de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 8430de9b25SBarry Smith - message - error message 8530de9b25SBarry Smith 8630de9b25SBarry Smith Level: beginner 8730de9b25SBarry Smith 8830de9b25SBarry Smith Notes: 8930de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 9030de9b25SBarry Smith 9130de9b25SBarry Smith See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments 9230de9b25SBarry Smith 9330de9b25SBarry Smith 9430de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 9530de9b25SBarry Smith 9630de9b25SBarry Smith Concepts: error^setting condition 9730de9b25SBarry Smith 9891d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3() 9930de9b25SBarry Smith M*/ 1004a2ae208SSatish Balay #define SETERRQ(n,s) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);} 10130de9b25SBarry Smith 10230de9b25SBarry Smith /*MC 10330de9b25SBarry Smith SETERRQ1 - Macro that is called when an error has been detected, 10430de9b25SBarry Smith 10530de9b25SBarry Smith Not Collective 10630de9b25SBarry Smith 10730de9b25SBarry Smith Synopsis: 10830de9b25SBarry Smith void SETERRQ1(int errorcode,char *formatmessage,arg) 10930de9b25SBarry Smith 11030de9b25SBarry Smith 11130de9b25SBarry Smith Input Parameters: 11230de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 11330de9b25SBarry Smith . message - error message in the printf format 11430de9b25SBarry Smith - arg - argument (for example an integer, string or double) 11530de9b25SBarry Smith 11630de9b25SBarry Smith Level: beginner 11730de9b25SBarry Smith 11830de9b25SBarry Smith Notes: 11930de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 12030de9b25SBarry Smith 12130de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 12230de9b25SBarry Smith 12330de9b25SBarry Smith Concepts: error^setting condition 12430de9b25SBarry Smith 12591d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3() 12630de9b25SBarry Smith M*/ 1274a2ae208SSatish Balay #define SETERRQ1(n,s,a1) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1);} 12830de9b25SBarry Smith 12930de9b25SBarry Smith /*MC 13030de9b25SBarry Smith SETERRQ2 - Macro that is called when an error has been detected, 13130de9b25SBarry Smith 13230de9b25SBarry Smith Not Collective 13330de9b25SBarry Smith 13430de9b25SBarry Smith Synopsis: 13530de9b25SBarry Smith void SETERRQ2(int errorcode,char *formatmessage,arg1,arg2) 13630de9b25SBarry Smith 13730de9b25SBarry Smith 13830de9b25SBarry Smith Input Parameters: 13930de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 14030de9b25SBarry Smith . message - error message in the printf format 14130de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 14230de9b25SBarry Smith - arg2 - argument (for example an integer, string or double) 14330de9b25SBarry Smith 14430de9b25SBarry Smith Level: beginner 14530de9b25SBarry Smith 14630de9b25SBarry Smith Notes: 14730de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 14830de9b25SBarry Smith 14930de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 15030de9b25SBarry Smith 15130de9b25SBarry Smith Concepts: error^setting condition 15230de9b25SBarry Smith 15391d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3() 15430de9b25SBarry Smith M*/ 1554a2ae208SSatish Balay #define SETERRQ2(n,s,a1,a2) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2);} 15630de9b25SBarry Smith 15730de9b25SBarry Smith /*MC 15830de9b25SBarry Smith SETERRQ3 - Macro that is called when an error has been detected, 15930de9b25SBarry Smith 16030de9b25SBarry Smith Not Collective 16130de9b25SBarry Smith 16230de9b25SBarry Smith Synopsis: 16330de9b25SBarry Smith void SETERRQ3(int errorcode,char *formatmessage,arg1,arg2,arg3) 16430de9b25SBarry Smith 16530de9b25SBarry Smith 16630de9b25SBarry Smith Input Parameters: 16730de9b25SBarry Smith + errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 16830de9b25SBarry Smith . message - error message in the printf format 16930de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 17030de9b25SBarry Smith . arg2 - argument (for example an integer, string or double) 17130de9b25SBarry Smith - arg3 - argument (for example an integer, string or double) 17230de9b25SBarry Smith 17330de9b25SBarry Smith Level: beginner 17430de9b25SBarry Smith 17530de9b25SBarry Smith Notes: 17630de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 17730de9b25SBarry Smith 17830de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 17930de9b25SBarry Smith 18030de9b25SBarry Smith Concepts: error^setting condition 18130de9b25SBarry Smith 18291d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2() 18330de9b25SBarry Smith M*/ 1844a2ae208SSatish Balay #define SETERRQ3(n,s,a1,a2,a3) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3);} 18530de9b25SBarry Smith 1864a2ae208SSatish Balay #define SETERRQ4(n,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4);} 187a30c184eSMatthew Knepley #define SETERRQ5(n,s,a1,a2,a3,a4,a5) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5);} 188a30c184eSMatthew 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);} 189a30c184eSMatthew 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);} 190e855a17bSBarry Smith #define SETERRABORT(comm,n,s) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);MPI_Abort(comm,n);} 1919a00fa46SSatish Balay 19230de9b25SBarry Smith /*MC 19330de9b25SBarry Smith CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns 19430de9b25SBarry Smith 19530de9b25SBarry Smith Not Collective 19630de9b25SBarry Smith 19730de9b25SBarry Smith Synopsis: 19830de9b25SBarry Smith void CHKERRQ(int errorcode) 19930de9b25SBarry Smith 20030de9b25SBarry Smith 20130de9b25SBarry Smith Input Parameters: 20230de9b25SBarry Smith . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 20330de9b25SBarry Smith 20430de9b25SBarry Smith Level: beginner 20530de9b25SBarry Smith 20630de9b25SBarry Smith Notes: 20730de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 20830de9b25SBarry Smith 20930de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 21030de9b25SBarry Smith 21130de9b25SBarry Smith Concepts: error^setting condition 21230de9b25SBarry Smith 21391d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2() 21430de9b25SBarry Smith M*/ 215c3be3f59SMatthew Knepley #define CHKERRQ(n) if (n) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");} 21630de9b25SBarry Smith 21794a56cdfSMatthew Knepley #define CHKERRABORT(comm,n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");MPI_Abort(comm,n);} 21894a56cdfSMatthew Knepley #define CHKERRCONTINUE(n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");} 21985614651SBarry Smith 22030de9b25SBarry Smith /*MC 22130de9b25SBarry Smith CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected 22230de9b25SBarry Smith 22330de9b25SBarry Smith Not Collective 22430de9b25SBarry Smith 22530de9b25SBarry Smith Synopsis: 22691d3bdf4SKris Buschelman CHKMEMQ; 22730de9b25SBarry Smith 22830de9b25SBarry Smith Level: beginner 22930de9b25SBarry Smith 23030de9b25SBarry Smith Notes: 23130de9b25SBarry Smith Must run with the option -trdebug to enable this option 23230de9b25SBarry Smith 23330de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 23430de9b25SBarry Smith 23530de9b25SBarry Smith By defaults prints location where memory that is corrupted was allocated. 23630de9b25SBarry Smith 23730de9b25SBarry Smith Concepts: memory corruption 23830de9b25SBarry Smith 23991d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2(), 24030de9b25SBarry Smith PetscTrValid() 24130de9b25SBarry Smith M*/ 242ef66eb69SBarry Smith #define CHKMEMQ {int _7_ierr = PetscTrValid(__LINE__,__FUNCT__,__FILE__,__SDIR__);CHKERRQ(_7_ierr);} 24385614651SBarry Smith 244f1af5d2fSBarry Smith #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 245f1af5d2fSBarry Smith extern int __gierr; 246f1af5d2fSBarry Smith #define _ __gierr = 247ac355199SBarry Smith #define ___ CHKERRQ(__gierr); 248f1af5d2fSBarry Smith #endif 249f1af5d2fSBarry Smith 25054a8ef01SBarry Smith #else 25190d37a7cSBarry Smith #define SETERRQ(n,s) ; 25290d37a7cSBarry Smith #define SETERRQ1(n,s,a1) ; 25390d37a7cSBarry Smith #define SETERRQ2(n,s,a1,a2) ; 25490d37a7cSBarry Smith #define SETERRQ3(n,s,a1,a2,a3) ; 25590d37a7cSBarry Smith #define SETERRQ4(n,s,a1,a2,a3,a4) ; 2561ee4faa0SMatthew Knepley #define SETERRABORT(comm,n,s) ; 25785614651SBarry Smith 2584f227f7cSBarry Smith #define CHKERRQ(n) ; 2591ee4faa0SMatthew Knepley #define CHKERRABORT(comm,n) ; 2601ee4faa0SMatthew Knepley #define CHKERRCONTINUE(n) ; 26185614651SBarry Smith 26285614651SBarry Smith #define CHKMEMQ ; 26385614651SBarry Smith 264f1af5d2fSBarry Smith #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 265f1af5d2fSBarry Smith #define _ 266f1af5d2fSBarry Smith #define ___ 267f1af5d2fSBarry Smith #endif 268f1af5d2fSBarry Smith 26954a8ef01SBarry Smith #endif 27054a8ef01SBarry Smith 2712fc52814SBarry Smith EXTERN int PetscErrorMessage(int,const char*[],char **); 2724c39959dSBarry Smith EXTERN int PetscTraceBackErrorHandler(int,const char*,const char*,const char*,int,int,const char*,void*); 2734c39959dSBarry Smith EXTERN int PetscIgnoreErrorHandler(int,const char*,const char*,const char*,int,int,const char*,void*); 2744c39959dSBarry Smith EXTERN int PetscEmacsClientErrorHandler(int,const char*,const char*,const char*,int,int,const char*,void*); 2754c39959dSBarry Smith EXTERN int PetscStopErrorHandler(int,const char*,const char*,const char*,int,int,const char*,void*); 2764c39959dSBarry Smith EXTERN int PetscAbortErrorHandler(int,const char*,const char*,const char*,int,int,const char*,void*); 2774c39959dSBarry Smith EXTERN int PetscAttachDebuggerErrorHandler(int,const char*,const char*,const char*,int,int,const char*,void*); 2784c39959dSBarry Smith EXTERN int PetscError(int,const char*,const char*,const char*,int,int,const char*,...) PETSC_PRINTF_FORMAT_CHECK(7,8); 2794c39959dSBarry Smith EXTERN int PetscPushErrorHandler(int (*handler)(int,const char*,const char*,const char*,int,int,const char*,void*),void*); 280ca44d042SBarry Smith EXTERN int PetscPopErrorHandler(void); 281ca44d042SBarry Smith EXTERN int PetscDefaultSignalHandler(int,void*); 282ca44d042SBarry Smith EXTERN int PetscPushSignalHandler(int (*)(int,void *),void*); 283ca44d042SBarry Smith EXTERN int PetscPopSignalHandler(void); 284329f5518SBarry Smith 285329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 286ca44d042SBarry Smith EXTERN int PetscSetFPTrap(PetscFPTrap); 28754a8ef01SBarry Smith 2883a40ed3dSBarry Smith /* 2893a40ed3dSBarry Smith Allows the code to build a stack frame as it runs 2903a40ed3dSBarry Smith */ 291aa482453SBarry Smith #if defined(PETSC_USE_STACK) 2923a40ed3dSBarry Smith 293184914b5SBarry Smith #define PETSCSTACKSIZE 15 294184914b5SBarry Smith 2953a40ed3dSBarry Smith typedef struct { 2960e33f6ddSBarry Smith const char *function[PETSCSTACKSIZE]; 2970e33f6ddSBarry Smith const char *file[PETSCSTACKSIZE]; 2980e33f6ddSBarry Smith const char *directory[PETSCSTACKSIZE]; 299184914b5SBarry Smith int line[PETSCSTACKSIZE]; 300184914b5SBarry Smith int currentsize; 3013a40ed3dSBarry Smith } PetscStack; 3023a40ed3dSBarry Smith 3033a40ed3dSBarry Smith extern PetscStack *petscstack; 304ca44d042SBarry Smith EXTERN int PetscStackCopy(PetscStack*,PetscStack*); 305ca44d042SBarry Smith EXTERN int PetscStackPrint(PetscStack*,FILE* fp); 306184914b5SBarry Smith 307184914b5SBarry Smith #define PetscStackActive (petscstack != 0) 3083a40ed3dSBarry Smith 309aa482453SBarry Smith #if !defined(PETSC_HAVE_AMS) 3106d385327SIbrahima Ba 31130de9b25SBarry Smith /*MC 31230de9b25SBarry Smith PetscFunctionBegin - First executable line of each PETSc function 31330de9b25SBarry Smith used for error handling. 31430de9b25SBarry Smith 31530de9b25SBarry Smith Synopsis: 31630de9b25SBarry Smith void PetscFunctionBegin; 31730de9b25SBarry Smith 31830de9b25SBarry Smith Usage: 31930de9b25SBarry Smith .vb 32030de9b25SBarry Smith int something; 32130de9b25SBarry Smith 32230de9b25SBarry Smith PetscFunctionBegin; 32330de9b25SBarry Smith .ve 32430de9b25SBarry Smith 32530de9b25SBarry Smith Notes: 32630de9b25SBarry Smith Not available in Fortran 32730de9b25SBarry Smith 32830de9b25SBarry Smith Level: developer 32930de9b25SBarry Smith 33030de9b25SBarry Smith .seealso: PetscFunctionReturn() 33130de9b25SBarry Smith 33230de9b25SBarry Smith .keywords: traceback, error handling 33330de9b25SBarry Smith M*/ 3343a40ed3dSBarry Smith #define PetscFunctionBegin \ 335beb17490SBarry Smith {\ 336184914b5SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 3374a2ae208SSatish Balay petscstack->function[petscstack->currentsize] = __FUNCT__; \ 338184914b5SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 339184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = __SDIR__; \ 340184914b5SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 341184914b5SBarry Smith petscstack->currentsize++; \ 3423a40ed3dSBarry Smith }} 3433a40ed3dSBarry Smith 3445cd90555SBarry Smith #define PetscStackPush(n) \ 345184914b5SBarry Smith {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 346184914b5SBarry Smith petscstack->function[petscstack->currentsize] = n; \ 347184914b5SBarry Smith petscstack->file[petscstack->currentsize] = "unknown"; \ 348184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = "unknown"; \ 349184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 350184914b5SBarry Smith petscstack->currentsize++; \ 3515cd90555SBarry Smith }} 3523a40ed3dSBarry Smith 353d64ed03dSBarry Smith #define PetscStackPop \ 354184914b5SBarry Smith {if (petscstack && petscstack->currentsize > 0) { \ 355184914b5SBarry Smith petscstack->currentsize--; \ 356184914b5SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 357184914b5SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 358184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = 0; \ 359184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 3605cd90555SBarry Smith }}; 361d64ed03dSBarry Smith 36230de9b25SBarry Smith /*MC 36330de9b25SBarry Smith PetscFunctionReturn - Last executable line of each PETSc function 36430de9b25SBarry Smith used for error handling. Replaces return() 36530de9b25SBarry Smith 36630de9b25SBarry Smith Synopsis: 36730de9b25SBarry Smith void PetscFunctionReturn(0); 36830de9b25SBarry Smith 36930de9b25SBarry Smith Usage: 37030de9b25SBarry Smith .vb 37130de9b25SBarry Smith .... 37230de9b25SBarry Smith PetscFunctionReturn(0); 37330de9b25SBarry Smith } 37430de9b25SBarry Smith .ve 37530de9b25SBarry Smith 37630de9b25SBarry Smith Notes: 37730de9b25SBarry Smith Not available in Fortran 37830de9b25SBarry Smith 37930de9b25SBarry Smith Level: developer 38030de9b25SBarry Smith 38130de9b25SBarry Smith .seealso: PetscFunctionBegin() 38230de9b25SBarry Smith 38330de9b25SBarry Smith .keywords: traceback, error handling 38430de9b25SBarry Smith M*/ 3855cd90555SBarry Smith #define PetscFunctionReturn(a) \ 386beb17490SBarry Smith {\ 38706d1fe2cSBarry Smith PetscStackPop; \ 3885cd90555SBarry Smith return(a);} 389d64ed03dSBarry Smith 390ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 391ff94ddecSSatish Balay {\ 3921fceb228SKris Buschelman PetscStackPop; \ 3931fceb228SKris Buschelman return;} 394ff94ddecSSatish Balay 3953a40ed3dSBarry Smith #else 3963a40ed3dSBarry Smith 39706d1fe2cSBarry Smith /* 39806d1fe2cSBarry Smith Duplicate Code for when the ALICE Memory Snooper (AMS) 399aa482453SBarry Smith is being used. When PETSC_HAVE_AMS is defined. 40006d1fe2cSBarry Smith 40106d1fe2cSBarry Smith stack_mem is the AMS memory that contains fields for the 40206d1fe2cSBarry Smith number of stack frames and names of the stack frames 40306d1fe2cSBarry Smith */ 40406d1fe2cSBarry Smith 4056d385327SIbrahima Ba extern AMS_Memory stack_mem; 40606d1fe2cSBarry Smith extern int stack_err; 4076d385327SIbrahima Ba 4086d385327SIbrahima Ba #define PetscFunctionBegin \ 409beb17490SBarry Smith {\ 410184914b5SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 41106d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 4124a2ae208SSatish Balay petscstack->function[petscstack->currentsize] = __FUNCT__; \ 413184914b5SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 414184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = __SDIR__; \ 415184914b5SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 416184914b5SBarry Smith petscstack->currentsize++; \ 41706d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 4186d385327SIbrahima Ba }} 4196d385327SIbrahima Ba 4206d385327SIbrahima Ba #define PetscStackPush(n) \ 421184914b5SBarry Smith {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 42206d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 423184914b5SBarry Smith petscstack->function[petscstack->currentsize] = n; \ 424184914b5SBarry Smith petscstack->file[petscstack->currentsize] = "unknown"; \ 425184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = "unknown"; \ 426184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 427184914b5SBarry Smith petscstack->currentsize++; \ 42806d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 4296d385327SIbrahima Ba }} 4306d385327SIbrahima Ba 4316d385327SIbrahima Ba #define PetscStackPop \ 432184914b5SBarry Smith {if (petscstack && petscstack->currentsize > 0) { \ 43306d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 434184914b5SBarry Smith petscstack->currentsize--; \ 435184914b5SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 436184914b5SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 437184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = 0; \ 438184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 43906d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 4406d385327SIbrahima Ba }}; 4416d385327SIbrahima Ba 4426d385327SIbrahima Ba #define PetscFunctionReturn(a) \ 443beb17490SBarry Smith {\ 44406d1fe2cSBarry Smith PetscStackPop; \ 4456d385327SIbrahima Ba return(a);} 4466d385327SIbrahima Ba 447ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 448ff94ddecSSatish Balay {\ 4491fceb228SKris Buschelman PetscStackPop; \ 4501fceb228SKris Buschelman return;} 451ff94ddecSSatish Balay 452ff94ddecSSatish Balay 4536d385327SIbrahima Ba #endif 4546d385327SIbrahima Ba 4556d385327SIbrahima Ba #else 4566d385327SIbrahima Ba 4573a40ed3dSBarry Smith #define PetscFunctionBegin 4583a40ed3dSBarry Smith #define PetscFunctionReturn(a) return(a) 4591fceb228SKris Buschelman #define PetscFunctionReturnVoid() return() 460d64ed03dSBarry Smith #define PetscStackPop 461d64ed03dSBarry Smith #define PetscStackPush(f) 462d64ed03dSBarry Smith #define PetscStackActive 0 4633a40ed3dSBarry Smith 4643a40ed3dSBarry Smith #endif 4653a40ed3dSBarry Smith 466ca44d042SBarry Smith EXTERN int PetscStackCreate(void); 467b0a32e0cSBarry Smith EXTERN int PetscStackView(PetscViewer); 468ca44d042SBarry Smith EXTERN int PetscStackDestroy(void); 469ca44d042SBarry Smith EXTERN int PetscStackPublish(void); 470ca44d042SBarry Smith EXTERN int PetscStackDepublish(void); 4713a40ed3dSBarry Smith 47206d1fe2cSBarry Smith 473e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END 47406d1fe2cSBarry Smith #endif 475