1 /* $Id: petscerror.h,v 1.21 1998/07/02 02:47:54 bsmith Exp ibrahba $ */ 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(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(USE_PETSC_DEBUG) 75 #define SETERRQ(n,p,s) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);} 76 #define SETERRA(n,p,s) {int _ierr = PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);\ 77 MPI_Abort(PETSC_COMM_WORLD,_ierr);} 78 #define CHKERRQ(n) {if (n) SETERRQ(n,0,(char *)0);} 79 #define CHKERRA(n) {if (n) SETERRA(n,0,(char *)0);} 80 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,0,(char*)0); 81 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,0,(char*)0); 82 #else 83 #define SETERRQ(n,p,s) ; 84 #define SETERRA(n,p,s) ; 85 #define CHKERRQ(n) ; 86 #define CHKERRA(n) ; 87 #define CHKPTRQ(p) ; 88 #define CHKPTRA(p) ; 89 #endif 90 91 extern int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*); 92 extern int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*); 93 extern int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void* ); 94 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*); 95 extern int PetscError(int,char*,char*,char*,int,int,char*); 96 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*); 97 extern int PetscPopErrorHandler(void); 98 99 extern int PetscDefaultSignalHandler(int,void*); 100 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 101 extern int PetscPopSignalHandler(void); 102 #define PETSC_FP_TRAP_OFF 0 103 #define PETSC_FP_TRAP_ON 1 104 extern int PetscSetFPTrap(int); 105 extern int PetscInitializeNans(Scalar*,int); 106 extern int PetscInitializeLargeInts(int *,int); 107 108 /* 109 Allows the code to build a stack frame as it runs 110 */ 111 #if defined(USE_PETSC_STACK) 112 113 typedef struct { 114 char **function; 115 char **file; 116 char **directory; 117 int *line; 118 } PetscStack; 119 120 extern int petscstacksize_max; 121 extern int petscstacksize; 122 extern PetscStack *petscstack; 123 124 #if !defined(HAVE_AMS) 125 126 #define PetscFunctionBegin \ 127 {if (petscstack && (petscstacksize < petscstacksize_max)) { \ 128 petscstack->function[petscstacksize] = __FUNC__; \ 129 petscstack->file[petscstacksize] = __FILE__; \ 130 petscstack->directory[petscstacksize] = __SDIR__; \ 131 petscstack->line[petscstacksize] = __LINE__; \ 132 petscstacksize++; \ 133 }} 134 135 #define PetscStackPush(n) \ 136 {if (petscstack && (petscstacksize < petscstacksize_max)) { \ 137 petscstack->function[petscstacksize] = n; \ 138 petscstack->file[petscstacksize] = 0; \ 139 petscstack->directory[petscstacksize] = 0; \ 140 petscstack->line[petscstacksize] = 0; \ 141 petscstacksize++; \ 142 }} 143 144 #define PetscStackPop \ 145 {if (petscstack && petscstacksize > 0) { \ 146 petscstacksize--; \ 147 petscstack->function[petscstacksize] = 0; \ 148 petscstack->file[petscstacksize] = 0; \ 149 petscstack->directory[petscstacksize] = 0; \ 150 petscstack->line[petscstacksize] = 0; \ 151 }}; 152 153 #define PetscFunctionReturn(a) \ 154 {PetscStackPop; \ 155 return(a);} 156 157 #define PetscStackActive (petscstack != 0) 158 159 #else 160 161 /* Duplicate Code for HAVE_AMS */ 162 extern AMS_Comm stack_comm; 163 extern AMS_Memory stack_mem; 164 extern stack_err; 165 166 #define PetscFunctionBegin \ 167 {if (petscstack && (petscstacksize < petscstacksize_max)) { \ 168 if (!(stack_mem < 0)) \ 169 stack_err = AMS_Memory_take_access(stack_mem);\ 170 petscstack->function[petscstacksize] = __FUNC__; \ 171 petscstack->file[petscstacksize] = __FILE__; \ 172 petscstack->directory[petscstacksize] = __SDIR__; \ 173 petscstack->line[petscstacksize] = __LINE__; \ 174 petscstacksize++; \ 175 if (!(stack_mem < 0)) \ 176 stack_err = AMS_Memory_grant_access(stack_mem);\ 177 }} 178 179 #define PetscStackPush(n) \ 180 {if (petscstack && (petscstacksize < petscstacksize_max)) { \ 181 if (!(stack_mem < 0)) \ 182 stack_err = AMS_Memory_take_access(stack_mem);\ 183 petscstack->function[petscstacksize] = n; \ 184 petscstack->file[petscstacksize] = 0; \ 185 petscstack->directory[petscstacksize] = 0; \ 186 petscstack->line[petscstacksize] = 0; \ 187 petscstacksize++; \ 188 if (!(stack_mem < 0)) \ 189 stack_err = AMS_Memory_grant_access(stack_mem);\ 190 }} 191 192 #define PetscStackPop \ 193 {if (petscstack && petscstacksize > 0) { \ 194 if (!(stack_mem < 0)) \ 195 stack_err = AMS_Memory_take_access(stack_mem);\ 196 petscstacksize--; \ 197 petscstack->function[petscstacksize] = 0; \ 198 petscstack->file[petscstacksize] = 0; \ 199 petscstack->directory[petscstacksize] = 0; \ 200 petscstack->line[petscstacksize] = 0; \ 201 if (!(stack_mem < 0)) \ 202 stack_err = AMS_Memory_grant_access(stack_mem);\ 203 }}; 204 205 #define PetscFunctionReturn(a) \ 206 {PetscStackPop; \ 207 return(a);} 208 209 #define PetscStackActive (petscstack != 0) 210 211 #endif 212 213 #else 214 215 #define PetscFunctionBegin 216 #define PetscFunctionReturn(a) return(a) 217 #define PetscStackPop 218 #define PetscStackPush(f) 219 #define PetscStackActive 0 220 221 #endif 222 223 extern int PetscStackCreate(int); 224 extern int PetscStackView(Viewer); 225 extern int PetscStackDestroy(void); 226 227 #endif 228