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