xref: /petsc/include/petscerror.h (revision b5758dff40dc4232f7fa9713b5481f7e0e0d5d24)
1 /* $Id: petscerror.h,v 1.53 2001/01/15 21:50:04 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_variables 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 */
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_NOTSAMECOMM 80   /* two args must be same communicators */
55 #define PETSC_ERR_ARG_WRONGSTATE  73   /* object in argument is in wrong state, e.g. unassembled mat */
56 #define PETSC_ERR_ARG_INCOMP      75   /* two arguments are incompatible */
57 
58 #define PETSC_ERR_FILE_OPEN       65   /* unable to open file */
59 #define PETSC_ERR_FILE_READ       66   /* unable to read from file */
60 #define PETSC_ERR_FILE_WRITE      67   /* unable to write to file */
61 #define PETSC_ERR_FILE_UNEXPECTED 79   /* unexpected data in file */
62 
63 #define PETSC_ERR_KSP_BRKDWN      70   /* break down in a Krylov method */
64 
65 #define PETSC_ERR_MAT_LU_ZRPVT    71   /* detected a zero pivot during LU factorization */
66 #define PETSC_ERR_MAT_CH_ZRPVT    81   /* detected a zero pivot during Cholesky factorization */
67 
68 #if defined(PETSC_USE_DEBUG)
69 #define SETERRQ(n,s)              {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,1,s);}
70 #define SETERRQ1(n,s,a1)          {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,1,s,a1);}
71 #define SETERRQ2(n,s,a1,a2)       {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,1,s,a1,a2);}
72 #define SETERRQ3(n,s,a1,a2,a3)    {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,1,s,a1,a2,a3);}
73 #define SETERRQ4(n,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4);}
74 
75 #define CHKERRQ(n)     if (n) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,0,0);}
76 
77 #define CHKMEMQ {int __ierr = PetscTrValid(__LINE__,__FUNC__,__FILE__,__SDIR__);CHKERRQ(__ierr);}
78 
79 #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
80 extern  int __gierr;
81 #define _   __gierr =
82 #define ___  CHKERRQ(__gierr);
83 #endif
84 
85 #else
86 #define SETERRQ(n,s) ;
87 #define SETERRQ1(n,s,a1) ;
88 #define SETERRQ2(n,s,a1,a2) ;
89 #define SETERRQ3(n,s,a1,a2,a3) ;
90 #define SETERRQ4(n,s,a1,a2,a3,a4) ;
91 
92 #define CHKERRQ(n)     ;
93 
94 #define CHKMEMQ        ;
95 
96 #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
97 #define _
98 #define ___
99 #endif
100 
101 #endif
102 
103 EXTERN int PetscErrorMessage(int,char**,char **);
104 EXTERN int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
105 EXTERN int PetscEmacsClientErrorHandler(int,char*,char*,char*,int,int,char*,void*);
106 EXTERN int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
107 EXTERN int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void*);
108 EXTERN int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
109 EXTERN int PetscError(int,char*,char*,char*,int,int,char*,...);
110 EXTERN int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
111 EXTERN int PetscPopErrorHandler(void);
112 EXTERN int PetscDefaultSignalHandler(int,void*);
113 EXTERN int PetscPushSignalHandler(int (*)(int,void *),void*);
114 EXTERN int PetscPopSignalHandler(void);
115 
116 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
117 EXTERN int PetscSetFPTrap(PetscFPTrap);
118 
119 /*
120       Allows the code to build a stack frame as it runs
121 */
122 #if defined(PETSC_USE_STACK)
123 
124 #define PETSCSTACKSIZE 15
125 
126 typedef struct  {
127   char *function[PETSCSTACKSIZE];
128   char *file[PETSCSTACKSIZE];
129   char *directory[PETSCSTACKSIZE];
130   int  line[PETSCSTACKSIZE];
131   int  currentsize;
132 } PetscStack;
133 
134 extern PetscStack *petscstack;
135 EXTERN int PetscStackCopy(PetscStack*,PetscStack*);
136 EXTERN int PetscStackPrint(PetscStack*,FILE* fp);
137 
138 #define PetscStackActive (petscstack != 0)
139 
140 #if !defined(PETSC_HAVE_AMS)
141 
142 #define PetscFunctionBegin \
143   {\
144    if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
145     petscstack->function[petscstack->currentsize]  = __FUNC__; \
146     petscstack->file[petscstack->currentsize]      = __FILE__; \
147     petscstack->directory[petscstack->currentsize] = __SDIR__; \
148     petscstack->line[petscstack->currentsize]      = __LINE__; \
149     petscstack->currentsize++; \
150   }}
151 
152 #define PetscStackPush(n) \
153   {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
154     petscstack->function[petscstack->currentsize]  = n; \
155     petscstack->file[petscstack->currentsize]      = "unknown"; \
156     petscstack->directory[petscstack->currentsize] = "unknown"; \
157     petscstack->line[petscstack->currentsize]      = 0; \
158     petscstack->currentsize++; \
159   }}
160 
161 #define PetscStackPop \
162   {if (petscstack && petscstack->currentsize > 0) {     \
163     petscstack->currentsize--; \
164     petscstack->function[petscstack->currentsize]  = 0; \
165     petscstack->file[petscstack->currentsize]      = 0; \
166     petscstack->directory[petscstack->currentsize] = 0; \
167     petscstack->line[petscstack->currentsize]      = 0; \
168   }};
169 
170 #define PetscFunctionReturn(a) \
171   {\
172   PetscStackPop; \
173   return(a);}
174 
175 #define PetscFunctionReturnVoid() \
176   {\
177   PetscStackPop;}
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 && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
195     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
196     petscstack->function[petscstack->currentsize]  = __FUNC__; \
197     petscstack->file[petscstack->currentsize]      = __FILE__; \
198     petscstack->directory[petscstack->currentsize] = __SDIR__; \
199     petscstack->line[petscstack->currentsize]      = __LINE__; \
200     petscstack->currentsize++; \
201     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
202   }}
203 
204 #define PetscStackPush(n) \
205   {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
206     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
207     petscstack->function[petscstack->currentsize]  = n; \
208     petscstack->file[petscstack->currentsize]      = "unknown"; \
209     petscstack->directory[petscstack->currentsize] = "unknown"; \
210     petscstack->line[petscstack->currentsize]      = 0; \
211     petscstack->currentsize++; \
212     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
213   }}
214 
215 #define PetscStackPop \
216   {if (petscstack && petscstack->currentsize > 0) {     \
217     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
218     petscstack->currentsize--; \
219     petscstack->function[petscstack->currentsize]  = 0; \
220     petscstack->file[petscstack->currentsize]      = 0; \
221     petscstack->directory[petscstack->currentsize] = 0; \
222     petscstack->line[petscstack->currentsize]      = 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 PetscFunctionReturnVoid() \
232   {\
233   PetscStackPop;}
234 
235 
236 #endif
237 
238 #else
239 
240 #define PetscFunctionBegin
241 #define PetscFunctionReturn(a)  return(a)
242 #define PetscFunctionReturnVoid()
243 #define PetscStackPop
244 #define PetscStackPush(f)
245 #define PetscStackActive        0
246 
247 #endif
248 
249 EXTERN int PetscStackCreate(void);
250 EXTERN int PetscStackView(PetscViewer);
251 EXTERN int PetscStackDestroy(void);
252 EXTERN int PetscStackPublish(void);
253 EXTERN int PetscStackDepublish(void);
254 
255 
256 #endif
257 
258 
259