1*ff94ddecSSatish Balay /* $Id: petscerror.h,v 1.45 2000/03/31 22:28:09 curfman Exp balay $ */ 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 */ 295615d1e5SSatish Balay #if !defined(__FUNC__) 3094a9d846SBarry Smith #define __FUNC__ "unknownfunction" 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 3745d48df9SBarry Smith In addition, each specific error in the code has an error 38126a7499SLois Curfman McInnes message: a specific, unique error code. (The specific error 39126a7499SLois Curfman McInnes code is not yet in use; these will be generated automatically and 404f227f7cSBarry Smith embed an integer into the PetscError() calls. For non-English 41329ffe3dSLois Curfman McInnes error messages, that integer will be extracted and used to look up the 424f227f7cSBarry Smith appropriate error message in the local language from a file.) 4345d48df9SBarry Smith 4454a8ef01SBarry Smith */ 4545d48df9SBarry Smith #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 4647794344SBarry Smith #define PETSC_ERR_SUP 56 /* no support for requested operation */ 4745d48df9SBarry Smith #define PETSC_ERR_SIG 59 /* signal received */ 48f1caa5a4SBarry Smith #define PETSC_ERR_FP 72 /* floating point exception */ 49a8c6a408SBarry Smith #define PETSC_ERR_COR 74 /* corrupted PETSc object */ 50a8c6a408SBarry Smith #define PETSC_ERR_LIB 76 /* error in library called by PETSc */ 51329ffe3dSLois Curfman McInnes #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */ 52329ffe3dSLois Curfman McInnes #define PETSC_ERR_MEMC 78 /* memory corruption */ 5345d48df9SBarry Smith 5445d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */ 5545d48df9SBarry Smith #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */ 56a8c6a408SBarry Smith #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */ 5745d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */ 5845d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */ 594f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */ 604f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */ 616831982aSBarry Smith #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */ 62d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */ 63a8c6a408SBarry Smith #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ 644f227f7cSBarry Smith 654f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ 664f227f7cSBarry Smith #define PETSC_ERR_FILE_READ 66 /* unable to read from file */ 674f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */ 68a8c6a408SBarry Smith #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */ 6945d48df9SBarry Smith 70329ffe3dSLois Curfman McInnes #define PETSC_ERR_KSP_BRKDWN 70 /* break down in a Krylov method */ 714f227f7cSBarry Smith 72329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */ 73329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_CH_ZRPVT 71 /* detected a zero pivot during Cholesky factorization */ 7454a8ef01SBarry Smith 75aa482453SBarry Smith #if defined(PETSC_USE_DEBUG) 76c22c1629SBarry Smith #define SETERRA(n,p,s) {int _ierr = PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);\ 77fdb4a956SSatish Balay MPI_Abort(PETSC_COMM_WORLD,_ierr);} 78af91731eSBarry Smith #define SETERRA1(n,p,s,a1) {int _ierr = PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s,a1);\ 79af91731eSBarry Smith MPI_Abort(PETSC_COMM_WORLD,_ierr);} 809a00fa46SSatish Balay #define SETERRQ(n,p,s) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);} 819a00fa46SSatish Balay #define SETERRQ1(n,p,s,a1) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s,a1);} 829a00fa46SSatish Balay #define SETERRQ2(n,p,s,a1,a2) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s,a1,a2);} 839a00fa46SSatish Balay #define SETERRQ3(n,p,s,a1,a2,a3) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s,a1,a2,a3);} 849a00fa46SSatish Balay #define SETERRQ4(n,p,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s,a1,a2,a3,a4);} 859a00fa46SSatish Balay 86e3372554SBarry Smith #define CHKERRQ(n) {if (n) SETERRQ(n,0,(char *)0);} 87e3372554SBarry Smith #define CHKERRA(n) {if (n) SETERRA(n,0,(char *)0);} 88e3372554SBarry Smith #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,0,(char*)0); 89e3372554SBarry Smith #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,0,(char*)0); 9085614651SBarry Smith 9185614651SBarry Smith #define CHKMEMQ {int __ierr = PetscTrValid(__LINE__,__FUNC__,__FILE__,__SDIR__);CHKERRQ(__ierr);} 9285614651SBarry Smith #define CHKMEMA {int __ierr = PetscTrValid(__LINE__,__FUNC__,__FILE__,__SDIR__);CHKERRA(__ierr);} 9385614651SBarry Smith 94f1af5d2fSBarry Smith #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 95f1af5d2fSBarry Smith extern int __gierr; 96f1af5d2fSBarry Smith #define _ __gierr = 97f1af5d2fSBarry Smith #define ___ CHKERRA(__gierr); 98f1af5d2fSBarry Smith #define ____ CHKERRQ(__gierr); 99f1af5d2fSBarry Smith #endif 100f1af5d2fSBarry Smith 10154a8ef01SBarry Smith #else 10254bb357eSBarry Smith #define SETERRA(n,p,s) ; 10354bb357eSBarry Smith #define SETERRA1(n,p,s,b) ; 104e3372554SBarry Smith #define SETERRQ(n,p,s) ; 105cf949a74SBarry Smith #define SETERRQ1(n,p,s,a1) ; 106cf949a74SBarry Smith #define SETERRQ2(n,p,s,a1,a2) ; 107cf949a74SBarry Smith #define SETERRQ3(n,p,s,a1,a2,a3) ; 108cf949a74SBarry Smith #define SETERRQ4(n,p,s,a1,a2,a3,a4) ; 10985614651SBarry Smith 1104f227f7cSBarry Smith #define CHKERRQ(n) ; 1114f227f7cSBarry Smith #define CHKERRA(n) ; 1124f227f7cSBarry Smith #define CHKPTRQ(p) ; 1134f227f7cSBarry Smith #define CHKPTRA(p) ; 11485614651SBarry Smith 11585614651SBarry Smith #define CHKMEMQ ; 11685614651SBarry Smith #define CHKMEMA ; 11785614651SBarry Smith 118f1af5d2fSBarry Smith #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 119f1af5d2fSBarry Smith #define _ 120f1af5d2fSBarry Smith #define ___ 121f1af5d2fSBarry Smith #define ____ 122f1af5d2fSBarry Smith #endif 123f1af5d2fSBarry Smith 12454a8ef01SBarry Smith #endif 12554a8ef01SBarry Smith 126e3372554SBarry Smith extern int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*); 1272bad1931SBarry Smith extern int PetscEmacsClientErrorHandler(int,char*,char*,char*,int,int,char*,void*); 128e3372554SBarry Smith extern int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*); 129e3372554SBarry Smith extern int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void*); 130e3372554SBarry Smith extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*); 1319a00fa46SSatish Balay extern int PetscError(int,char*,char*,char*,int,int,char*,...); 132e3372554SBarry Smith extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*); 133cf256101SBarry Smith extern int PetscPopErrorHandler(void); 13454a8ef01SBarry Smith 13554a8ef01SBarry Smith extern int PetscDefaultSignalHandler(int,void*); 13654a8ef01SBarry Smith extern int PetscPushSignalHandler(int (*)(int,void *),void*); 137cf256101SBarry Smith extern int PetscPopSignalHandler(void); 138329f5518SBarry Smith 139329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 140329f5518SBarry Smith extern int PetscSetFPTrap(PetscFPTrap); 14154a8ef01SBarry Smith 1423a40ed3dSBarry Smith /* 1433a40ed3dSBarry Smith Allows the code to build a stack frame as it runs 1443a40ed3dSBarry Smith */ 145aa482453SBarry Smith #if defined(PETSC_USE_STACK) 1463a40ed3dSBarry Smith 147184914b5SBarry Smith #define PETSCSTACKSIZE 15 148184914b5SBarry Smith 1493a40ed3dSBarry Smith typedef struct { 150184914b5SBarry Smith char *function[PETSCSTACKSIZE]; 151184914b5SBarry Smith char *file[PETSCSTACKSIZE]; 152184914b5SBarry Smith char *directory[PETSCSTACKSIZE]; 153184914b5SBarry Smith int line[PETSCSTACKSIZE]; 154184914b5SBarry Smith int currentsize; 1553a40ed3dSBarry Smith } PetscStack; 1563a40ed3dSBarry Smith 1573a40ed3dSBarry Smith extern PetscStack *petscstack; 158184914b5SBarry Smith extern int PetscStackCopy(PetscStack*,PetscStack*); 159184914b5SBarry Smith extern int PetscStackPrint(PetscStack*,FILE* fp); 160184914b5SBarry Smith 161184914b5SBarry Smith #define PetscStackActive (petscstack != 0) 1623a40ed3dSBarry Smith 163aa482453SBarry Smith #if !defined(PETSC_HAVE_AMS) 1646d385327SIbrahima Ba 1653a40ed3dSBarry Smith #define PetscFunctionBegin \ 166beb17490SBarry Smith {\ 167184914b5SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 168184914b5SBarry Smith petscstack->function[petscstack->currentsize] = __FUNC__; \ 169184914b5SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 170184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = __SDIR__; \ 171184914b5SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 172184914b5SBarry Smith petscstack->currentsize++; \ 1733a40ed3dSBarry Smith }} 1743a40ed3dSBarry Smith 1755cd90555SBarry Smith #define PetscStackPush(n) \ 176184914b5SBarry Smith {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 177184914b5SBarry Smith petscstack->function[petscstack->currentsize] = n; \ 178184914b5SBarry Smith petscstack->file[petscstack->currentsize] = "unknown"; \ 179184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = "unknown"; \ 180184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 181184914b5SBarry Smith petscstack->currentsize++; \ 1825cd90555SBarry Smith }} 1833a40ed3dSBarry Smith 184d64ed03dSBarry Smith #define PetscStackPop \ 185184914b5SBarry Smith {if (petscstack && petscstack->currentsize > 0) { \ 186184914b5SBarry Smith petscstack->currentsize--; \ 187184914b5SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 188184914b5SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 189184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = 0; \ 190184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 1915cd90555SBarry Smith }}; 192d64ed03dSBarry Smith 1935cd90555SBarry Smith #define PetscFunctionReturn(a) \ 194beb17490SBarry Smith {\ 19506d1fe2cSBarry Smith PetscStackPop; \ 1965cd90555SBarry Smith return(a);} 197d64ed03dSBarry Smith 198*ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 199*ff94ddecSSatish Balay {\ 200*ff94ddecSSatish Balay PetscStackPop;} 201*ff94ddecSSatish Balay 2023a40ed3dSBarry Smith #else 2033a40ed3dSBarry Smith 20406d1fe2cSBarry Smith /* 20506d1fe2cSBarry Smith Duplicate Code for when the ALICE Memory Snooper (AMS) 206aa482453SBarry Smith is being used. When PETSC_HAVE_AMS is defined. 20706d1fe2cSBarry Smith 20806d1fe2cSBarry Smith stack_mem is the AMS memory that contains fields for the 20906d1fe2cSBarry Smith number of stack frames and names of the stack frames 21006d1fe2cSBarry Smith */ 21106d1fe2cSBarry Smith 2126d385327SIbrahima Ba extern AMS_Memory stack_mem; 21306d1fe2cSBarry Smith extern int stack_err; 2146d385327SIbrahima Ba 2156d385327SIbrahima Ba #define PetscFunctionBegin \ 216beb17490SBarry Smith {\ 217184914b5SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 21806d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 219184914b5SBarry Smith petscstack->function[petscstack->currentsize] = __FUNC__; \ 220184914b5SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 221184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = __SDIR__; \ 222184914b5SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 223184914b5SBarry Smith petscstack->currentsize++; \ 22406d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 2256d385327SIbrahima Ba }} 2266d385327SIbrahima Ba 2276d385327SIbrahima Ba #define PetscStackPush(n) \ 228184914b5SBarry Smith {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 22906d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 230184914b5SBarry Smith petscstack->function[petscstack->currentsize] = n; \ 231184914b5SBarry Smith petscstack->file[petscstack->currentsize] = "unknown"; \ 232184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = "unknown"; \ 233184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 234184914b5SBarry Smith petscstack->currentsize++; \ 23506d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 2366d385327SIbrahima Ba }} 2376d385327SIbrahima Ba 2386d385327SIbrahima Ba #define PetscStackPop \ 239184914b5SBarry Smith {if (petscstack && petscstack->currentsize > 0) { \ 24006d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 241184914b5SBarry Smith petscstack->currentsize--; \ 242184914b5SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 243184914b5SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 244184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = 0; \ 245184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 24606d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 2476d385327SIbrahima Ba }}; 2486d385327SIbrahima Ba 2496d385327SIbrahima Ba #define PetscFunctionReturn(a) \ 250beb17490SBarry Smith {\ 25106d1fe2cSBarry Smith PetscStackPop; \ 2526d385327SIbrahima Ba return(a);} 2536d385327SIbrahima Ba 254*ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 255*ff94ddecSSatish Balay {\ 256*ff94ddecSSatish Balay PetscStackPop;} 257*ff94ddecSSatish Balay 258*ff94ddecSSatish Balay 2596d385327SIbrahima Ba #endif 2606d385327SIbrahima Ba 2616d385327SIbrahima Ba #else 2626d385327SIbrahima Ba 2633a40ed3dSBarry Smith #define PetscFunctionBegin 2643a40ed3dSBarry Smith #define PetscFunctionReturn(a) return(a) 265d64ed03dSBarry Smith #define PetscStackPop 266d64ed03dSBarry Smith #define PetscStackPush(f) 267d64ed03dSBarry Smith #define PetscStackActive 0 2683a40ed3dSBarry Smith 2693a40ed3dSBarry Smith #endif 2703a40ed3dSBarry Smith 271184914b5SBarry Smith extern int PetscStackCreate(void); 2723a40ed3dSBarry Smith extern int PetscStackView(Viewer); 273cf256101SBarry Smith extern int PetscStackDestroy(void); 274f2b01315SBarry Smith extern int PetscStackPublish(void); 275f2b01315SBarry Smith extern int PetscStackDepublish(void); 2763a40ed3dSBarry Smith 27706d1fe2cSBarry Smith 27806d1fe2cSBarry Smith #endif 27906d1fe2cSBarry Smith 280329f5518SBarry Smith 281