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) 754a2ae208SSatish Balay #define SETERRQ(n,s) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);} 764a2ae208SSatish Balay #define SETERRQ1(n,s,a1) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1);} 774a2ae208SSatish Balay #define SETERRQ2(n,s,a1,a2) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2);} 784a2ae208SSatish Balay #define SETERRQ3(n,s,a1,a2,a3) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3);} 794a2ae208SSatish Balay #define SETERRQ4(n,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4);} 80a30c184eSMatthew Knepley #define SETERRQ5(n,s,a1,a2,a3,a4,a5) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5);} 81a30c184eSMatthew 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);} 82a30c184eSMatthew 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);} 83*e855a17bSBarry Smith #define SETERRABORT(comm,n,s) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);MPI_Abort(comm,n);} 849a00fa46SSatish Balay 85c3be3f59SMatthew Knepley #define CHKERRQ(n) if (n) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");} 8694a56cdfSMatthew Knepley #define CHKERRABORT(comm,n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");MPI_Abort(comm,n);} 8794a56cdfSMatthew Knepley #define CHKERRCONTINUE(n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");} 8885614651SBarry Smith 89ef66eb69SBarry Smith #define CHKMEMQ {int _7_ierr = PetscTrValid(__LINE__,__FUNCT__,__FILE__,__SDIR__);CHKERRQ(_7_ierr);} 9085614651SBarry Smith 91f1af5d2fSBarry Smith #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 92f1af5d2fSBarry Smith extern int __gierr; 93f1af5d2fSBarry Smith #define _ __gierr = 94ac355199SBarry Smith #define ___ CHKERRQ(__gierr); 95f1af5d2fSBarry Smith #endif 96f1af5d2fSBarry Smith 9754a8ef01SBarry Smith #else 9890d37a7cSBarry Smith #define SETERRQ(n,s) ; 9990d37a7cSBarry Smith #define SETERRQ1(n,s,a1) ; 10090d37a7cSBarry Smith #define SETERRQ2(n,s,a1,a2) ; 10190d37a7cSBarry Smith #define SETERRQ3(n,s,a1,a2,a3) ; 10290d37a7cSBarry Smith #define SETERRQ4(n,s,a1,a2,a3,a4) ; 1031ee4faa0SMatthew Knepley #define SETERRABORT(comm,n,s) ; 10485614651SBarry Smith 1054f227f7cSBarry Smith #define CHKERRQ(n) ; 1061ee4faa0SMatthew Knepley #define CHKERRABORT(comm,n) ; 1071ee4faa0SMatthew Knepley #define CHKERRCONTINUE(n) ; 10885614651SBarry Smith 10985614651SBarry Smith #define CHKMEMQ ; 11085614651SBarry Smith 111f1af5d2fSBarry Smith #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 112f1af5d2fSBarry Smith #define _ 113f1af5d2fSBarry Smith #define ___ 114f1af5d2fSBarry Smith #endif 115f1af5d2fSBarry Smith 11654a8ef01SBarry Smith #endif 11754a8ef01SBarry Smith 1184916b209SBarry Smith EXTERN int PetscErrorMessage(int,char**,char **); 119ca44d042SBarry Smith EXTERN int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*); 1203a7fca6bSBarry Smith EXTERN int PetscIgnoreErrorHandler(int,char*,char*,char*,int,int,char*,void*); 121ca44d042SBarry Smith EXTERN int PetscEmacsClientErrorHandler(int,char*,char*,char*,int,int,char*,void*); 122ca44d042SBarry Smith EXTERN int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*); 123ca44d042SBarry Smith EXTERN int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void*); 124ca44d042SBarry Smith EXTERN int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*); 125f80b7eb0SBarry Smith EXTERN int PetscError(int,char*,char*,char*,int,int,char*,...) PETSC_PRINTF_FORMAT_CHECK(7,8); 126ca44d042SBarry Smith EXTERN int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*); 127ca44d042SBarry Smith EXTERN int PetscPopErrorHandler(void); 128ca44d042SBarry Smith EXTERN int PetscDefaultSignalHandler(int,void*); 129ca44d042SBarry Smith EXTERN int PetscPushSignalHandler(int (*)(int,void *),void*); 130ca44d042SBarry Smith EXTERN int PetscPopSignalHandler(void); 131329f5518SBarry Smith 132329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 133ca44d042SBarry Smith EXTERN int PetscSetFPTrap(PetscFPTrap); 13454a8ef01SBarry Smith 1353a40ed3dSBarry Smith /* 1363a40ed3dSBarry Smith Allows the code to build a stack frame as it runs 1373a40ed3dSBarry Smith */ 138aa482453SBarry Smith #if defined(PETSC_USE_STACK) 1393a40ed3dSBarry Smith 140184914b5SBarry Smith #define PETSCSTACKSIZE 15 141184914b5SBarry Smith 1423a40ed3dSBarry Smith typedef struct { 143184914b5SBarry Smith char *function[PETSCSTACKSIZE]; 144184914b5SBarry Smith char *file[PETSCSTACKSIZE]; 145184914b5SBarry Smith char *directory[PETSCSTACKSIZE]; 146184914b5SBarry Smith int line[PETSCSTACKSIZE]; 147184914b5SBarry Smith int currentsize; 1483a40ed3dSBarry Smith } PetscStack; 1493a40ed3dSBarry Smith 1503a40ed3dSBarry Smith extern PetscStack *petscstack; 151ca44d042SBarry Smith EXTERN int PetscStackCopy(PetscStack*,PetscStack*); 152ca44d042SBarry Smith EXTERN int PetscStackPrint(PetscStack*,FILE* fp); 153184914b5SBarry Smith 154184914b5SBarry Smith #define PetscStackActive (petscstack != 0) 1553a40ed3dSBarry Smith 156aa482453SBarry Smith #if !defined(PETSC_HAVE_AMS) 1576d385327SIbrahima Ba 1583a40ed3dSBarry Smith #define PetscFunctionBegin \ 159beb17490SBarry Smith {\ 160184914b5SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 1614a2ae208SSatish Balay petscstack->function[petscstack->currentsize] = __FUNCT__; \ 162184914b5SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 163184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = __SDIR__; \ 164184914b5SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 165184914b5SBarry Smith petscstack->currentsize++; \ 1663a40ed3dSBarry Smith }} 1673a40ed3dSBarry Smith 1685cd90555SBarry Smith #define PetscStackPush(n) \ 169184914b5SBarry Smith {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 170184914b5SBarry Smith petscstack->function[petscstack->currentsize] = n; \ 171184914b5SBarry Smith petscstack->file[petscstack->currentsize] = "unknown"; \ 172184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = "unknown"; \ 173184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 174184914b5SBarry Smith petscstack->currentsize++; \ 1755cd90555SBarry Smith }} 1763a40ed3dSBarry Smith 177d64ed03dSBarry Smith #define PetscStackPop \ 178184914b5SBarry Smith {if (petscstack && petscstack->currentsize > 0) { \ 179184914b5SBarry Smith petscstack->currentsize--; \ 180184914b5SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 181184914b5SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 182184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = 0; \ 183184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 1845cd90555SBarry Smith }}; 185d64ed03dSBarry Smith 1865cd90555SBarry Smith #define PetscFunctionReturn(a) \ 187beb17490SBarry Smith {\ 18806d1fe2cSBarry Smith PetscStackPop; \ 1895cd90555SBarry Smith return(a);} 190d64ed03dSBarry Smith 191ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 192ff94ddecSSatish Balay {\ 1931fceb228SKris Buschelman PetscStackPop; \ 1941fceb228SKris Buschelman return;} 195ff94ddecSSatish Balay 1963a40ed3dSBarry Smith #else 1973a40ed3dSBarry Smith 19806d1fe2cSBarry Smith /* 19906d1fe2cSBarry Smith Duplicate Code for when the ALICE Memory Snooper (AMS) 200aa482453SBarry Smith is being used. When PETSC_HAVE_AMS is defined. 20106d1fe2cSBarry Smith 20206d1fe2cSBarry Smith stack_mem is the AMS memory that contains fields for the 20306d1fe2cSBarry Smith number of stack frames and names of the stack frames 20406d1fe2cSBarry Smith */ 20506d1fe2cSBarry Smith 2066d385327SIbrahima Ba extern AMS_Memory stack_mem; 20706d1fe2cSBarry Smith extern int stack_err; 2086d385327SIbrahima Ba 2096d385327SIbrahima Ba #define PetscFunctionBegin \ 210beb17490SBarry Smith {\ 211184914b5SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 21206d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 2134a2ae208SSatish Balay petscstack->function[petscstack->currentsize] = __FUNCT__; \ 214184914b5SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 215184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = __SDIR__; \ 216184914b5SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 217184914b5SBarry Smith petscstack->currentsize++; \ 21806d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 2196d385327SIbrahima Ba }} 2206d385327SIbrahima Ba 2216d385327SIbrahima Ba #define PetscStackPush(n) \ 222184914b5SBarry Smith {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 22306d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 224184914b5SBarry Smith petscstack->function[petscstack->currentsize] = n; \ 225184914b5SBarry Smith petscstack->file[petscstack->currentsize] = "unknown"; \ 226184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = "unknown"; \ 227184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 228184914b5SBarry Smith petscstack->currentsize++; \ 22906d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 2306d385327SIbrahima Ba }} 2316d385327SIbrahima Ba 2326d385327SIbrahima Ba #define PetscStackPop \ 233184914b5SBarry Smith {if (petscstack && petscstack->currentsize > 0) { \ 23406d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 235184914b5SBarry Smith petscstack->currentsize--; \ 236184914b5SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 237184914b5SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 238184914b5SBarry Smith petscstack->directory[petscstack->currentsize] = 0; \ 239184914b5SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 24006d1fe2cSBarry Smith if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 2416d385327SIbrahima Ba }}; 2426d385327SIbrahima Ba 2436d385327SIbrahima Ba #define PetscFunctionReturn(a) \ 244beb17490SBarry Smith {\ 24506d1fe2cSBarry Smith PetscStackPop; \ 2466d385327SIbrahima Ba return(a);} 2476d385327SIbrahima Ba 248ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 249ff94ddecSSatish Balay {\ 2501fceb228SKris Buschelman PetscStackPop; \ 2511fceb228SKris Buschelman return;} 252ff94ddecSSatish Balay 253ff94ddecSSatish Balay 2546d385327SIbrahima Ba #endif 2556d385327SIbrahima Ba 2566d385327SIbrahima Ba #else 2576d385327SIbrahima Ba 2583a40ed3dSBarry Smith #define PetscFunctionBegin 2593a40ed3dSBarry Smith #define PetscFunctionReturn(a) return(a) 2601fceb228SKris Buschelman #define PetscFunctionReturnVoid() return() 261d64ed03dSBarry Smith #define PetscStackPop 262d64ed03dSBarry Smith #define PetscStackPush(f) 263d64ed03dSBarry Smith #define PetscStackActive 0 2643a40ed3dSBarry Smith 2653a40ed3dSBarry Smith #endif 2663a40ed3dSBarry Smith 267ca44d042SBarry Smith EXTERN int PetscStackCreate(void); 268b0a32e0cSBarry Smith EXTERN int PetscStackView(PetscViewer); 269ca44d042SBarry Smith EXTERN int PetscStackDestroy(void); 270ca44d042SBarry Smith EXTERN int PetscStackPublish(void); 271ca44d042SBarry Smith EXTERN int PetscStackDepublish(void); 2723a40ed3dSBarry Smith 27306d1fe2cSBarry Smith 27406d1fe2cSBarry Smith #endif 27506d1fe2cSBarry Smith 276329f5518SBarry Smith 277