xref: /petsc/include/petscerror.h (revision 3a40ed3dce77c081171d005ae1a6ff4bb9d13b6f)
1 /* $Id: petscerror.h,v 1.13 1997/05/20 03:00:06 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 /*
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. The same error code is used in
28      many different places in the 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 
43 #define PETSC_ERR_ARG_SIZ         60   /* nonconforming object sizes used in operation */
44 #define PETSC_ERR_ARG_IDN         61   /* two arguments not allowed to be the same */
45 #define PETSC_ERR_ARG_WRONG       62   /* wrong object (but object probably ok) */
46 #define PETSC_ERR_ARG_CORRUPT     64   /* null or corrupted PETSc object as argument */
47 #define PETSC_ERR_ARG_OUTOFRANGE  63   /* input argument, out of range */
48 #define PETSC_ERR_ARG_BADPTR      68   /* invalid pointer argument */
49 #define PETSC_ERR_ARG_NOTSAMETYPE 69   /* two args must be same object type */
50 #define PETSC_ERR_ARG_WRONGSTATE  73   /* object in argument is in wrong state, e.g. unassembled mat */
51 
52 #define PETSC_ERR_FILE_OPEN       65   /* unable to open file */
53 #define PETSC_ERR_FILE_READ       66   /* unable to read from file */
54 #define PETSC_ERR_FILE_WRITE      67   /* unable to write to file */
55 
56 #define PETSC_ERR_KSP_BRKDWN      70   /* Break down in a Krylov method */
57 
58 #define PETSC_ERR_MAT_LU_ZRPVT    71   /* Detected a zero pivot during LU factorization */
59 #define PETSC_ERR_MAT_CH_ZRPVT    71   /* Detected a zero pivot during Cholesky factorization */
60 
61 #if defined(USE_PETSC_DEBUG)
62 #define SETERRQ(n,p,s) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);}
63 #define SETERRA(n,p,s) {int _ierr = PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);\
64                           MPI_Abort(PETSC_COMM_WORLD,_ierr);}
65 #define CHKERRQ(n)     {if (n) SETERRQ(n,0,(char *)0);}
66 #define CHKERRA(n)     {if (n) SETERRA(n,0,(char *)0);}
67 #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,0,(char*)0);
68 #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,0,(char*)0);
69 #else
70 #define SETERRQ(n,p,s) ;
71 #define SETERRA(n,p,s) ;
72 #define CHKERRQ(n)     ;
73 #define CHKERRA(n)     ;
74 #define CHKPTRQ(p)     ;
75 #define CHKPTRA(p)     ;
76 #endif
77 
78 extern int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
79 extern int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
80 extern int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void* );
81 extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
82 extern int PetscError(int,char*,char*,char*,int,int,char*);
83 extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
84 extern int PetscPopErrorHandler();
85 
86 extern int PetscDefaultSignalHandler(int,void*);
87 extern int PetscPushSignalHandler(int (*)(int,void *),void*);
88 extern int PetscPopSignalHandler();
89 #define PETSC_FP_TRAP_OFF    0
90 #define PETSC_FP_TRAP_ON     1
91 extern int PetscSetFPTrap(int);
92 extern int PetscInitializeNans(Scalar*,int);
93 extern int PetscInitializeLargeInts(int *,int);
94 
95 /*
96       Allows the code to build a stack frame as it runs
97 */
98 #if defined(USE_PETSC_STACK)
99 
100 typedef struct  {
101   char *function;
102   char *file;
103   char *directory;
104   int  line;
105 } PetscStack;
106 
107 extern int        petscstacksize_max;
108 extern int        petscstacksize;
109 extern PetscStack *petscstack;
110 
111 #define PetscFunctionBegin \
112   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
113     petscstack[petscstacksize].function  = __FUNC__; \
114     petscstack[petscstacksize].file      = __FILE__; \
115     petscstack[petscstacksize].directory = __SDIR__;  \
116     petscstack[petscstacksize].line      = __LINE__; \
117     petscstacksize++; \
118   }}
119 
120 #define PetscFunctionReturn(a) \
121   {if (petscstack && petscstacksize > 0) {    \
122     petscstacksize--; \
123   } \
124   return(a);}
125 
126 #else
127 
128 #define PetscFunctionBegin
129 #define PetscFunctionReturn(a)  return(a)
130 
131 #endif
132 
133 extern int PetscStackCreate(int);
134 extern int PetscStackView(Viewer);
135 extern int PetscStackDestroy();
136 extern int PetscStackPop();
137 
138 #endif
139