1 /* $Id: petscerror.h,v 1.59 2001/09/07 20:13:16 bsmith Exp $ */ 2 /* 3 Contains all error handling code for PETSc. 4 */ 5 #if !defined(__PETSCERROR_H) 6 #define __PETSCERROR_H 7 8 #include "petsc.h" 9 10 #if defined(PETSC_HAVE_AMS) 11 #include "ams.h" 12 #endif 13 14 /* 15 Defines the directory where the compiled source is located; used 16 in printing error messages. Each makefile has an entry 17 LOCDIR = thedirectory 18 and bmake/common_variables includes in CCPPFLAGS -D__SDIR__='"${LOCDIR}"' 19 which is a flag passed to the C/C++ compilers. 20 */ 21 #if !defined(__SDIR__) 22 #define __SDIR__ "unknowndirectory/" 23 #endif 24 25 /* 26 Defines the function where the compiled source is located; used 27 in printing error messages. 28 */ 29 #if !defined(__FUNCT__) 30 #define __FUNCT__ "unknownfunction" 31 #endif 32 33 /* 34 These are the generic error codes. These error codes are used 35 many different places in the PETSc source code. 36 37 */ 38 #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 39 #define PETSC_ERR_SUP 56 /* no support for requested operation */ 40 #define PETSC_ERR_SIG 59 /* signal received */ 41 #define PETSC_ERR_FP 72 /* floating point exception */ 42 #define PETSC_ERR_COR 74 /* corrupted PETSc object */ 43 #define PETSC_ERR_LIB 76 /* error in library called by PETSc */ 44 #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */ 45 #define PETSC_ERR_MEMC 78 /* memory corruption */ 46 #define PETSC_ERR_MAX_ITER 82 /* Maximum iterations reached */ 47 48 #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */ 49 #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */ 50 #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */ 51 #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */ 52 #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */ 53 #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */ 54 #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */ 55 #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */ 56 #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */ 57 #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ 58 59 #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ 60 #define PETSC_ERR_FILE_READ 66 /* unable to read from file */ 61 #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */ 62 #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */ 63 64 #define PETSC_ERR_KSP_BRKDWN 70 /* break down in a Krylov method */ 65 66 #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */ 67 #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */ 68 69 #define PETSC_ERR_MESH_NULL_ELEM 84 /* Element had no interior */ 70 71 #define PETSC_ERR_DISC_SING_JAC 83 /* Singular element Jacobian */ 72 73 #if defined(PETSC_USE_DEBUG) 74 #define SETERRQ(n,s) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);} 75 #define SETERRQ1(n,s,a1) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1);} 76 #define SETERRQ2(n,s,a1,a2) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2);} 77 #define SETERRQ3(n,s,a1,a2,a3) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3);} 78 #define SETERRQ4(n,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4);} 79 #define SETERRABORT(comm,n,s) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);MPI_Abort(com,n);} 80 81 #define CHKERRQ(n) if (n) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0,0);} 82 #define CHKERRABORT(comm,n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0,0);MPI_Abort(comm,n);} 83 #define CHKERRCONTINUE(n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0,0);} 84 85 #define CHKMEMQ {int _7_ierr = PetscTrValid(__LINE__,__FUNCT__,__FILE__,__SDIR__);CHKERRQ(_7_ierr);} 86 87 #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 88 extern int __gierr; 89 #define _ __gierr = 90 #define ___ CHKERRQ(__gierr); 91 #endif 92 93 #else 94 #define SETERRQ(n,s) ; 95 #define SETERRQ1(n,s,a1) ; 96 #define SETERRQ2(n,s,a1,a2) ; 97 #define SETERRQ3(n,s,a1,a2,a3) ; 98 #define SETERRQ4(n,s,a1,a2,a3,a4) ; 99 100 #define CHKERRQ(n) ; 101 102 #define CHKMEMQ ; 103 104 #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 105 #define _ 106 #define ___ 107 #endif 108 109 #endif 110 111 EXTERN int PetscErrorMessage(int,char**,char **); 112 EXTERN int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*); 113 EXTERN int PetscIgnoreErrorHandler(int,char*,char*,char*,int,int,char*,void*); 114 EXTERN int PetscEmacsClientErrorHandler(int,char*,char*,char*,int,int,char*,void*); 115 EXTERN int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*); 116 EXTERN int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void*); 117 EXTERN int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*); 118 EXTERN int PetscError(int,char*,char*,char*,int,int,char*,...); 119 EXTERN int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*); 120 EXTERN int PetscPopErrorHandler(void); 121 EXTERN int PetscDefaultSignalHandler(int,void*); 122 EXTERN int PetscPushSignalHandler(int (*)(int,void *),void*); 123 EXTERN int PetscPopSignalHandler(void); 124 125 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 126 EXTERN int PetscSetFPTrap(PetscFPTrap); 127 128 /* 129 Allows the code to build a stack frame as it runs 130 */ 131 #if defined(PETSC_USE_STACK) 132 133 #define PETSCSTACKSIZE 15 134 135 typedef struct { 136 char *function[PETSCSTACKSIZE]; 137 char *file[PETSCSTACKSIZE]; 138 char *directory[PETSCSTACKSIZE]; 139 int line[PETSCSTACKSIZE]; 140 int currentsize; 141 } PetscStack; 142 143 extern PetscStack *petscstack; 144 EXTERN int PetscStackCopy(PetscStack*,PetscStack*); 145 EXTERN int PetscStackPrint(PetscStack*,FILE* fp); 146 147 #define PetscStackActive (petscstack != 0) 148 149 #if !defined(PETSC_HAVE_AMS) 150 151 #define PetscFunctionBegin \ 152 {\ 153 if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 154 petscstack->function[petscstack->currentsize] = __FUNCT__; \ 155 petscstack->file[petscstack->currentsize] = __FILE__; \ 156 petscstack->directory[petscstack->currentsize] = __SDIR__; \ 157 petscstack->line[petscstack->currentsize] = __LINE__; \ 158 petscstack->currentsize++; \ 159 }} 160 161 #define PetscStackPush(n) \ 162 {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 163 petscstack->function[petscstack->currentsize] = n; \ 164 petscstack->file[petscstack->currentsize] = "unknown"; \ 165 petscstack->directory[petscstack->currentsize] = "unknown"; \ 166 petscstack->line[petscstack->currentsize] = 0; \ 167 petscstack->currentsize++; \ 168 }} 169 170 #define PetscStackPop \ 171 {if (petscstack && petscstack->currentsize > 0) { \ 172 petscstack->currentsize--; \ 173 petscstack->function[petscstack->currentsize] = 0; \ 174 petscstack->file[petscstack->currentsize] = 0; \ 175 petscstack->directory[petscstack->currentsize] = 0; \ 176 petscstack->line[petscstack->currentsize] = 0; \ 177 }}; 178 179 #define PetscFunctionReturn(a) \ 180 {\ 181 PetscStackPop; \ 182 return(a);} 183 184 #define PetscFunctionReturnVoid() \ 185 {\ 186 PetscStackPop; \ 187 return;} 188 189 #else 190 191 /* 192 Duplicate Code for when the ALICE Memory Snooper (AMS) 193 is being used. When PETSC_HAVE_AMS is defined. 194 195 stack_mem is the AMS memory that contains fields for the 196 number of stack frames and names of the stack frames 197 */ 198 199 extern AMS_Memory stack_mem; 200 extern int stack_err; 201 202 #define PetscFunctionBegin \ 203 {\ 204 if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 205 if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 206 petscstack->function[petscstack->currentsize] = __FUNCT__; \ 207 petscstack->file[petscstack->currentsize] = __FILE__; \ 208 petscstack->directory[petscstack->currentsize] = __SDIR__; \ 209 petscstack->line[petscstack->currentsize] = __LINE__; \ 210 petscstack->currentsize++; \ 211 if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 212 }} 213 214 #define PetscStackPush(n) \ 215 {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 216 if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 217 petscstack->function[petscstack->currentsize] = n; \ 218 petscstack->file[petscstack->currentsize] = "unknown"; \ 219 petscstack->directory[petscstack->currentsize] = "unknown"; \ 220 petscstack->line[petscstack->currentsize] = 0; \ 221 petscstack->currentsize++; \ 222 if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 223 }} 224 225 #define PetscStackPop \ 226 {if (petscstack && petscstack->currentsize > 0) { \ 227 if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 228 petscstack->currentsize--; \ 229 petscstack->function[petscstack->currentsize] = 0; \ 230 petscstack->file[petscstack->currentsize] = 0; \ 231 petscstack->directory[petscstack->currentsize] = 0; \ 232 petscstack->line[petscstack->currentsize] = 0; \ 233 if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 234 }}; 235 236 #define PetscFunctionReturn(a) \ 237 {\ 238 PetscStackPop; \ 239 return(a);} 240 241 #define PetscFunctionReturnVoid() \ 242 {\ 243 PetscStackPop; \ 244 return;} 245 246 247 #endif 248 249 #else 250 251 #define PetscFunctionBegin 252 #define PetscFunctionReturn(a) return(a) 253 #define PetscFunctionReturnVoid() return() 254 #define PetscStackPop 255 #define PetscStackPush(f) 256 #define PetscStackActive 0 257 258 #endif 259 260 EXTERN int PetscStackCreate(void); 261 EXTERN int PetscStackView(PetscViewer); 262 EXTERN int PetscStackDestroy(void); 263 EXTERN int PetscStackPublish(void); 264 EXTERN int PetscStackDepublish(void); 265 266 267 #endif 268 269 270