xref: /petsc/include/petscerror.h (revision c8a8475e04bcaa43590892a5c3e60c6f87bc31f7)
1 /* $Id: petscerror.h,v 1.59 2001/09/07 20:13:16 bsmith Exp $ */
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 #define PETSC_ERR_MAX_ITER        82   /* Maximum iterations reached */
47 
48 #define PETSC_ERR_ARG_SIZ         60   /* nonconforming object sizes used in operation */
49 #define PETSC_ERR_ARG_IDN         61   /* two arguments not allowed to be the same */
50 #define PETSC_ERR_ARG_WRONG       62   /* wrong argument (but object probably ok) */
51 #define PETSC_ERR_ARG_CORRUPT     64   /* null or corrupted PETSc object as argument */
52 #define PETSC_ERR_ARG_OUTOFRANGE  63   /* input argument, out of range */
53 #define PETSC_ERR_ARG_BADPTR      68   /* invalid pointer argument */
54 #define PETSC_ERR_ARG_NOTSAMETYPE 69   /* two args must be same object type */
55 #define PETSC_ERR_ARG_NOTSAMECOMM 80   /* two args must be same communicators */
56 #define PETSC_ERR_ARG_WRONGSTATE  73   /* object in argument is in wrong state, e.g. unassembled mat */
57 #define PETSC_ERR_ARG_INCOMP      75   /* two arguments are incompatible */
58 
59 #define PETSC_ERR_FILE_OPEN       65   /* unable to open file */
60 #define PETSC_ERR_FILE_READ       66   /* unable to read from file */
61 #define PETSC_ERR_FILE_WRITE      67   /* unable to write to file */
62 #define PETSC_ERR_FILE_UNEXPECTED 79   /* unexpected data in file */
63 
64 #define PETSC_ERR_KSP_BRKDWN      70   /* break down in a Krylov method */
65 
66 #define PETSC_ERR_MAT_LU_ZRPVT    71   /* detected a zero pivot during LU factorization */
67 #define PETSC_ERR_MAT_CH_ZRPVT    81   /* detected a zero pivot during Cholesky factorization */
68 
69 #define PETSC_ERR_MESH_NULL_ELEM  84   /* Element had no interior */
70 
71 #define PETSC_ERR_DISC_SING_JAC   83   /* Singular element Jacobian */
72 
73 #if defined(PETSC_USE_DEBUG)
74 #define SETERRQ(n,s)              {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);}
75 #define SETERRQ1(n,s,a1)          {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1);}
76 #define SETERRQ2(n,s,a1,a2)       {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2);}
77 #define SETERRQ3(n,s,a1,a2,a3)    {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3);}
78 #define SETERRQ4(n,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4);}
79 #define SETERRQ5(n,s,a1,a2,a3,a4,a5)       {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5);}
80 #define SETERRQ6(n,s,a1,a2,a3,a4,a5,a6)    {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5,a6);}
81 #define SETERRQ7(n,s,a1,a2,a3,a4,a5,a6,a7) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5,a6,a7);}
82 #define SETERRABORT(comm,n,s)     {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);MPI_Abort(com,n);}
83 
84 #define CHKERRQ(n)             if (n) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");}
85 #define CHKERRABORT(comm,n)    if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");MPI_Abort(comm,n);}
86 #define CHKERRCONTINUE(n)      if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");}
87 
88 #define CHKMEMQ {int _7_ierr = PetscTrValid(__LINE__,__FUNCT__,__FILE__,__SDIR__);CHKERRQ(_7_ierr);}
89 
90 #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
91 extern  int __gierr;
92 #define _   __gierr =
93 #define ___  CHKERRQ(__gierr);
94 #endif
95 
96 #else
97 #define SETERRQ(n,s) ;
98 #define SETERRQ1(n,s,a1) ;
99 #define SETERRQ2(n,s,a1,a2) ;
100 #define SETERRQ3(n,s,a1,a2,a3) ;
101 #define SETERRQ4(n,s,a1,a2,a3,a4) ;
102 #define SETERRABORT(comm,n,s) ;
103 
104 #define CHKERRQ(n)     ;
105 #define CHKERRABORT(comm,n) ;
106 #define CHKERRCONTINUE(n) ;
107 
108 #define CHKMEMQ        ;
109 
110 #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
111 #define _
112 #define ___
113 #endif
114 
115 #endif
116 
117 EXTERN int PetscErrorMessage(int,char**,char **);
118 EXTERN int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
119 EXTERN int PetscIgnoreErrorHandler(int,char*,char*,char*,int,int,char*,void*);
120 EXTERN int PetscEmacsClientErrorHandler(int,char*,char*,char*,int,int,char*,void*);
121 EXTERN int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
122 EXTERN int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void*);
123 EXTERN int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
124 EXTERN int PetscError(int,char*,char*,char*,int,int,char*,...) PETSC_PRINTF_FORMAT_CHECK(7,8);
125 EXTERN int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
126 EXTERN int PetscPopErrorHandler(void);
127 EXTERN int PetscDefaultSignalHandler(int,void*);
128 EXTERN int PetscPushSignalHandler(int (*)(int,void *),void*);
129 EXTERN int PetscPopSignalHandler(void);
130 
131 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
132 EXTERN int PetscSetFPTrap(PetscFPTrap);
133 
134 /*
135       Allows the code to build a stack frame as it runs
136 */
137 #if defined(PETSC_USE_STACK)
138 
139 #define PETSCSTACKSIZE 15
140 
141 typedef struct  {
142   char *function[PETSCSTACKSIZE];
143   char *file[PETSCSTACKSIZE];
144   char *directory[PETSCSTACKSIZE];
145   int  line[PETSCSTACKSIZE];
146   int  currentsize;
147 } PetscStack;
148 
149 extern PetscStack *petscstack;
150 EXTERN int PetscStackCopy(PetscStack*,PetscStack*);
151 EXTERN int PetscStackPrint(PetscStack*,FILE* fp);
152 
153 #define PetscStackActive (petscstack != 0)
154 
155 #if !defined(PETSC_HAVE_AMS)
156 
157 #define PetscFunctionBegin \
158   {\
159    if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
160     petscstack->function[petscstack->currentsize]  = __FUNCT__; \
161     petscstack->file[petscstack->currentsize]      = __FILE__; \
162     petscstack->directory[petscstack->currentsize] = __SDIR__; \
163     petscstack->line[petscstack->currentsize]      = __LINE__; \
164     petscstack->currentsize++; \
165   }}
166 
167 #define PetscStackPush(n) \
168   {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
169     petscstack->function[petscstack->currentsize]  = n; \
170     petscstack->file[petscstack->currentsize]      = "unknown"; \
171     petscstack->directory[petscstack->currentsize] = "unknown"; \
172     petscstack->line[petscstack->currentsize]      = 0; \
173     petscstack->currentsize++; \
174   }}
175 
176 #define PetscStackPop \
177   {if (petscstack && petscstack->currentsize > 0) {     \
178     petscstack->currentsize--; \
179     petscstack->function[petscstack->currentsize]  = 0; \
180     petscstack->file[petscstack->currentsize]      = 0; \
181     petscstack->directory[petscstack->currentsize] = 0; \
182     petscstack->line[petscstack->currentsize]      = 0; \
183   }};
184 
185 #define PetscFunctionReturn(a) \
186   {\
187   PetscStackPop; \
188   return(a);}
189 
190 #define PetscFunctionReturnVoid() \
191   {\
192   PetscStackPop; \
193   return;}
194 
195 #else
196 
197 /*
198     Duplicate Code for when the ALICE Memory Snooper (AMS)
199   is being used. When PETSC_HAVE_AMS is defined.
200 
201      stack_mem is the AMS memory that contains fields for the
202                number of stack frames and names of the stack frames
203 */
204 
205 extern AMS_Memory stack_mem;
206 extern int        stack_err;
207 
208 #define PetscFunctionBegin \
209   {\
210    if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
211     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
212     petscstack->function[petscstack->currentsize]  = __FUNCT__; \
213     petscstack->file[petscstack->currentsize]      = __FILE__; \
214     petscstack->directory[petscstack->currentsize] = __SDIR__; \
215     petscstack->line[petscstack->currentsize]      = __LINE__; \
216     petscstack->currentsize++; \
217     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
218   }}
219 
220 #define PetscStackPush(n) \
221   {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
222     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
223     petscstack->function[petscstack->currentsize]  = n; \
224     petscstack->file[petscstack->currentsize]      = "unknown"; \
225     petscstack->directory[petscstack->currentsize] = "unknown"; \
226     petscstack->line[petscstack->currentsize]      = 0; \
227     petscstack->currentsize++; \
228     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
229   }}
230 
231 #define PetscStackPop \
232   {if (petscstack && petscstack->currentsize > 0) {     \
233     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
234     petscstack->currentsize--; \
235     petscstack->function[petscstack->currentsize]  = 0; \
236     petscstack->file[petscstack->currentsize]      = 0; \
237     petscstack->directory[petscstack->currentsize] = 0; \
238     petscstack->line[petscstack->currentsize]      = 0; \
239     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
240   }};
241 
242 #define PetscFunctionReturn(a) \
243   {\
244   PetscStackPop; \
245   return(a);}
246 
247 #define PetscFunctionReturnVoid() \
248   {\
249   PetscStackPop; \
250   return;}
251 
252 
253 #endif
254 
255 #else
256 
257 #define PetscFunctionBegin
258 #define PetscFunctionReturn(a)  return(a)
259 #define PetscFunctionReturnVoid() return()
260 #define PetscStackPop
261 #define PetscStackPush(f)
262 #define PetscStackActive        0
263 
264 #endif
265 
266 EXTERN int PetscStackCreate(void);
267 EXTERN int PetscStackView(PetscViewer);
268 EXTERN int PetscStackDestroy(void);
269 EXTERN int PetscStackPublish(void);
270 EXTERN int PetscStackDepublish(void);
271 
272 
273 #endif
274 
275 
276