xref: /petsc/include/petscerror.h (revision 44bdcb2d3326b2ce09a36bf9b6840bc8773a5d60)
1 /* $Id: petscerror.h,v 1.18 1998/04/09 04:19:44 bsmith Exp curfman $ */
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 /*
11    Defines the directory where the compiled source is located; used
12    in printing error messages. __SDIR__ is usually defined in the makefile.
13 */
14 #if !defined(__SDIR__)
15 #define __SDIR__ "unknowndirectory/"
16 #endif
17 
18 /*
19    Defines the function where the compiled source is located; used
20    in printing error messages.
21 */
22 #if !defined(__FUNC__)
23 #define __FUNC__ "unknownfunction"
24 #endif
25 
26 /*
27      These are the generic error codes. These error codes are used
28      many different places in the PETSc source code.
29 
30      In addition, each specific error in the code has an error
31      message: a specific, unique error code.  (The specific error
32      code is not yet in use; these will be generated automatically and
33      embed an integer into the PetscError() calls. For non-English
34      error messages, that integer will be extracted and used to look up the
35      appropriate error message in the local language from a file.)
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_WRONGSTATE  73   /* object in argument is in wrong state, e.g. unassembled mat */
55 #define PETSC_ERR_ARG_INCOMP      75   /* two arguments are incompatible */
56 
57 #define PETSC_ERR_FILE_OPEN       65   /* unable to open file */
58 #define PETSC_ERR_FILE_READ       66   /* unable to read from file */
59 #define PETSC_ERR_FILE_WRITE      67   /* unable to write to file */
60 #define PETSC_ERR_FILE_UNEXPECTED 79   /* unexpected data in file */
61 
62 #define PETSC_ERR_KSP_BRKDWN      70   /* break down in a Krylov method */
63 
64 #define PETSC_ERR_MAT_LU_ZRPVT    71   /* detected a zero pivot during LU factorization */
65 #define PETSC_ERR_MAT_CH_ZRPVT    71   /* detected a zero pivot during Cholesky factorization */
66 
67 #if defined(USE_PETSC_DEBUG)
68 #define SETERRQ(n,p,s) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);}
69 #define SETERRA(n,p,s) {int _ierr = PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);\
70                           MPI_Abort(PETSC_COMM_WORLD,_ierr);}
71 #define CHKERRQ(n)     {if (n) SETERRQ(n,0,(char *)0);}
72 #define CHKERRA(n)     {if (n) SETERRA(n,0,(char *)0);}
73 #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,0,(char*)0);
74 #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,0,(char*)0);
75 #else
76 #define SETERRQ(n,p,s) ;
77 #define SETERRA(n,p,s) ;
78 #define CHKERRQ(n)     ;
79 #define CHKERRA(n)     ;
80 #define CHKPTRQ(p)     ;
81 #define CHKPTRA(p)     ;
82 #endif
83 
84 extern int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
85 extern int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
86 extern int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void* );
87 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
88 extern int PetscError(int,char*,char*,char*,int,int,char*);
89 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
90 extern int PetscPopErrorHandler(void);
91 
92 extern int PetscDefaultSignalHandler(int,void*);
93 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
94 extern int PetscPopSignalHandler(void);
95 #define PETSC_FP_TRAP_OFF    0
96 #define PETSC_FP_TRAP_ON     1
97 extern int PetscSetFPTrap(int);
98 extern int PetscInitializeNans(Scalar*,int);
99 extern int PetscInitializeLargeInts(int *,int);
100 
101 /*
102       Allows the code to build a stack frame as it runs
103 */
104 #if defined(USE_PETSC_STACK)
105 
106 typedef struct  {
107   char **function;
108   char **file;
109   char **directory;
110   int  *line;
111 } PetscStack;
112 
113 extern int        petscstacksize_max;
114 extern int        petscstacksize;
115 extern PetscStack *petscstack;
116 
117 #define PetscFunctionBegin \
118   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
119     petscstack->function[petscstacksize]  = __FUNC__; \
120     petscstack->file[petscstacksize]      = __FILE__; \
121     petscstack->directory[petscstacksize] = __SDIR__;  \
122     petscstack->line[petscstacksize]      = __LINE__; \
123     petscstacksize++; \
124   }}
125 
126 #define PetscStackPush(n) \
127   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
128     petscstack->function[petscstacksize]  = n; \
129     petscstack->file[petscstacksize]      = 0; \
130     petscstack->directory[petscstacksize] = 0;  \
131     petscstack->line[petscstacksize]      = 0; \
132     petscstacksize++; \
133   }}
134 
135 #define PetscStackPop \
136   {if (petscstack && petscstacksize > 0) {    \
137     petscstacksize--; \
138     petscstack->function[petscstacksize]  = 0; \
139     petscstack->file[petscstacksize]      = 0; \
140     petscstack->directory[petscstacksize] = 0;  \
141     petscstack->line[petscstacksize]      = 0; \
142   }};
143 
144 #define PetscFunctionReturn(a) \
145   {PetscStackPop; \
146   return(a);}
147 
148 #define PetscStackActive (petscstack != 0)
149 
150 #else
151 
152 #define PetscFunctionBegin
153 #define PetscFunctionReturn(a)  return(a)
154 #define PetscStackPop
155 #define PetscStackPush(f)
156 #define PetscStackActive        0
157 
158 #endif
159 
160 extern int PetscStackCreate(int);
161 extern int PetscStackView(Viewer);
162 extern int PetscStackDestroy(void);
163 
164 #endif
165