xref: /petsc/include/petscerror.h (revision 329ffe3d5b84df072bb1bc61767f9f7a10081355)
1*329ffe3dSLois Curfman McInnes /* $Id: petscerror.h,v 1.18 1998/04/09 04:19:44 bsmith Exp curfman $ */
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 /*
27*329ffe3dSLois Curfman McInnes      These are the generic error codes. These error codes are used
28*329ffe3dSLois Curfman McInnes      many different places in the PETSc source 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
34*329ffe3dSLois Curfman McInnes      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 */
42a8c6a408SBarry Smith #define PETSC_ERR_COR             74   /* corrupted PETSc object */
43a8c6a408SBarry Smith #define PETSC_ERR_LIB             76   /* error in library called by PETSc */
44*329ffe3dSLois Curfman McInnes #define PETSC_ERR_PLIB            77   /* PETSc library generated inconsistent data */
45*329ffe3dSLois Curfman McInnes #define PETSC_ERR_MEMC            78   /* memory corruption */
4645d48df9SBarry Smith 
4745d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ         60   /* nonconforming object sizes used in operation */
4845d48df9SBarry Smith #define PETSC_ERR_ARG_IDN         61   /* two arguments not allowed to be the same */
49a8c6a408SBarry Smith #define PETSC_ERR_ARG_WRONG       62   /* wrong argument (but object probably ok) */
5045d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT     64   /* null or corrupted PETSc object as argument */
5145d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE  63   /* input argument, out of range */
524f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR      68   /* invalid pointer argument */
534f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE 69   /* two args must be same object type */
54d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE  73   /* object in argument is in wrong state, e.g. unassembled mat */
55a8c6a408SBarry Smith #define PETSC_ERR_ARG_INCOMP      75   /* two arguments are incompatible */
564f227f7cSBarry Smith 
574f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN       65   /* unable to open file */
584f227f7cSBarry Smith #define PETSC_ERR_FILE_READ       66   /* unable to read from file */
594f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE      67   /* unable to write to file */
60a8c6a408SBarry Smith #define PETSC_ERR_FILE_UNEXPECTED 79   /* unexpected data in file */
6145d48df9SBarry Smith 
62*329ffe3dSLois Curfman McInnes #define PETSC_ERR_KSP_BRKDWN      70   /* break down in a Krylov method */
634f227f7cSBarry Smith 
64*329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_LU_ZRPVT    71   /* detected a zero pivot during LU factorization */
65*329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_CH_ZRPVT    71   /* detected a zero pivot during Cholesky factorization */
6654a8ef01SBarry Smith 
673a40ed3dSBarry Smith #if defined(USE_PETSC_DEBUG)
68c22c1629SBarry Smith #define SETERRQ(n,p,s) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);}
69c22c1629SBarry Smith #define SETERRA(n,p,s) {int _ierr = PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);\
7054a8ef01SBarry Smith                           MPI_Abort(PETSC_COMM_WORLD,_ierr);}
71e3372554SBarry Smith #define CHKERRQ(n)     {if (n) SETERRQ(n,0,(char *)0);}
72e3372554SBarry Smith #define CHKERRA(n)     {if (n) SETERRA(n,0,(char *)0);}
73e3372554SBarry Smith #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,0,(char*)0);
74e3372554SBarry Smith #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,0,(char*)0);
7554a8ef01SBarry Smith #else
76e3372554SBarry Smith #define SETERRQ(n,p,s) ;
77e3372554SBarry Smith #define SETERRA(n,p,s) ;
784f227f7cSBarry Smith #define CHKERRQ(n)     ;
794f227f7cSBarry Smith #define CHKERRA(n)     ;
804f227f7cSBarry Smith #define CHKPTRQ(p)     ;
814f227f7cSBarry Smith #define CHKPTRA(p)     ;
8254a8ef01SBarry Smith #endif
8354a8ef01SBarry Smith 
84e3372554SBarry Smith extern int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
85e3372554SBarry Smith extern int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
86e3372554SBarry Smith extern int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void* );
87e3372554SBarry Smith extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
88e3372554SBarry Smith extern int PetscError(int,char*,char*,char*,int,int,char*);
89e3372554SBarry Smith extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
90cf256101SBarry Smith extern int PetscPopErrorHandler(void);
9154a8ef01SBarry Smith 
9254a8ef01SBarry Smith extern int PetscDefaultSignalHandler(int,void*);
9354a8ef01SBarry Smith extern int PetscPushSignalHandler(int (*)(int,void *),void*);
94cf256101SBarry Smith extern int PetscPopSignalHandler(void);
9554a8ef01SBarry Smith #define PETSC_FP_TRAP_OFF    0
9654a8ef01SBarry Smith #define PETSC_FP_TRAP_ON     1
9754a8ef01SBarry Smith extern int PetscSetFPTrap(int);
980513a670SBarry Smith extern int PetscInitializeNans(Scalar*,int);
990513a670SBarry Smith extern int PetscInitializeLargeInts(int *,int);
10054a8ef01SBarry Smith 
1013a40ed3dSBarry Smith /*
1023a40ed3dSBarry Smith       Allows the code to build a stack frame as it runs
1033a40ed3dSBarry Smith */
1043a40ed3dSBarry Smith #if defined(USE_PETSC_STACK)
1053a40ed3dSBarry Smith 
1063a40ed3dSBarry Smith typedef struct  {
1075cd90555SBarry Smith   char **function;
1085cd90555SBarry Smith   char **file;
1095cd90555SBarry Smith   char **directory;
1105cd90555SBarry Smith   int  *line;
1113a40ed3dSBarry Smith } PetscStack;
1123a40ed3dSBarry Smith 
1133a40ed3dSBarry Smith extern int        petscstacksize_max;
1143a40ed3dSBarry Smith extern int        petscstacksize;
1153a40ed3dSBarry Smith extern PetscStack *petscstack;
1163a40ed3dSBarry Smith 
1173a40ed3dSBarry Smith #define PetscFunctionBegin \
1183a40ed3dSBarry Smith   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
1195cd90555SBarry Smith     petscstack->function[petscstacksize]  = __FUNC__; \
1205cd90555SBarry Smith     petscstack->file[petscstacksize]      = __FILE__; \
1215cd90555SBarry Smith     petscstack->directory[petscstacksize] = __SDIR__;  \
1225cd90555SBarry Smith     petscstack->line[petscstacksize]      = __LINE__; \
1233a40ed3dSBarry Smith     petscstacksize++; \
1243a40ed3dSBarry Smith   }}
1253a40ed3dSBarry Smith 
1265cd90555SBarry Smith #define PetscStackPush(n) \
1275cd90555SBarry Smith   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
1285cd90555SBarry Smith     petscstack->function[petscstacksize]  = n; \
1295cd90555SBarry Smith     petscstack->file[petscstacksize]      = 0; \
1305cd90555SBarry Smith     petscstack->directory[petscstacksize] = 0;  \
1315cd90555SBarry Smith     petscstack->line[petscstacksize]      = 0; \
1325cd90555SBarry Smith     petscstacksize++; \
1335cd90555SBarry Smith   }}
1343a40ed3dSBarry Smith 
135d64ed03dSBarry Smith #define PetscStackPop \
1365cd90555SBarry Smith   {if (petscstack && petscstacksize > 0) {    \
1375cd90555SBarry Smith     petscstacksize--; \
1385cd90555SBarry Smith     petscstack->function[petscstacksize]  = 0; \
1395cd90555SBarry Smith     petscstack->file[petscstacksize]      = 0; \
1405cd90555SBarry Smith     petscstack->directory[petscstacksize] = 0;  \
1415cd90555SBarry Smith     petscstack->line[petscstacksize]      = 0; \
1425cd90555SBarry Smith   }};
143d64ed03dSBarry Smith 
1445cd90555SBarry Smith #define PetscFunctionReturn(a) \
1455cd90555SBarry Smith   {PetscStackPop; \
1465cd90555SBarry Smith   return(a);}
147d64ed03dSBarry Smith 
148d64ed03dSBarry Smith #define PetscStackActive (petscstack != 0)
149d64ed03dSBarry Smith 
1503a40ed3dSBarry Smith #else
1513a40ed3dSBarry Smith 
1523a40ed3dSBarry Smith #define PetscFunctionBegin
1533a40ed3dSBarry Smith #define PetscFunctionReturn(a)  return(a)
154d64ed03dSBarry Smith #define PetscStackPop
155d64ed03dSBarry Smith #define PetscStackPush(f)
156d64ed03dSBarry Smith #define PetscStackActive        0
1573a40ed3dSBarry Smith 
1583a40ed3dSBarry Smith #endif
1593a40ed3dSBarry Smith 
1603a40ed3dSBarry Smith extern int PetscStackCreate(int);
1613a40ed3dSBarry Smith extern int PetscStackView(Viewer);
162cf256101SBarry Smith extern int PetscStackDestroy(void);
1633a40ed3dSBarry Smith 
16454a8ef01SBarry Smith #endif
165