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 #define SETERRABORT(comm,n,s) ; 100 101 #define CHKERRQ(n) ; 102 #define CHKERRABORT(comm,n) ; 103 #define CHKERRCONTINUE(n) ; 104 105 #define CHKMEMQ ; 106 107 #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR) 108 #define _ 109 #define ___ 110 #endif 111 112 #endif 113 114 EXTERN int PetscErrorMessage(int,char**,char **); 115 EXTERN int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*); 116 EXTERN int PetscIgnoreErrorHandler(int,char*,char*,char*,int,int,char*,void*); 117 EXTERN int PetscEmacsClientErrorHandler(int,char*,char*,char*,int,int,char*,void*); 118 EXTERN int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*); 119 EXTERN int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void*); 120 EXTERN int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*); 121 EXTERN int PetscError(int,char*,char*,char*,int,int,char*,...); 122 EXTERN int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*); 123 EXTERN int PetscPopErrorHandler(void); 124 EXTERN int PetscDefaultSignalHandler(int,void*); 125 EXTERN int PetscPushSignalHandler(int (*)(int,void *),void*); 126 EXTERN int PetscPopSignalHandler(void); 127 128 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 129 EXTERN int PetscSetFPTrap(PetscFPTrap); 130 131 /* 132 Allows the code to build a stack frame as it runs 133 */ 134 #if defined(PETSC_USE_STACK) 135 136 #define PETSCSTACKSIZE 15 137 138 typedef struct { 139 char *function[PETSCSTACKSIZE]; 140 char *file[PETSCSTACKSIZE]; 141 char *directory[PETSCSTACKSIZE]; 142 int line[PETSCSTACKSIZE]; 143 int currentsize; 144 } PetscStack; 145 146 extern PetscStack *petscstack; 147 EXTERN int PetscStackCopy(PetscStack*,PetscStack*); 148 EXTERN int PetscStackPrint(PetscStack*,FILE* fp); 149 150 #define PetscStackActive (petscstack != 0) 151 152 #if !defined(PETSC_HAVE_AMS) 153 154 #define PetscFunctionBegin \ 155 {\ 156 if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 157 petscstack->function[petscstack->currentsize] = __FUNCT__; \ 158 petscstack->file[petscstack->currentsize] = __FILE__; \ 159 petscstack->directory[petscstack->currentsize] = __SDIR__; \ 160 petscstack->line[petscstack->currentsize] = __LINE__; \ 161 petscstack->currentsize++; \ 162 }} 163 164 #define PetscStackPush(n) \ 165 {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 166 petscstack->function[petscstack->currentsize] = n; \ 167 petscstack->file[petscstack->currentsize] = "unknown"; \ 168 petscstack->directory[petscstack->currentsize] = "unknown"; \ 169 petscstack->line[petscstack->currentsize] = 0; \ 170 petscstack->currentsize++; \ 171 }} 172 173 #define PetscStackPop \ 174 {if (petscstack && petscstack->currentsize > 0) { \ 175 petscstack->currentsize--; \ 176 petscstack->function[petscstack->currentsize] = 0; \ 177 petscstack->file[petscstack->currentsize] = 0; \ 178 petscstack->directory[petscstack->currentsize] = 0; \ 179 petscstack->line[petscstack->currentsize] = 0; \ 180 }}; 181 182 #define PetscFunctionReturn(a) \ 183 {\ 184 PetscStackPop; \ 185 return(a);} 186 187 #define PetscFunctionReturnVoid() \ 188 {\ 189 PetscStackPop; \ 190 return;} 191 192 #else 193 194 /* 195 Duplicate Code for when the ALICE Memory Snooper (AMS) 196 is being used. When PETSC_HAVE_AMS is defined. 197 198 stack_mem is the AMS memory that contains fields for the 199 number of stack frames and names of the stack frames 200 */ 201 202 extern AMS_Memory stack_mem; 203 extern int stack_err; 204 205 #define PetscFunctionBegin \ 206 {\ 207 if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 208 if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 209 petscstack->function[petscstack->currentsize] = __FUNCT__; \ 210 petscstack->file[petscstack->currentsize] = __FILE__; \ 211 petscstack->directory[petscstack->currentsize] = __SDIR__; \ 212 petscstack->line[petscstack->currentsize] = __LINE__; \ 213 petscstack->currentsize++; \ 214 if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 215 }} 216 217 #define PetscStackPush(n) \ 218 {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 219 if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 220 petscstack->function[petscstack->currentsize] = n; \ 221 petscstack->file[petscstack->currentsize] = "unknown"; \ 222 petscstack->directory[petscstack->currentsize] = "unknown"; \ 223 petscstack->line[petscstack->currentsize] = 0; \ 224 petscstack->currentsize++; \ 225 if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 226 }} 227 228 #define PetscStackPop \ 229 {if (petscstack && petscstack->currentsize > 0) { \ 230 if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 231 petscstack->currentsize--; \ 232 petscstack->function[petscstack->currentsize] = 0; \ 233 petscstack->file[petscstack->currentsize] = 0; \ 234 petscstack->directory[petscstack->currentsize] = 0; \ 235 petscstack->line[petscstack->currentsize] = 0; \ 236 if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 237 }}; 238 239 #define PetscFunctionReturn(a) \ 240 {\ 241 PetscStackPop; \ 242 return(a);} 243 244 #define PetscFunctionReturnVoid() \ 245 {\ 246 PetscStackPop; \ 247 return;} 248 249 250 #endif 251 252 #else 253 254 #define PetscFunctionBegin 255 #define PetscFunctionReturn(a) return(a) 256 #define PetscFunctionReturnVoid() return() 257 #define PetscStackPop 258 #define PetscStackPush(f) 259 #define PetscStackActive 0 260 261 #endif 262 263 EXTERN int PetscStackCreate(void); 264 EXTERN int PetscStackView(PetscViewer); 265 EXTERN int PetscStackDestroy(void); 266 EXTERN int PetscStackPublish(void); 267 EXTERN int PetscStackDepublish(void); 268 269 270 #endif 271 272 273