xref: /petsc/include/petscerror.h (revision 5e97870ef1e12764549367e251013179ad05aa16)
1*5e97870eSBarry Smith /* $Id: petscerror.h,v 1.20 1998/06/09 21:21:55 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
12*5e97870eSBarry Smith    in printing error messages. Each makefile has an entry
13*5e97870eSBarry Smith    LOCDIR	  =  thedirectory
14*5e97870eSBarry Smith    and bmake/common includes in CCPPFLAGS -D__SDIR__='"${LOCDIR}"'
15*5e97870eSBarry Smith    which is a flag passed to the C/C++ compilers.
1654a8ef01SBarry Smith */
17c22c1629SBarry Smith #if !defined(__SDIR__)
182ee1dbe0SBarry Smith #define __SDIR__ "unknowndirectory/"
1954a8ef01SBarry Smith #endif
2054a8ef01SBarry Smith 
2154a8ef01SBarry Smith /*
224f227f7cSBarry Smith    Defines the function where the compiled source is located; used
234f227f7cSBarry Smith    in printing error messages.
244f227f7cSBarry Smith */
255615d1e5SSatish Balay #if !defined(__FUNC__)
2694a9d846SBarry Smith #define __FUNC__ "unknownfunction"
274f227f7cSBarry Smith #endif
284f227f7cSBarry Smith 
294f227f7cSBarry Smith /*
30329ffe3dSLois Curfman McInnes      These are the generic error codes. These error codes are used
31329ffe3dSLois Curfman McInnes      many different places in the PETSc source code.
3245d48df9SBarry Smith 
3345d48df9SBarry Smith      In addition, each specific error in the code has an error
34126a7499SLois Curfman McInnes      message: a specific, unique error code.  (The specific error
35126a7499SLois Curfman McInnes      code is not yet in use; these will be generated automatically and
364f227f7cSBarry Smith      embed an integer into the PetscError() calls. For non-English
37329ffe3dSLois Curfman McInnes      error messages, that integer will be extracted and used to look up the
384f227f7cSBarry Smith      appropriate error message in the local language from a file.)
3945d48df9SBarry Smith 
4054a8ef01SBarry Smith */
4145d48df9SBarry Smith #define PETSC_ERR_MEM             55   /* unable to allocate requested memory */
4247794344SBarry Smith #define PETSC_ERR_SUP             56   /* no support for requested operation */
4345d48df9SBarry Smith #define PETSC_ERR_SIG             59   /* signal received */
44f1caa5a4SBarry Smith #define PETSC_ERR_FP              72   /* floating point exception */
45a8c6a408SBarry Smith #define PETSC_ERR_COR             74   /* corrupted PETSc object */
46a8c6a408SBarry Smith #define PETSC_ERR_LIB             76   /* error in library called by PETSc */
47329ffe3dSLois Curfman McInnes #define PETSC_ERR_PLIB            77   /* PETSc library generated inconsistent data */
48329ffe3dSLois Curfman McInnes #define PETSC_ERR_MEMC            78   /* memory corruption */
4945d48df9SBarry Smith 
5045d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ         60   /* nonconforming object sizes used in operation */
5145d48df9SBarry Smith #define PETSC_ERR_ARG_IDN         61   /* two arguments not allowed to be the same */
52a8c6a408SBarry Smith #define PETSC_ERR_ARG_WRONG       62   /* wrong argument (but object probably ok) */
5345d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT     64   /* null or corrupted PETSc object as argument */
5445d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE  63   /* input argument, out of range */
554f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR      68   /* invalid pointer argument */
564f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE 69   /* two args must be same object type */
57d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE  73   /* object in argument is in wrong state, e.g. unassembled mat */
58a8c6a408SBarry Smith #define PETSC_ERR_ARG_INCOMP      75   /* two arguments are incompatible */
594f227f7cSBarry Smith 
604f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN       65   /* unable to open file */
614f227f7cSBarry Smith #define PETSC_ERR_FILE_READ       66   /* unable to read from file */
624f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE      67   /* unable to write to file */
63a8c6a408SBarry Smith #define PETSC_ERR_FILE_UNEXPECTED 79   /* unexpected data in file */
6445d48df9SBarry Smith 
65329ffe3dSLois Curfman McInnes #define PETSC_ERR_KSP_BRKDWN      70   /* break down in a Krylov method */
664f227f7cSBarry Smith 
67329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_LU_ZRPVT    71   /* detected a zero pivot during LU factorization */
68329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_CH_ZRPVT    71   /* detected a zero pivot during Cholesky factorization */
6954a8ef01SBarry Smith 
703a40ed3dSBarry Smith #if defined(USE_PETSC_DEBUG)
71c22c1629SBarry Smith #define SETERRQ(n,p,s) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);}
72c22c1629SBarry Smith #define SETERRA(n,p,s) {int _ierr = PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);\
7354a8ef01SBarry Smith                           MPI_Abort(PETSC_COMM_WORLD,_ierr);}
74e3372554SBarry Smith #define CHKERRQ(n)     {if (n) SETERRQ(n,0,(char *)0);}
75e3372554SBarry Smith #define CHKERRA(n)     {if (n) SETERRA(n,0,(char *)0);}
76e3372554SBarry Smith #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,0,(char*)0);
77e3372554SBarry Smith #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,0,(char*)0);
7854a8ef01SBarry Smith #else
79e3372554SBarry Smith #define SETERRQ(n,p,s) ;
80e3372554SBarry Smith #define SETERRA(n,p,s) ;
814f227f7cSBarry Smith #define CHKERRQ(n)     ;
824f227f7cSBarry Smith #define CHKERRA(n)     ;
834f227f7cSBarry Smith #define CHKPTRQ(p)     ;
844f227f7cSBarry Smith #define CHKPTRA(p)     ;
8554a8ef01SBarry Smith #endif
8654a8ef01SBarry Smith 
87e3372554SBarry Smith extern int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
88e3372554SBarry Smith extern int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
89e3372554SBarry Smith extern int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void* );
90e3372554SBarry Smith extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
91e3372554SBarry Smith extern int PetscError(int,char*,char*,char*,int,int,char*);
92e3372554SBarry Smith extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
93cf256101SBarry Smith extern int PetscPopErrorHandler(void);
9454a8ef01SBarry Smith 
9554a8ef01SBarry Smith extern int PetscDefaultSignalHandler(int,void*);
9654a8ef01SBarry Smith extern int PetscPushSignalHandler(int (*)(int,void *),void*);
97cf256101SBarry Smith extern int PetscPopSignalHandler(void);
9854a8ef01SBarry Smith #define PETSC_FP_TRAP_OFF    0
9954a8ef01SBarry Smith #define PETSC_FP_TRAP_ON     1
10054a8ef01SBarry Smith extern int PetscSetFPTrap(int);
1010513a670SBarry Smith extern int PetscInitializeNans(Scalar*,int);
1020513a670SBarry Smith extern int PetscInitializeLargeInts(int *,int);
10354a8ef01SBarry Smith 
1043a40ed3dSBarry Smith /*
1053a40ed3dSBarry Smith       Allows the code to build a stack frame as it runs
1063a40ed3dSBarry Smith */
1073a40ed3dSBarry Smith #if defined(USE_PETSC_STACK)
1083a40ed3dSBarry Smith 
1093a40ed3dSBarry Smith typedef struct  {
1105cd90555SBarry Smith   char **function;
1115cd90555SBarry Smith   char **file;
1125cd90555SBarry Smith   char **directory;
1135cd90555SBarry Smith   int  *line;
1143a40ed3dSBarry Smith } PetscStack;
1153a40ed3dSBarry Smith 
1163a40ed3dSBarry Smith extern int        petscstacksize_max;
1173a40ed3dSBarry Smith extern int        petscstacksize;
1183a40ed3dSBarry Smith extern PetscStack *petscstack;
1193a40ed3dSBarry Smith 
1203a40ed3dSBarry Smith #define PetscFunctionBegin \
1213a40ed3dSBarry Smith   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
1225cd90555SBarry Smith     petscstack->function[petscstacksize]  = __FUNC__; \
1235cd90555SBarry Smith     petscstack->file[petscstacksize]      = __FILE__; \
1245cd90555SBarry Smith     petscstack->directory[petscstacksize] = __SDIR__; \
1255cd90555SBarry Smith     petscstack->line[petscstacksize]      = __LINE__; \
1263a40ed3dSBarry Smith     petscstacksize++; \
1273a40ed3dSBarry Smith   }}
1283a40ed3dSBarry Smith 
1295cd90555SBarry Smith #define PetscStackPush(n) \
1305cd90555SBarry Smith   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
1315cd90555SBarry Smith     petscstack->function[petscstacksize]  = n; \
1325cd90555SBarry Smith     petscstack->file[petscstacksize]      = 0; \
1335cd90555SBarry Smith     petscstack->directory[petscstacksize] = 0; \
1345cd90555SBarry Smith     petscstack->line[petscstacksize]      = 0; \
1355cd90555SBarry Smith     petscstacksize++; \
1365cd90555SBarry Smith   }}
1373a40ed3dSBarry Smith 
138d64ed03dSBarry Smith #define PetscStackPop \
1395cd90555SBarry Smith   {if (petscstack && petscstacksize > 0) {     \
1405cd90555SBarry Smith     petscstacksize--; \
1415cd90555SBarry Smith     petscstack->function[petscstacksize]  = 0; \
1425cd90555SBarry Smith     petscstack->file[petscstacksize]      = 0; \
1435cd90555SBarry Smith     petscstack->directory[petscstacksize] = 0; \
1445cd90555SBarry Smith     petscstack->line[petscstacksize]      = 0; \
1455cd90555SBarry Smith   }};
146d64ed03dSBarry Smith 
1475cd90555SBarry Smith #define PetscFunctionReturn(a) \
1485cd90555SBarry Smith   {PetscStackPop; \
1495cd90555SBarry Smith   return(a);}
150d64ed03dSBarry Smith 
151d64ed03dSBarry Smith #define PetscStackActive (petscstack != 0)
152d64ed03dSBarry Smith 
1533a40ed3dSBarry Smith #else
1543a40ed3dSBarry Smith 
1553a40ed3dSBarry Smith #define PetscFunctionBegin
1563a40ed3dSBarry Smith #define PetscFunctionReturn(a)  return(a)
157d64ed03dSBarry Smith #define PetscStackPop
158d64ed03dSBarry Smith #define PetscStackPush(f)
159d64ed03dSBarry Smith #define PetscStackActive        0
1603a40ed3dSBarry Smith 
1613a40ed3dSBarry Smith #endif
1623a40ed3dSBarry Smith 
1633a40ed3dSBarry Smith extern int PetscStackCreate(int);
1643a40ed3dSBarry Smith extern int PetscStackView(Viewer);
165cf256101SBarry Smith extern int PetscStackDestroy(void);
1663a40ed3dSBarry Smith 
16754a8ef01SBarry Smith #endif
168