xref: /petsc/include/petscerror.h (revision 2e8a6d31cfff42dc61c2443ddfa186a411c27ca7)
1 /* $Id: petscerror.h,v 1.26 1998/09/23 15:48:45 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(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 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      In addition, each specific error in the code has an error
38      message: a specific, unique error code.  (The specific error
39      code is not yet in use; these will be generated automatically and
40      embed an integer into the PetscError() calls. For non-English
41      error messages, that integer will be extracted and used to look up the
42      appropriate error message in the local language from a file.)
43 
44 */
45 #define PETSC_ERR_MEM             55   /* unable to allocate requested memory */
46 #define PETSC_ERR_SUP             56   /* no support for requested operation */
47 #define PETSC_ERR_SIG             59   /* signal received */
48 #define PETSC_ERR_FP              72   /* floating point exception */
49 #define PETSC_ERR_COR             74   /* corrupted PETSc object */
50 #define PETSC_ERR_LIB             76   /* error in library called by PETSc */
51 #define PETSC_ERR_PLIB            77   /* PETSc library generated inconsistent data */
52 #define PETSC_ERR_MEMC            78   /* memory corruption */
53 
54 #define PETSC_ERR_ARG_SIZ         60   /* nonconforming object sizes used in operation */
55 #define PETSC_ERR_ARG_IDN         61   /* two arguments not allowed to be the same */
56 #define PETSC_ERR_ARG_WRONG       62   /* wrong argument (but object probably ok) */
57 #define PETSC_ERR_ARG_CORRUPT     64   /* null or corrupted PETSc object as argument */
58 #define PETSC_ERR_ARG_OUTOFRANGE  63   /* input argument, out of range */
59 #define PETSC_ERR_ARG_BADPTR      68   /* invalid pointer argument */
60 #define PETSC_ERR_ARG_NOTSAMETYPE 69   /* two args must be same object type */
61 #define PETSC_ERR_ARG_WRONGSTATE  73   /* object in argument is in wrong state, e.g. unassembled mat */
62 #define PETSC_ERR_ARG_INCOMP      75   /* two arguments are incompatible */
63 
64 #define PETSC_ERR_FILE_OPEN       65   /* unable to open file */
65 #define PETSC_ERR_FILE_READ       66   /* unable to read from file */
66 #define PETSC_ERR_FILE_WRITE      67   /* unable to write to file */
67 #define PETSC_ERR_FILE_UNEXPECTED 79   /* unexpected data in file */
68 
69 #define PETSC_ERR_KSP_BRKDWN      70   /* break down in a Krylov method */
70 
71 #define PETSC_ERR_MAT_LU_ZRPVT    71   /* detected a zero pivot during LU factorization */
72 #define PETSC_ERR_MAT_CH_ZRPVT    71   /* detected a zero pivot during Cholesky factorization */
73 
74 #if defined(USE_PETSC_DEBUG)
75 #define SETERRQ(n,p,s) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);}
76 #define SETERRA(n,p,s) {int _ierr = PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);\
77                           MPI_Abort(PETSC_COMM_WORLD,_ierr);}
78 #define CHKERRQ(n)     {if (n) SETERRQ(n,0,(char *)0);}
79 #define CHKERRA(n)     {if (n) SETERRA(n,0,(char *)0);}
80 #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,0,(char*)0);
81 #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,0,(char*)0);
82 #else
83 #define SETERRQ(n,p,s) ;
84 #define SETERRA(n,p,s) ;
85 #define CHKERRQ(n)     ;
86 #define CHKERRA(n)     ;
87 #define CHKPTRQ(p)     ;
88 #define CHKPTRA(p)     ;
89 #endif
90 
91 extern int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
92 extern int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
93 extern int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void* );
94 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
95 extern int PetscError(int,char*,char*,char*,int,int,char*);
96 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
97 extern int PetscPopErrorHandler(void);
98 
99 extern int PetscDefaultSignalHandler(int,void*);
100 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
101 extern int PetscPopSignalHandler(void);
102 #define PETSC_FP_TRAP_OFF    0
103 #define PETSC_FP_TRAP_ON     1
104 extern int PetscSetFPTrap(int);
105 extern int PetscInitializeNans(Scalar*,int);
106 extern int PetscInitializeLargeInts(int *,int);
107 
108 /*
109       Allows the code to build a stack frame as it runs
110 */
111 #if defined(USE_PETSC_STACK)
112 
113 typedef struct  {
114   char **function;
115   char **file;
116   char **directory;
117   int  *line;
118 } PetscStack;
119 
120 extern int        petscstacksize_max;
121 extern int        petscstacksize;
122 extern PetscStack *petscstack;
123 
124 #if !defined(HAVE_AMS)
125 
126 #define PetscFunctionBegin \
127   {\
128    if (petscstack && (petscstacksize < petscstacksize_max)) {    \
129     petscstack->function[petscstacksize]  = __FUNC__; \
130     petscstack->file[petscstacksize]      = __FILE__; \
131     petscstack->directory[petscstacksize] = __SDIR__; \
132     petscstack->line[petscstacksize]      = __LINE__; \
133     petscstacksize++; \
134   }}
135 
136 #define PetscStackPush(n) \
137   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
138     petscstack->function[petscstacksize]  = n; \
139     petscstack->file[petscstacksize]      = "unknown"; \
140     petscstack->directory[petscstacksize] = "unknown"; \
141     petscstack->line[petscstacksize]      = 0; \
142     petscstacksize++; \
143   }}
144 
145 #define PetscStackPop \
146   {if (petscstack && petscstacksize > 0) {     \
147     petscstacksize--; \
148     petscstack->function[petscstacksize]  = 0; \
149     petscstack->file[petscstacksize]      = 0; \
150     petscstack->directory[petscstacksize] = 0; \
151     petscstack->line[petscstacksize]      = 0; \
152   }};
153 
154 #define PetscFunctionReturn(a) \
155   {\
156   PetscStackPop; \
157   return(a);}
158 
159 #define PetscStackActive (petscstack != 0)
160 
161 #else
162 
163 /*
164     Duplicate Code for when the ALICE Memory Snooper (AMS)
165   is being used. When HAVE_AMS is defined.
166 
167      stack_mem is the AMS memory that contains fields for the
168                number of stack frames and names of the stack frames
169 */
170 
171 extern AMS_Memory stack_mem;
172 extern int        stack_err;
173 
174 #define PetscFunctionBegin \
175   {\
176    if (petscstack && (petscstacksize < petscstacksize_max)) {    \
177     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
178     petscstack->function[petscstacksize]  = __FUNC__; \
179     petscstack->file[petscstacksize]      = __FILE__; \
180     petscstack->directory[petscstacksize] = __SDIR__; \
181     petscstack->line[petscstacksize]      = __LINE__; \
182     petscstacksize++; \
183     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
184   }}
185 
186 #define PetscStackPush(n) \
187   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
188     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
189     petscstack->function[petscstacksize]  = n; \
190     petscstack->file[petscstacksize]      = "unknown"; \
191     petscstack->directory[petscstacksize] = "unknown"; \
192     petscstack->line[petscstacksize]      = 0; \
193     petscstacksize++; \
194     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
195   }}
196 
197 #define PetscStackPop \
198   {if (petscstack && petscstacksize > 0) {     \
199     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
200     petscstacksize--; \
201     petscstack->function[petscstacksize]  = 0; \
202     petscstack->file[petscstacksize]      = 0; \
203     petscstack->directory[petscstacksize] = 0; \
204     petscstack->line[petscstacksize]      = 0; \
205     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
206   }};
207 
208 #define PetscFunctionReturn(a) \
209   {\
210   PetscStackPop; \
211   return(a);}
212 
213 #define PetscStackActive (petscstack != 0)
214 
215 #endif
216 
217 #else
218 
219 #define PetscFunctionBegin
220 #define PetscFunctionReturn(a)  return(a)
221 #define PetscStackPop
222 #define PetscStackPush(f)
223 #define PetscStackActive        0
224 
225 #endif
226 
227 extern int PetscStackCreate(int);
228 extern int PetscStackView(Viewer);
229 extern int PetscStackDestroy(void);
230 
231 /*
232           For locking and unlocking AMS memories associated with
233     PETSc objects
234 */
235 
236 #if defined(HAVE_AMS)
237 #define PetscAMSTakeAccess(obj)   \
238     ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_take_access(((PetscObject)(obj))->amem));
239 #define PetscAMSGrantAccess(obj)  \
240     ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_grant_access(((PetscObject)(obj))->amem));
241 #else
242 #define PetscAMSTakeAccess(obj)
243 #define PetscAMSGrantAccess(obj)
244 #endif
245 
246 #endif
247 
248