xref: /petsc/include/petscerror.h (revision ef66eb6987ddfdf4e414d6b820cbc8d8d7d17bc2)
1 /* $Id: petscerror.h,v 1.58 2001/07/10 04:52:49 buschelm 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(__FUNCT__)
30 #define __FUNCT__ "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__,__FUNCT__,__FILE__,__SDIR__,n,1,s);}
70 #define SETERRQ1(n,s,a1)          {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1);}
71 #define SETERRQ2(n,s,a1,a2)       {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2);}
72 #define SETERRQ3(n,s,a1,a2,a3)    {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3);}
73 #define SETERRQ4(n,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4);}
74 #define SETERRABORT(n,s)          {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);MPI_Abort(n);}
75 
76 #define CHKERRQ(n)        if (n) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0,0);}
77 #define CHKERRABORT(n)    if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0,0);MPI_Abort(n);}
78 #define CHKERRCONTINUE(n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0,0);}
79 
80 #define CHKMEMQ {int _7_ierr = PetscTrValid(__LINE__,__FUNCT__,__FILE__,__SDIR__);CHKERRQ(_7_ierr);}
81 
82 #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
83 extern  int __gierr;
84 #define _   __gierr =
85 #define ___  CHKERRQ(__gierr);
86 #endif
87 
88 #else
89 #define SETERRQ(n,s) ;
90 #define SETERRQ1(n,s,a1) ;
91 #define SETERRQ2(n,s,a1,a2) ;
92 #define SETERRQ3(n,s,a1,a2,a3) ;
93 #define SETERRQ4(n,s,a1,a2,a3,a4) ;
94 
95 #define CHKERRQ(n)     ;
96 
97 #define CHKMEMQ        ;
98 
99 #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
100 #define _
101 #define ___
102 #endif
103 
104 #endif
105 
106 EXTERN int PetscErrorMessage(int,char**,char **);
107 EXTERN int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
108 EXTERN int PetscIgnoreErrorHandler(int,char*,char*,char*,int,int,char*,void*);
109 EXTERN int PetscEmacsClientErrorHandler(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 EXTERN int PetscDefaultSignalHandler(int,void*);
117 EXTERN int PetscPushSignalHandler(int (*)(int,void *),void*);
118 EXTERN int PetscPopSignalHandler(void);
119 
120 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
121 EXTERN int PetscSetFPTrap(PetscFPTrap);
122 
123 /*
124       Allows the code to build a stack frame as it runs
125 */
126 #if defined(PETSC_USE_STACK)
127 
128 #define PETSCSTACKSIZE 15
129 
130 typedef struct  {
131   char *function[PETSCSTACKSIZE];
132   char *file[PETSCSTACKSIZE];
133   char *directory[PETSCSTACKSIZE];
134   int  line[PETSCSTACKSIZE];
135   int  currentsize;
136 } PetscStack;
137 
138 extern PetscStack *petscstack;
139 EXTERN int PetscStackCopy(PetscStack*,PetscStack*);
140 EXTERN int PetscStackPrint(PetscStack*,FILE* fp);
141 
142 #define PetscStackActive (petscstack != 0)
143 
144 #if !defined(PETSC_HAVE_AMS)
145 
146 #define PetscFunctionBegin \
147   {\
148    if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
149     petscstack->function[petscstack->currentsize]  = __FUNCT__; \
150     petscstack->file[petscstack->currentsize]      = __FILE__; \
151     petscstack->directory[petscstack->currentsize] = __SDIR__; \
152     petscstack->line[petscstack->currentsize]      = __LINE__; \
153     petscstack->currentsize++; \
154   }}
155 
156 #define PetscStackPush(n) \
157   {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
158     petscstack->function[petscstack->currentsize]  = n; \
159     petscstack->file[petscstack->currentsize]      = "unknown"; \
160     petscstack->directory[petscstack->currentsize] = "unknown"; \
161     petscstack->line[petscstack->currentsize]      = 0; \
162     petscstack->currentsize++; \
163   }}
164 
165 #define PetscStackPop \
166   {if (petscstack && petscstack->currentsize > 0) {     \
167     petscstack->currentsize--; \
168     petscstack->function[petscstack->currentsize]  = 0; \
169     petscstack->file[petscstack->currentsize]      = 0; \
170     petscstack->directory[petscstack->currentsize] = 0; \
171     petscstack->line[petscstack->currentsize]      = 0; \
172   }};
173 
174 #define PetscFunctionReturn(a) \
175   {\
176   PetscStackPop; \
177   return(a);}
178 
179 #define PetscFunctionReturnVoid() \
180   {\
181   PetscStackPop; \
182   return;}
183 
184 #else
185 
186 /*
187     Duplicate Code for when the ALICE Memory Snooper (AMS)
188   is being used. When PETSC_HAVE_AMS is defined.
189 
190      stack_mem is the AMS memory that contains fields for the
191                number of stack frames and names of the stack frames
192 */
193 
194 extern AMS_Memory stack_mem;
195 extern int        stack_err;
196 
197 #define PetscFunctionBegin \
198   {\
199    if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
200     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
201     petscstack->function[petscstack->currentsize]  = __FUNCT__; \
202     petscstack->file[petscstack->currentsize]      = __FILE__; \
203     petscstack->directory[petscstack->currentsize] = __SDIR__; \
204     petscstack->line[petscstack->currentsize]      = __LINE__; \
205     petscstack->currentsize++; \
206     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
207   }}
208 
209 #define PetscStackPush(n) \
210   {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
211     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
212     petscstack->function[petscstack->currentsize]  = n; \
213     petscstack->file[petscstack->currentsize]      = "unknown"; \
214     petscstack->directory[petscstack->currentsize] = "unknown"; \
215     petscstack->line[petscstack->currentsize]      = 0; \
216     petscstack->currentsize++; \
217     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
218   }}
219 
220 #define PetscStackPop \
221   {if (petscstack && petscstack->currentsize > 0) {     \
222     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
223     petscstack->currentsize--; \
224     petscstack->function[petscstack->currentsize]  = 0; \
225     petscstack->file[petscstack->currentsize]      = 0; \
226     petscstack->directory[petscstack->currentsize] = 0; \
227     petscstack->line[petscstack->currentsize]      = 0; \
228     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
229   }};
230 
231 #define PetscFunctionReturn(a) \
232   {\
233   PetscStackPop; \
234   return(a);}
235 
236 #define PetscFunctionReturnVoid() \
237   {\
238   PetscStackPop; \
239   return;}
240 
241 
242 #endif
243 
244 #else
245 
246 #define PetscFunctionBegin
247 #define PetscFunctionReturn(a)  return(a)
248 #define PetscFunctionReturnVoid() return()
249 #define PetscStackPop
250 #define PetscStackPush(f)
251 #define PetscStackActive        0
252 
253 #endif
254 
255 EXTERN int PetscStackCreate(void);
256 EXTERN int PetscStackView(PetscViewer);
257 EXTERN int PetscStackDestroy(void);
258 EXTERN int PetscStackPublish(void);
259 EXTERN int PetscStackDepublish(void);
260 
261 
262 #endif
263 
264 
265