1 /* $Id: petscerror.h,v 1.35 1999/07/10 21:16:17 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 typedef struct { 132 char **function; 133 char **file; 134 char **directory; 135 int *line; 136 } PetscStack; 137 138 extern int petscstacksize_max; 139 extern int petscstacksize; 140 extern PetscStack *petscstack; 141 142 #if !defined(PETSC_HAVE_AMS) 143 144 #define PetscFunctionBegin \ 145 {\ 146 if (petscstack && (petscstacksize < petscstacksize_max)) { \ 147 petscstack->function[petscstacksize] = __FUNC__; \ 148 petscstack->file[petscstacksize] = __FILE__; \ 149 petscstack->directory[petscstacksize] = __SDIR__; \ 150 petscstack->line[petscstacksize] = __LINE__; \ 151 petscstacksize++; \ 152 }} 153 154 #define PetscStackPush(n) \ 155 {if (petscstack && (petscstacksize < petscstacksize_max)) { \ 156 petscstack->function[petscstacksize] = n; \ 157 petscstack->file[petscstacksize] = "unknown"; \ 158 petscstack->directory[petscstacksize] = "unknown"; \ 159 petscstack->line[petscstacksize] = 0; \ 160 petscstacksize++; \ 161 }} 162 163 #define PetscStackPop \ 164 {if (petscstack && petscstacksize > 0) { \ 165 petscstacksize--; \ 166 petscstack->function[petscstacksize] = 0; \ 167 petscstack->file[petscstacksize] = 0; \ 168 petscstack->directory[petscstacksize] = 0; \ 169 petscstack->line[petscstacksize] = 0; \ 170 }}; 171 172 #define PetscFunctionReturn(a) \ 173 {\ 174 PetscStackPop; \ 175 return(a);} 176 177 #define PetscStackActive (petscstack != 0) 178 179 #else 180 181 /* 182 Duplicate Code for when the ALICE Memory Snooper (AMS) 183 is being used. When PETSC_HAVE_AMS is defined. 184 185 stack_mem is the AMS memory that contains fields for the 186 number of stack frames and names of the stack frames 187 */ 188 189 extern AMS_Memory stack_mem; 190 extern int stack_err; 191 192 #define PetscFunctionBegin \ 193 {\ 194 if (petscstack && (petscstacksize < petscstacksize_max)) { \ 195 if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 196 petscstack->function[petscstacksize] = __FUNC__; \ 197 petscstack->file[petscstacksize] = __FILE__; \ 198 petscstack->directory[petscstacksize] = __SDIR__; \ 199 petscstack->line[petscstacksize] = __LINE__; \ 200 petscstacksize++; \ 201 if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 202 }} 203 204 #define PetscStackPush(n) \ 205 {if (petscstack && (petscstacksize < petscstacksize_max)) { \ 206 if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 207 petscstack->function[petscstacksize] = n; \ 208 petscstack->file[petscstacksize] = "unknown"; \ 209 petscstack->directory[petscstacksize] = "unknown"; \ 210 petscstack->line[petscstacksize] = 0; \ 211 petscstacksize++; \ 212 if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 213 }} 214 215 #define PetscStackPop \ 216 {if (petscstack && petscstacksize > 0) { \ 217 if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\ 218 petscstacksize--; \ 219 petscstack->function[petscstacksize] = 0; \ 220 petscstack->file[petscstacksize] = 0; \ 221 petscstack->directory[petscstacksize] = 0; \ 222 petscstack->line[petscstacksize] = 0; \ 223 if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\ 224 }}; 225 226 #define PetscFunctionReturn(a) \ 227 {\ 228 PetscStackPop; \ 229 return(a);} 230 231 #define PetscStackActive (petscstack != 0) 232 233 #endif 234 235 #else 236 237 #define PetscFunctionBegin 238 #define PetscFunctionReturn(a) return(a) 239 #define PetscStackPop 240 #define PetscStackPush(f) 241 #define PetscStackActive 0 242 243 #endif 244 245 extern int PetscStackCreate(int); 246 extern int PetscStackView(Viewer); 247 extern int PetscStackDestroy(void); 248 extern int PetscStackPublish(void); 249 extern int PetscStackDepublish(void); 250 251 /* 252 For locking, unlocking and destroying AMS memories associated with 253 PETSc objects 254 */ 255 256 #if defined(PETSC_HAVE_AMS) 257 #define PetscAMSTakeAccess(obj) \ 258 ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_take_access(((PetscObject)(obj))->amem)) 259 #define PetscAMSGrantAccess(obj) \ 260 ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_grant_access(((PetscObject)(obj))->amem)) 261 #define PetscAMSDestroy(obj) \ 262 ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_destroy(((PetscObject)(obj))->amem)); \ 263 ((PetscObject)(obj))->amem = -1; 264 #else 265 #define PetscAMSTakeAccess(obj) 0 266 #define PetscAMSGrantAccess(obj) 0 267 #define PetscAMSDestroy(obj) 0 268 #endif 269 270 #endif 271 272