xref: /petsc/include/petscerror.h (revision 194405b315295dc9d64191f8f2a14e831cccbfba)
1 /* $Id: petscerror.h,v 1.55 2001/03/23 23:26:09 balay 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 __ierr = PetscTrValid(__LINE__,__FUNCT__,__FILE__,__SDIR__);CHKERRQ(__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 PetscEmacsClientErrorHandler(int,char*,char*,char*,int,int,char*,void*);
109 EXTERN int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
110 EXTERN int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void*);
111 EXTERN int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
112 EXTERN int PetscError(int,char*,char*,char*,int,int,char*,...);
113 EXTERN int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
114 EXTERN int PetscPopErrorHandler(void);
115 EXTERN int PetscDefaultSignalHandler(int,void*);
116 EXTERN int PetscPushSignalHandler(int (*)(int,void *),void*);
117 EXTERN int PetscPopSignalHandler(void);
118 
119 typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
120 EXTERN int PetscSetFPTrap(PetscFPTrap);
121 
122 /*
123       Allows the code to build a stack frame as it runs
124 */
125 #if defined(PETSC_USE_STACK)
126 
127 #define PETSCSTACKSIZE 15
128 
129 typedef struct  {
130   char *function[PETSCSTACKSIZE];
131   char *file[PETSCSTACKSIZE];
132   char *directory[PETSCSTACKSIZE];
133   int  line[PETSCSTACKSIZE];
134   int  currentsize;
135 } PetscStack;
136 
137 extern PetscStack *petscstack;
138 EXTERN int PetscStackCopy(PetscStack*,PetscStack*);
139 EXTERN int PetscStackPrint(PetscStack*,FILE* fp);
140 
141 #define PetscStackActive (petscstack != 0)
142 
143 #if !defined(PETSC_HAVE_AMS)
144 
145 #define PetscFunctionBegin \
146   {\
147    if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
148     petscstack->function[petscstack->currentsize]  = __FUNCT__; \
149     petscstack->file[petscstack->currentsize]      = __FILE__; \
150     petscstack->directory[petscstack->currentsize] = __SDIR__; \
151     petscstack->line[petscstack->currentsize]      = __LINE__; \
152     petscstack->currentsize++; \
153   }}
154 
155 #define PetscStackPush(n) \
156   {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
157     petscstack->function[petscstack->currentsize]  = n; \
158     petscstack->file[petscstack->currentsize]      = "unknown"; \
159     petscstack->directory[petscstack->currentsize] = "unknown"; \
160     petscstack->line[petscstack->currentsize]      = 0; \
161     petscstack->currentsize++; \
162   }}
163 
164 #define PetscStackPop \
165   {if (petscstack && petscstack->currentsize > 0) {     \
166     petscstack->currentsize--; \
167     petscstack->function[petscstack->currentsize]  = 0; \
168     petscstack->file[petscstack->currentsize]      = 0; \
169     petscstack->directory[petscstack->currentsize] = 0; \
170     petscstack->line[petscstack->currentsize]      = 0; \
171   }};
172 
173 #define PetscFunctionReturn(a) \
174   {\
175   PetscStackPop; \
176   return(a);}
177 
178 #define PetscFunctionReturnVoid() \
179   {\
180   PetscStackPop;}
181 
182 #else
183 
184 /*
185     Duplicate Code for when the ALICE Memory Snooper (AMS)
186   is being used. When PETSC_HAVE_AMS is defined.
187 
188      stack_mem is the AMS memory that contains fields for the
189                number of stack frames and names of the stack frames
190 */
191 
192 extern AMS_Memory stack_mem;
193 extern int        stack_err;
194 
195 #define PetscFunctionBegin \
196   {\
197    if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
198     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
199     petscstack->function[petscstack->currentsize]  = __FUNCT__; \
200     petscstack->file[petscstack->currentsize]      = __FILE__; \
201     petscstack->directory[petscstack->currentsize] = __SDIR__; \
202     petscstack->line[petscstack->currentsize]      = __LINE__; \
203     petscstack->currentsize++; \
204     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
205   }}
206 
207 #define PetscStackPush(n) \
208   {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    \
209     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
210     petscstack->function[petscstack->currentsize]  = n; \
211     petscstack->file[petscstack->currentsize]      = "unknown"; \
212     petscstack->directory[petscstack->currentsize] = "unknown"; \
213     petscstack->line[petscstack->currentsize]      = 0; \
214     petscstack->currentsize++; \
215     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
216   }}
217 
218 #define PetscStackPop \
219   {if (petscstack && petscstack->currentsize > 0) {     \
220     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
221     petscstack->currentsize--; \
222     petscstack->function[petscstack->currentsize]  = 0; \
223     petscstack->file[petscstack->currentsize]      = 0; \
224     petscstack->directory[petscstack->currentsize] = 0; \
225     petscstack->line[petscstack->currentsize]      = 0; \
226     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
227   }};
228 
229 #define PetscFunctionReturn(a) \
230   {\
231   PetscStackPop; \
232   return(a);}
233 
234 #define PetscFunctionReturnVoid() \
235   {\
236   PetscStackPop;}
237 
238 
239 #endif
240 
241 #else
242 
243 #define PetscFunctionBegin
244 #define PetscFunctionReturn(a)  return(a)
245 #define PetscFunctionReturnVoid()
246 #define PetscStackPop
247 #define PetscStackPush(f)
248 #define PetscStackActive        0
249 
250 #endif
251 
252 EXTERN int PetscStackCreate(void);
253 EXTERN int PetscStackView(PetscViewer);
254 EXTERN int PetscStackDestroy(void);
255 EXTERN int PetscStackPublish(void);
256 EXTERN int PetscStackDepublish(void);
257 
258 
259 #endif
260 
261 
262