1 /* $Id: petscerror.h,v 1.20 1998/06/09 21:21:55 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 /* 11 Defines the directory where the compiled source is located; used 12 in printing error messages. Each makefile has an entry 13 LOCDIR = thedirectory 14 and bmake/common includes in CCPPFLAGS -D__SDIR__='"${LOCDIR}"' 15 which is a flag passed to the C/C++ compilers. 16 */ 17 #if !defined(__SDIR__) 18 #define __SDIR__ "unknowndirectory/" 19 #endif 20 21 /* 22 Defines the function where the compiled source is located; used 23 in printing error messages. 24 */ 25 #if !defined(__FUNC__) 26 #define __FUNC__ "unknownfunction" 27 #endif 28 29 /* 30 These are the generic error codes. These error codes are used 31 many different places in the PETSc source code. 32 33 In addition, each specific error in the code has an error 34 message: a specific, unique error code. (The specific error 35 code is not yet in use; these will be generated automatically and 36 embed an integer into the PetscError() calls. For non-English 37 error messages, that integer will be extracted and used to look up the 38 appropriate error message in the local language from a file.) 39 40 */ 41 #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 42 #define PETSC_ERR_SUP 56 /* no support for requested operation */ 43 #define PETSC_ERR_SIG 59 /* signal received */ 44 #define PETSC_ERR_FP 72 /* floating point exception */ 45 #define PETSC_ERR_COR 74 /* corrupted PETSc object */ 46 #define PETSC_ERR_LIB 76 /* error in library called by PETSc */ 47 #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */ 48 #define PETSC_ERR_MEMC 78 /* memory corruption */ 49 50 #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */ 51 #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */ 52 #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */ 53 #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */ 54 #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */ 55 #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */ 56 #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */ 57 #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */ 58 #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ 59 60 #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ 61 #define PETSC_ERR_FILE_READ 66 /* unable to read from file */ 62 #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */ 63 #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */ 64 65 #define PETSC_ERR_KSP_BRKDWN 70 /* break down in a Krylov method */ 66 67 #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */ 68 #define PETSC_ERR_MAT_CH_ZRPVT 71 /* detected a zero pivot during Cholesky factorization */ 69 70 #if defined(USE_PETSC_DEBUG) 71 #define SETERRQ(n,p,s) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);} 72 #define SETERRA(n,p,s) {int _ierr = PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);\ 73 MPI_Abort(PETSC_COMM_WORLD,_ierr);} 74 #define CHKERRQ(n) {if (n) SETERRQ(n,0,(char *)0);} 75 #define CHKERRA(n) {if (n) SETERRA(n,0,(char *)0);} 76 #define CHKPTRQ(p) if (!p) SETERRQ(PETSC_ERR_MEM,0,(char*)0); 77 #define CHKPTRA(p) if (!p) SETERRA(PETSC_ERR_MEM,0,(char*)0); 78 #else 79 #define SETERRQ(n,p,s) ; 80 #define SETERRA(n,p,s) ; 81 #define CHKERRQ(n) ; 82 #define CHKERRA(n) ; 83 #define CHKPTRQ(p) ; 84 #define CHKPTRA(p) ; 85 #endif 86 87 extern int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*); 88 extern int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*); 89 extern int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void* ); 90 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*); 91 extern int PetscError(int,char*,char*,char*,int,int,char*); 92 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*); 93 extern int PetscPopErrorHandler(void); 94 95 extern int PetscDefaultSignalHandler(int,void*); 96 extern int PetscPushSignalHandler(int (*)(int,void *),void*); 97 extern int PetscPopSignalHandler(void); 98 #define PETSC_FP_TRAP_OFF 0 99 #define PETSC_FP_TRAP_ON 1 100 extern int PetscSetFPTrap(int); 101 extern int PetscInitializeNans(Scalar*,int); 102 extern int PetscInitializeLargeInts(int *,int); 103 104 /* 105 Allows the code to build a stack frame as it runs 106 */ 107 #if defined(USE_PETSC_STACK) 108 109 typedef struct { 110 char **function; 111 char **file; 112 char **directory; 113 int *line; 114 } PetscStack; 115 116 extern int petscstacksize_max; 117 extern int petscstacksize; 118 extern PetscStack *petscstack; 119 120 #define PetscFunctionBegin \ 121 {if (petscstack && (petscstacksize < petscstacksize_max)) { \ 122 petscstack->function[petscstacksize] = __FUNC__; \ 123 petscstack->file[petscstacksize] = __FILE__; \ 124 petscstack->directory[petscstacksize] = __SDIR__; \ 125 petscstack->line[petscstacksize] = __LINE__; \ 126 petscstacksize++; \ 127 }} 128 129 #define PetscStackPush(n) \ 130 {if (petscstack && (petscstacksize < petscstacksize_max)) { \ 131 petscstack->function[petscstacksize] = n; \ 132 petscstack->file[petscstacksize] = 0; \ 133 petscstack->directory[petscstacksize] = 0; \ 134 petscstack->line[petscstacksize] = 0; \ 135 petscstacksize++; \ 136 }} 137 138 #define PetscStackPop \ 139 {if (petscstack && petscstacksize > 0) { \ 140 petscstacksize--; \ 141 petscstack->function[petscstacksize] = 0; \ 142 petscstack->file[petscstacksize] = 0; \ 143 petscstack->directory[petscstacksize] = 0; \ 144 petscstack->line[petscstacksize] = 0; \ 145 }}; 146 147 #define PetscFunctionReturn(a) \ 148 {PetscStackPop; \ 149 return(a);} 150 151 #define PetscStackActive (petscstack != 0) 152 153 #else 154 155 #define PetscFunctionBegin 156 #define PetscFunctionReturn(a) return(a) 157 #define PetscStackPop 158 #define PetscStackPush(f) 159 #define PetscStackActive 0 160 161 #endif 162 163 extern int PetscStackCreate(int); 164 extern int PetscStackView(Viewer); 165 extern int PetscStackDestroy(void); 166 167 #endif 168