xref: /petsc/include/petscerror.h (revision 3a40ed3dce77c081171d005ae1a6ff4bb9d13b6f)
1*3a40ed3dSBarry Smith /* $Id: petscerror.h,v 1.13 1997/05/20 03:00:06 bsmith Exp bsmith $ */
254a8ef01SBarry Smith /*
34f227f7cSBarry Smith     Contains all error handling code for PETSc.
454a8ef01SBarry Smith */
545d48df9SBarry Smith #if !defined(__PETSCERROR_H)
645d48df9SBarry Smith #define __PETSCERROR_H
754a8ef01SBarry Smith 
8c22c1629SBarry Smith #include "petsc.h"
9c22c1629SBarry Smith 
1054a8ef01SBarry Smith /*
1154a8ef01SBarry Smith    Defines the directory where the compiled source is located; used
12c22c1629SBarry Smith    in printing error messages. __SDIR__ is usually defined in the makefile.
1354a8ef01SBarry Smith */
14c22c1629SBarry Smith #if !defined(__SDIR__)
152ee1dbe0SBarry Smith #define __SDIR__ "unknowndirectory/"
1654a8ef01SBarry Smith #endif
1754a8ef01SBarry Smith 
1854a8ef01SBarry Smith /*
194f227f7cSBarry Smith    Defines the function where the compiled source is located; used
204f227f7cSBarry Smith    in printing error messages.
214f227f7cSBarry Smith */
225615d1e5SSatish Balay #if !defined(__FUNC__)
2394a9d846SBarry Smith #define __FUNC__ "unknownfunction"
244f227f7cSBarry Smith #endif
254f227f7cSBarry Smith 
264f227f7cSBarry Smith /*
2745d48df9SBarry Smith      These are the generic error codes. The same error code is used in
2845d48df9SBarry Smith      many different places in the code.
2945d48df9SBarry Smith 
3045d48df9SBarry Smith      In addition, each specific error in the code has an error
31126a7499SLois Curfman McInnes      message: a specific, unique error code.  (The specific error
32126a7499SLois Curfman McInnes      code is not yet in use; these will be generated automatically and
334f227f7cSBarry Smith      embed an integer into the PetscError() calls. For non-English
344f227f7cSBarry Smith      error messages that integer will be extracted and used to look up the
354f227f7cSBarry Smith      appropriate error message in the local language from a file.)
3645d48df9SBarry Smith 
3754a8ef01SBarry Smith */
3845d48df9SBarry Smith #define PETSC_ERR_MEM             55   /* unable to allocate requested memory */
3947794344SBarry Smith #define PETSC_ERR_SUP             56   /* no support for requested operation */
4045d48df9SBarry Smith #define PETSC_ERR_SIG             59   /* signal received */
41f1caa5a4SBarry Smith #define PETSC_ERR_FP              72   /* floating point exception */
4245d48df9SBarry Smith 
4345d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ         60   /* nonconforming object sizes used in operation */
4445d48df9SBarry Smith #define PETSC_ERR_ARG_IDN         61   /* two arguments not allowed to be the same */
4545d48df9SBarry Smith #define PETSC_ERR_ARG_WRONG       62   /* wrong object (but object probably ok) */
4645d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT     64   /* null or corrupted PETSc object as argument */
4745d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE  63   /* input argument, out of range */
484f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR      68   /* invalid pointer argument */
494f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE 69   /* two args must be same object type */
50d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE  73   /* object in argument is in wrong state, e.g. unassembled mat */
514f227f7cSBarry Smith 
524f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN       65   /* unable to open file */
534f227f7cSBarry Smith #define PETSC_ERR_FILE_READ       66   /* unable to read from file */
544f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE      67   /* unable to write to file */
5545d48df9SBarry Smith 
5645d48df9SBarry Smith #define PETSC_ERR_KSP_BRKDWN      70   /* Break down in a Krylov method */
574f227f7cSBarry Smith 
5845d48df9SBarry Smith #define PETSC_ERR_MAT_LU_ZRPVT    71   /* Detected a zero pivot during LU factorization */
5945d48df9SBarry Smith #define PETSC_ERR_MAT_CH_ZRPVT    71   /* Detected a zero pivot during Cholesky factorization */
6054a8ef01SBarry Smith 
61*3a40ed3dSBarry Smith #if defined(USE_PETSC_DEBUG)
62c22c1629SBarry Smith #define SETERRQ(n,p,s) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);}
63c22c1629SBarry Smith #define SETERRA(n,p,s) {int _ierr = PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);\
6454a8ef01SBarry Smith                           MPI_Abort(PETSC_COMM_WORLD,_ierr);}
65e3372554SBarry Smith #define CHKERRQ(n)     {if (n) SETERRQ(n,0,(char *)0);}
66e3372554SBarry Smith #define CHKERRA(n)     {if (n) SETERRA(n,0,(char *)0);}
67e3372554SBarry Smith #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,0,(char*)0);
68e3372554SBarry Smith #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,0,(char*)0);
6954a8ef01SBarry Smith #else
70e3372554SBarry Smith #define SETERRQ(n,p,s) ;
71e3372554SBarry Smith #define SETERRA(n,p,s) ;
724f227f7cSBarry Smith #define CHKERRQ(n)     ;
734f227f7cSBarry Smith #define CHKERRA(n)     ;
744f227f7cSBarry Smith #define CHKPTRQ(p)     ;
754f227f7cSBarry Smith #define CHKPTRA(p)     ;
7654a8ef01SBarry Smith #endif
7754a8ef01SBarry Smith 
78e3372554SBarry Smith extern int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
79e3372554SBarry Smith extern int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
80e3372554SBarry Smith extern int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void* );
81e3372554SBarry Smith extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
82e3372554SBarry Smith extern int PetscError(int,char*,char*,char*,int,int,char*);
83e3372554SBarry Smith extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
8454a8ef01SBarry Smith extern int PetscPopErrorHandler();
8554a8ef01SBarry Smith 
8654a8ef01SBarry Smith extern int PetscDefaultSignalHandler(int,void*);
8754a8ef01SBarry Smith extern int PetscPushSignalHandler(int (*)(int,void *),void*);
8854a8ef01SBarry Smith extern int PetscPopSignalHandler();
8954a8ef01SBarry Smith #define PETSC_FP_TRAP_OFF    0
9054a8ef01SBarry Smith #define PETSC_FP_TRAP_ON     1
9154a8ef01SBarry Smith extern int PetscSetFPTrap(int);
920513a670SBarry Smith extern int PetscInitializeNans(Scalar*,int);
930513a670SBarry Smith extern int PetscInitializeLargeInts(int *,int);
9454a8ef01SBarry Smith 
95*3a40ed3dSBarry Smith /*
96*3a40ed3dSBarry Smith       Allows the code to build a stack frame as it runs
97*3a40ed3dSBarry Smith */
98*3a40ed3dSBarry Smith #if defined(USE_PETSC_STACK)
99*3a40ed3dSBarry Smith 
100*3a40ed3dSBarry Smith typedef struct  {
101*3a40ed3dSBarry Smith   char *function;
102*3a40ed3dSBarry Smith   char *file;
103*3a40ed3dSBarry Smith   char *directory;
104*3a40ed3dSBarry Smith   int  line;
105*3a40ed3dSBarry Smith } PetscStack;
106*3a40ed3dSBarry Smith 
107*3a40ed3dSBarry Smith extern int        petscstacksize_max;
108*3a40ed3dSBarry Smith extern int        petscstacksize;
109*3a40ed3dSBarry Smith extern PetscStack *petscstack;
110*3a40ed3dSBarry Smith 
111*3a40ed3dSBarry Smith #define PetscFunctionBegin \
112*3a40ed3dSBarry Smith   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
113*3a40ed3dSBarry Smith     petscstack[petscstacksize].function  = __FUNC__; \
114*3a40ed3dSBarry Smith     petscstack[petscstacksize].file      = __FILE__; \
115*3a40ed3dSBarry Smith     petscstack[petscstacksize].directory = __SDIR__;  \
116*3a40ed3dSBarry Smith     petscstack[petscstacksize].line      = __LINE__; \
117*3a40ed3dSBarry Smith     petscstacksize++; \
118*3a40ed3dSBarry Smith   }}
119*3a40ed3dSBarry Smith 
120*3a40ed3dSBarry Smith #define PetscFunctionReturn(a) \
121*3a40ed3dSBarry Smith   {if (petscstack && petscstacksize > 0) {    \
122*3a40ed3dSBarry Smith     petscstacksize--; \
123*3a40ed3dSBarry Smith   } \
124*3a40ed3dSBarry Smith   return(a);}
125*3a40ed3dSBarry Smith 
126*3a40ed3dSBarry Smith #else
127*3a40ed3dSBarry Smith 
128*3a40ed3dSBarry Smith #define PetscFunctionBegin
129*3a40ed3dSBarry Smith #define PetscFunctionReturn(a)  return(a)
130*3a40ed3dSBarry Smith 
131*3a40ed3dSBarry Smith #endif
132*3a40ed3dSBarry Smith 
133*3a40ed3dSBarry Smith extern int PetscStackCreate(int);
134*3a40ed3dSBarry Smith extern int PetscStackView(Viewer);
135*3a40ed3dSBarry Smith extern int PetscStackDestroy();
136*3a40ed3dSBarry Smith extern int PetscStackPop();
137*3a40ed3dSBarry Smith 
13854a8ef01SBarry Smith #endif
139