1 /* $Id: petscerror.h,v 1.36 1999/07/15 17:43:50 bsmith Exp bsmith $ */ 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 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(__FUNC__) 30 #define __FUNC__ "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 In addition, each specific error in the code has an error 38 message: a specific, unique error code. (The specific error 39 code is not yet in use; these will be generated automatically and 40 embed an integer into the PetscError() calls. For non-English 41 error messages, that integer will be extracted and used to look up the 42 appropriate error message in the local language from a file.) 43 44 */ 45 #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 46 #define PETSC_ERR_SUP 56 /* no support for requested operation */ 47 #define PETSC_ERR_SIG 59 /* signal received */ 48 #define PETSC_ERR_FP 72 /* floating point exception */ 49 #define PETSC_ERR_COR 74 /* corrupted PETSc object */ 50 #define PETSC_ERR_LIB 76 /* error in library called by PETSc */ 51 #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */ 52 #define PETSC_ERR_MEMC 78 /* memory corruption */ 53 54 #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */ 55 #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */ 56 #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */ 57 #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */ 58 #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */ 59 #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */ 60 #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */ 61 #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */ 62 #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ 63 64 #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ 65 #define PETSC_ERR_FILE_READ 66 /* unable to read from file */ 66 #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */ 67 #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */ 68 69 #define PETSC_ERR_KSP_BRKDWN 70 /* break down in a Krylov method */ 70 71 #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */ 72 #define PETSC_ERR_MAT_CH_ZRPVT 71 /* detected a zero pivot during Cholesky factorization */ 73 74 #if defined(PETSC_USE_DEBUG) 75 #define SETERRA(n,p,s) {int _ierr = PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);\ 76 MPI_Abort(PETSC_COMM_WORLD,_ierr);} 77 #define SETERRQ(n,p,s) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);} 78 #define SETERRQ1(n,p,s,a1) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s,a1);} 79 #define SETERRQ2(n,p,s,a1,a2) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s,a1,a2);} 80 #define SETERRQ3(n,p,s,a1,a2,a3) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s,a1,a2,a3);} 81 #define SETERRQ4(n,p,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s,a1,a2,a3,a4);} 82 83 #define CHKERRQ(n) {if (n) SETERRQ(n,0,(char *)0);} 84 #define CHKERRA(n) {if (n) SETERRA(n,0,(char *)0);} 85 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,0,(char*)0); 86 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,0,(char*)0); 87 88 #define CHKMEMQ {int __ierr = PetscTrValid(__LINE__,__FUNC__,__FILE__,__SDIR__); CHKERRQ(__ierr);} 89 #define CHKMEMA {int __ierr = PetscTrValid(__LINE__,__FUNC__,__FILE__,__SDIR__); CHKERRA(__ierr);} 90 91 #else 92 #define SETERRQ(n,p,s) ; 93 #define SETERRQ1(n,p,s,a1) ; 94 #define SETERRQ2(n,p,s,a1,a2) ; 95 #define SETERRQ3(n,p,s,a1,a2,a3) ; 96 #define SETERRQ4(n,p,s,a1,a2,a3,a4) ; 97 #define SETERRA(n,p,s) ; 98 99 #define CHKERRQ(n) ; 100 #define CHKERRA(n) ; 101 #define CHKPTRQ(p) ; 102 #define CHKPTRA(p) ; 103 104 #define CHKMEMQ ; 105 #define CHKMEMA ; 106 107 #endif 108 109 extern int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*); 110 extern int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*); 111 extern int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void* ); 112 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*); 113 extern int PetscError(int,char*,char*,char*,int,int,char*,...); 114 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*); 115 extern int PetscPopErrorHandler(void); 116 117 extern int PetscDefaultSignalHandler(int,void*); 118 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 119 extern int PetscPopSignalHandler(void); 120 #define PETSC_FP_TRAP_OFF 0 121 #define PETSC_FP_TRAP_ON 1 122 extern int PetscSetFPTrap(int); 123 extern int PetscInitializeNans(Scalar*,int); 124 extern int PetscInitializeLargeInts(int *,int); 125 126 /* 127 Allows the code to build a stack frame as it runs 128 */ 129 #if defined(PETSC_USE_STACK) 130 131 #define PETSCSTACKSIZE 15 132 133 typedef struct { 134 char *function[PETSCSTACKSIZE]; 135 char *file[PETSCSTACKSIZE]; 136 char *directory[PETSCSTACKSIZE]; 137 int line[PETSCSTACKSIZE]; 138 int currentsize; 139 } PetscStack; 140 141 extern PetscStack *petscstack; 142 extern int PetscStackCopy(PetscStack*,PetscStack*); 143 extern int PetscStackPrint(PetscStack*,FILE* fp); 144 145 #define PetscStackActive (petscstack != 0) 146 147 #if !defined(PETSC_HAVE_AMS) 148 149 #define PetscFunctionBegin \ 150 {\ 151 if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 152 petscstack->function[petscstack->currentsize] = __FUNC__; \ 153 petscstack->file[petscstack->currentsize] = __FILE__; \ 154 petscstack->directory[petscstack->currentsize] = __SDIR__; \ 155 petscstack->line[petscstack->currentsize] = __LINE__; \ 156 petscstack->currentsize++; \ 157 }} 158 159 #define PetscStackPush(n) \ 160 {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 161 petscstack->function[petscstack->currentsize] = n; \ 162 petscstack->file[petscstack->currentsize] = "unknown"; \ 163 petscstack->directory[petscstack->currentsize] = "unknown"; \ 164 petscstack->line[petscstack->currentsize] = 0; \ 165 petscstack->currentsize++; \ 166 }} 167 168 #define PetscStackPop \ 169 {if (petscstack && petscstack->currentsize > 0) { \ 170 petscstack->currentsize--; \ 171 petscstack->function[petscstack->currentsize] = 0; \ 172 petscstack->file[petscstack->currentsize] = 0; \ 173 petscstack->directory[petscstack->currentsize] = 0; \ 174 petscstack->line[petscstack->currentsize] = 0; \ 175 }}; 176 177 #define PetscFunctionReturn(a) \ 178 {\ 179 PetscStackPop; \ 180 return(a);} 181 182 #else 183 184 /* 185 Duplicate Code for when the ALICE Memory Snooper (AMS) 186 is being used. When PETSC_HAVE_AMS is defined. 187 188 stack_mem is the AMS memory that contains fields for the 189 number of stack frames and names of the stack frames 190 */ 191 192 extern AMS_Memory stack_mem; 193 extern int stack_err; 194 195 #define PetscFunctionBegin \ 196 {\ 197 if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 198 if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 199 petscstack->function[petscstack->currentsize] = __FUNC__; \ 200 petscstack->file[petscstack->currentsize] = __FILE__; \ 201 petscstack->directory[petscstack->currentsize] = __SDIR__; \ 202 petscstack->line[petscstack->currentsize] = __LINE__; \ 203 petscstack->currentsize++; \ 204 if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 205 }} 206 207 #define PetscStackPush(n) \ 208 {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 209 if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 210 petscstack->function[petscstack->currentsize] = n; \ 211 petscstack->file[petscstack->currentsize] = "unknown"; \ 212 petscstack->directory[petscstack->currentsize] = "unknown"; \ 213 petscstack->line[petscstack->currentsize] = 0; \ 214 petscstack->currentsize++; \ 215 if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 216 }} 217 218 #define PetscStackPop \ 219 {if (petscstack && petscstack->currentsize > 0) { \ 220 if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 221 petscstack->currentsize--; \ 222 petscstack->function[petscstack->currentsize] = 0; \ 223 petscstack->file[petscstack->currentsize] = 0; \ 224 petscstack->directory[petscstack->currentsize] = 0; \ 225 petscstack->line[petscstack->currentsize] = 0; \ 226 if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 227 }}; 228 229 #define PetscFunctionReturn(a) \ 230 {\ 231 PetscStackPop; \ 232 return(a);} 233 234 #endif 235 236 #else 237 238 #define PetscFunctionBegin 239 #define PetscFunctionReturn(a) return(a) 240 #define PetscStackPop 241 #define PetscStackPush(f) 242 #define PetscStackActive 0 243 244 #endif 245 246 extern int PetscStackCreate(void); 247 extern int PetscStackView(Viewer); 248 extern int PetscStackDestroy(void); 249 extern int PetscStackPublish(void); 250 extern int PetscStackDepublish(void); 251 252 /* 253 For locking, unlocking and destroying AMS memories associated with 254 PETSc objects 255 */ 256 257 #if defined(PETSC_HAVE_AMS) 258 #define PetscAMSTakeAccess(obj) \ 259 ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_take_access(((PetscObject)(obj))->amem)) 260 #define PetscAMSGrantAccess(obj) \ 261 ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_grant_access(((PetscObject)(obj))->amem)) 262 #define PetscAMSDestroy(obj) \ 263 ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_destroy(((PetscObject)(obj))->amem)); \ 264 ((PetscObject)(obj))->amem = -1; 265 #else 266 #define PetscAMSTakeAccess(obj) 0 267 #define PetscAMSGrantAccess(obj) 0 268 #define PetscAMSDestroy(obj) 0 269 #endif 270 271 #endif 272 273