Actual source code: petscerror.h
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: */
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: */
31: #endif
33: /*
34: These are the generic error codes. These error codes are used
35: many different places in the PETSc source code.
37: */
38: #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */
39: #define PETSC_ERR_MEM_MALLOC_0 85 /* cannot malloc zero size */
40: #define PETSC_ERR_SUP 56 /* no support for requested operation */
41: #define PETSC_ERR_SIG 59 /* signal received */
42: #define PETSC_ERR_FP 72 /* floating point exception */
43: #define PETSC_ERR_COR 74 /* corrupted PETSc object */
44: #define PETSC_ERR_LIB 76 /* error in library called by PETSc */
45: #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */
46: #define PETSC_ERR_MEMC 78 /* memory corruption */
47: #define PETSC_ERR_MAX_ITER 82 /* Maximum iterations reached */
49: #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */
50: #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */
51: #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */
52: #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */
53: #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */
54: #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */
55: #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */
56: #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */
57: #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */
58: #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */
60: #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */
61: #define PETSC_ERR_FILE_READ 66 /* unable to read from file */
62: #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */
63: #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */
65: #define PETSC_ERR_KSP_BRKDWN 70 /* break down in a Krylov method */
67: #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */
68: #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */
70: #define PETSC_ERR_MESH_NULL_ELEM 84 /* Element had no interior */
72: #define PETSC_ERR_DISC_SING_JAC 83 /* Singular element Jacobian */
74: #if defined(PETSC_USE_DEBUG)
75: #define SETERRQ(n,s) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);}
76: #define SETERRQ1(n,s,a1) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1);}
77: #define SETERRQ2(n,s,a1,a2) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2);}
78: #define SETERRQ3(n,s,a1,a2,a3) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3);}
79: #define SETERRQ4(n,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4);}
80: #define SETERRQ5(n,s,a1,a2,a3,a4,a5) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s,a1,a2,a3,a4,a5);}
81: #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);}
82: #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);}
83: #define SETERRABORT(comm,n,s) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);MPI_Abort(com,n);}
85: #define CHKERRQ(n) if (n) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");}
86: #define CHKERRABORT(comm,n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");MPI_Abort(comm,n);}
87: #define CHKERRCONTINUE(n) if (n) {PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,0," ");}
89: #define CHKMEMQ {int _7_PetscTrValid(__LINE__,__FUNCT__,__FILE__,__SDIR__);CHKERRQ(_7_ierr);}
91: #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
92: extern int __gierr;
93: #define _ __g
95: #endif
97: #else
98: #define SETERRQ(n,s) ;
99: #define SETERRQ1(n,s,a1) ;
100: #define SETERRQ2(n,s,a1,a2) ;
101: #define SETERRQ3(n,s,a1,a2,a3) ;
102: #define SETERRQ4(n,s,a1,a2,a3,a4) ;
103: #define SETERRABORT(comm,n,s) ;
105: #define CHKERRQ(n) ;
106: #define CHKERRABORT(comm,n) ;
107: #define CHKERRCONTINUE(n) ;
109: #define CHKMEMQ ;
111: #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
112: #define _
114: #endif
116: #endif
118: EXTERN int PetscErrorMessage(int,char**,char **);
119: EXTERN int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
120: EXTERN int PetscIgnoreErrorHandler(int,char*,char*,char*,int,int,char*,void*);
121: EXTERN int PetscEmacsClientErrorHandler(int,char*,char*,char*,int,int,char*,void*);
122: EXTERN int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
123: EXTERN int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void*);
124: EXTERN int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
125: EXTERN int PetscError(int,char*,char*,char*,int,int,char*,...) PETSC_PRINTF_FORMAT_CHECK(7,8);
126: EXTERN int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
127: EXTERN int PetscPopErrorHandler(void);
128: EXTERN int PetscDefaultSignalHandler(int,void*);
129: EXTERN int PetscPushSignalHandler(int (*)(int,void *),void*);
130: EXTERN int PetscPopSignalHandler(void);
132: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
133: EXTERN int PetscSetFPTrap(PetscFPTrap);
135: /*
136: Allows the code to build a stack frame as it runs
137: */
138: #if defined(PETSC_USE_STACK)
140: #define PETSCSTACKSIZE 15
142: typedef struct {
143: char *function[PETSCSTACKSIZE];
144: char *file[PETSCSTACKSIZE];
145: char *directory[PETSCSTACKSIZE];
146: int line[PETSCSTACKSIZE];
147: int currentsize;
148: } PetscStack;
150: extern PetscStack *petscstack;
151: EXTERN int PetscStackCopy(PetscStack*,PetscStack*);
152: EXTERN int PetscStackPrint(PetscStack*,FILE* fp);
154: #define PetscStackActive (petscstack != 0)
156: #if !defined(PETSC_HAVE_AMS)
159: {
160: if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {
161: petscstack->function[petscstack->currentsize] = __FUNCT__;
162: petscstack->file[petscstack->currentsize] = __FILE__;
163: petscstack->directory[petscstack->currentsize] = __SDIR__;
164: petscstack->line[petscstack->currentsize] = __LINE__;
165: petscstack->currentsize++;
166: }}
168: #define PetscStackPush(n)
169: {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {
170: petscstack->function[petscstack->currentsize] = n;
171: petscstack->file[petscstack->currentsize] = "unknown";
172: petscstack->directory[petscstack->currentsize] = "unknown";
173: petscstack->line[petscstack->currentsize] = 0;
174: petscstack->currentsize++;
175: }}
177: #define PetscStackPop
178: {if (petscstack && petscstack->currentsize > 0) {
179: petscstack->currentsize--;
180: petscstack->function[petscstack->currentsize] = 0;
181: petscstack->file[petscstack->currentsize] = 0;
182: petscstack->directory[petscstack->currentsize] = 0;
183: petscstack->line[petscstack->currentsize] = 0;
184: }};
186: #define PetscFunctionReturn(a)
187: {
188: PetscStackPop;
189: return(a);}
191: #define PetscFunctionReturnVoid()
192: {
193: PetscStackPop;
194: return;}
196: #else
198: /*
199: Duplicate Code for when the ALICE Memory Snooper (AMS)
200: is being used. When PETSC_HAVE_AMS is defined.
202: stack_mem is the AMS memory that contains fields for the
203: number of stack frames and names of the stack frames
204: */
206: extern AMS_Memory stack_mem;
207: extern int stack_err;
210: {
211: if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {
212: if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);
213: petscstack->function[petscstack->currentsize] = __FUNCT__;
214: petscstack->file[petscstack->currentsize] = __FILE__;
215: petscstack->directory[petscstack->currentsize] = __SDIR__;
216: petscstack->line[petscstack->currentsize] = __LINE__;
217: petscstack->currentsize++;
218: if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);
219: }}
221: #define PetscStackPush(n)
222: {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {
223: if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);
224: petscstack->function[petscstack->currentsize] = n;
225: petscstack->file[petscstack->currentsize] = "unknown";
226: petscstack->directory[petscstack->currentsize] = "unknown";
227: petscstack->line[petscstack->currentsize] = 0;
228: petscstack->currentsize++;
229: if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);
230: }}
232: #define PetscStackPop
233: {if (petscstack && petscstack->currentsize > 0) {
234: if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);
235: petscstack->currentsize--;
236: petscstack->function[petscstack->currentsize] = 0;
237: petscstack->file[petscstack->currentsize] = 0;
238: petscstack->directory[petscstack->currentsize] = 0;
239: petscstack->line[petscstack->currentsize] = 0;
240: if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);
241: }};
243: #define PetscFunctionReturn(a)
244: {
245: PetscStackPop;
246: return(a);}
248: #define PetscFunctionReturnVoid()
249: {
250: PetscStackPop;
251: return;}
254: #endif
256: #else
259: #define PetscFunctionReturn(a) return(a)
260: #define PetscFunctionReturnVoid() return()
261: #define PetscStackPop
262: #define PetscStackPush(f)
263: #define PetscStackActive 0
265: #endif
267: EXTERN int PetscStackCreate(void);
268: EXTERN int PetscStackView(PetscViewer);
269: EXTERN int PetscStackDestroy(void);
270: EXTERN int PetscStackPublish(void);
271: EXTERN int PetscStackDepublish(void);
274: #endif