Actual source code: petscerror.h
1: /* $Id: petscerror.h,v 1.55 2001/03/23 23:26:09 balay Exp $ */
2: /*
3: Contains all error handling code for PETSc.
4: */
8: #include petsc.h
10: #if defined(PETSC_HAVE_AMS)
11: #include "ams.h"
12: #endif
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: */
23: #endif
25: /*
26: Defines the function where the compiled source is located; used
27: in printing error messages.
28: */
29: #endif
31: /*
32: These are the generic error codes. These error codes are used
33: many different places in the PETSc source code.
35: */
36: #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */
37: #define PETSC_ERR_SUP 56 /* no support for requested operation */
38: #define PETSC_ERR_SIG 59 /* signal received */
39: #define PETSC_ERR_FP 72 /* floating point exception */
40: #define PETSC_ERR_COR 74 /* corrupted PETSc object */
41: #define PETSC_ERR_LIB 76 /* error in library called by PETSc */
42: #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */
43: #define PETSC_ERR_MEMC 78 /* memory corruption */
45: #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */
46: #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */
47: #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */
48: #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */
49: #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */
50: #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */
51: #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */
52: #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */
53: #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */
54: #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */
56: #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */
57: #define PETSC_ERR_FILE_READ 66 /* unable to read from file */
58: #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */
59: #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */
61: #define PETSC_ERR_KSP_BRKDWN 70 /* break down in a Krylov method */
63: #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */
64: #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */
66: #if defined(PETSC_USE_DEBUG)
70: #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
71: extern int __gierr;
72: #define _ __g
74: #endif
76: #else
77: #define SETERRQ(n,s) ;
78: #define SETERRQ1(n,s,a1) ;
79: #define SETERRQ2(n,s,a1,a2) ;
80: #define SETERRQ3(n,s,a1,a2,a3) ;
81: #define SETERRQ4(n,s,a1,a2,a3,a4) ;
83: #define CHKERRQ(n) ;
85: #define CHKMEMQ ;
87: #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
88: #define _
90: #endif
92: #endif
94: EXTERN int PetscErrorMessage(int,char**,char **);
95: EXTERN int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
96: EXTERN int PetscEmacsClientErrorHandler(int,char*,char*,char*,int,int,char*,void*);
97: EXTERN int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
98: EXTERN int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void*);
99: EXTERN int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
100: EXTERN int PetscError(int,char*,char*,char*,int,int,char*,...);
101: EXTERN int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
102: EXTERN int PetscPopErrorHandler(void);
103: EXTERN int PetscDefaultSignalHandler(int,void*);
104: EXTERN int PetscPushSignalHandler(int (*)(int,void *),void*);
105: EXTERN int PetscPopSignalHandler(void);
107: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
108: EXTERN int PetscSetFPTrap(PetscFPTrap);
110: /*
111: Allows the code to build a stack frame as it runs
112: */
113: #if defined(PETSC_USE_STACK)
115: #define PETSCSTACKSIZE 15
117: typedef struct {
118: char *function[PETSCSTACKSIZE];
119: char *file[PETSCSTACKSIZE];
120: char *directory[PETSCSTACKSIZE];
121: int line[PETSCSTACKSIZE];
122: int currentsize;
123: } PetscStack;
125: extern PetscStack *petscstack;
126: EXTERN int PetscStackCopy(PetscStack*,PetscStack*);
127: EXTERN int PetscStackPrint(PetscStack*,FILE* fp);
129: #define PetscStackActive (petscstack != 0)
131: #if !defined(PETSC_HAVE_AMS)
134: {
135: if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {
136: petscstack->file[petscstack->currentsize] = __FILE__;
137: petscstack->directory[petscstack->currentsize] = __SDIR__;
138: petscstack->line[petscstack->currentsize] = __LINE__;
139: petscstack->currentsize++;
140: }}
142: #define PetscStackPush(n)
143: {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {
144: petscstack->function[petscstack->currentsize] = n;
145: petscstack->file[petscstack->currentsize] = "unknown";
146: petscstack->directory[petscstack->currentsize] = "unknown";
147: petscstack->line[petscstack->currentsize] = 0;
148: petscstack->currentsize++;
149: }}
151: #define PetscStackPop
152: {if (petscstack && petscstack->currentsize > 0) {
153: petscstack->currentsize--;
154: petscstack->function[petscstack->currentsize] = 0;
155: petscstack->file[petscstack->currentsize] = 0;
156: petscstack->directory[petscstack->currentsize] = 0;
157: petscstack->line[petscstack->currentsize] = 0;
158: }};
160: #define PetscFunctionReturn(a)
161: {
162: PetscStackPop;
163: return(a);}
165: #define PetscFunctionReturnVoid()
166: {
167: PetscStackPop;}
169: #else
171: /*
172: Duplicate Code for when the ALICE Memory Snooper (AMS)
173: is being used. When PETSC_HAVE_AMS is defined.
175: stack_mem is the AMS memory that contains fields for the
176: number of stack frames and names of the stack frames
177: */
179: extern AMS_Memory stack_mem;
180: extern int stack_err;
183: {
184: if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {
185: if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);
186: petscstack->file[petscstack->currentsize] = __FILE__;
187: petscstack->directory[petscstack->currentsize] = __SDIR__;
188: petscstack->line[petscstack->currentsize] = __LINE__;
189: petscstack->currentsize++;
190: if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);
191: }}
193: #define PetscStackPush(n)
194: {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {
195: if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);
196: petscstack->function[petscstack->currentsize] = n;
197: petscstack->file[petscstack->currentsize] = "unknown";
198: petscstack->directory[petscstack->currentsize] = "unknown";
199: petscstack->line[petscstack->currentsize] = 0;
200: petscstack->currentsize++;
201: if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);
202: }}
204: #define PetscStackPop
205: {if (petscstack && petscstack->currentsize > 0) {
206: if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);
207: petscstack->currentsize--;
208: petscstack->function[petscstack->currentsize] = 0;
209: petscstack->file[petscstack->currentsize] = 0;
210: petscstack->directory[petscstack->currentsize] = 0;
211: petscstack->line[petscstack->currentsize] = 0;
212: if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);
213: }};
215: #define PetscFunctionReturn(a)
216: {
217: PetscStackPop;
218: return(a);}
220: #define PetscFunctionReturnVoid()
221: {
222: PetscStackPop;}
225: #endif
227: #else
230: #define PetscFunctionReturn(a) return(a)
231: #define PetscFunctionReturnVoid()
232: #define PetscStackPop
233: #define PetscStackPush(f)
234: #define PetscStackActive 0
236: #endif
238: EXTERN int PetscStackCreate(void);
239: EXTERN int PetscStackView(PetscViewer);
240: EXTERN int PetscStackDestroy(void);
241: EXTERN int PetscStackPublish(void);
242: EXTERN int PetscStackDepublish(void);
245: #endif