xref: /petsc/include/petscerror.h (revision 6d385327d4a72452d0ed5002b1e487139f349caf)
1*6d385327SIbrahima Ba /* $Id: petscerror.h,v 1.21 1998/07/02 02:47:54 bsmith Exp ibrahba $ */
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 
10*6d385327SIbrahima Ba #if defined(HAVE_AMS)
11*6d385327SIbrahima Ba #include "ams.h"
12*6d385327SIbrahima Ba #endif
13*6d385327SIbrahima Ba 
1454a8ef01SBarry Smith /*
1554a8ef01SBarry Smith    Defines the directory where the compiled source is located; used
165e97870eSBarry Smith    in printing error messages. Each makefile has an entry
175e97870eSBarry Smith    LOCDIR	  =  thedirectory
185e97870eSBarry Smith    and bmake/common includes in CCPPFLAGS -D__SDIR__='"${LOCDIR}"'
195e97870eSBarry Smith    which is a flag passed to the C/C++ compilers.
2054a8ef01SBarry Smith */
21c22c1629SBarry Smith #if !defined(__SDIR__)
222ee1dbe0SBarry Smith #define __SDIR__ "unknowndirectory/"
2354a8ef01SBarry Smith #endif
2454a8ef01SBarry Smith 
2554a8ef01SBarry Smith /*
264f227f7cSBarry Smith    Defines the function where the compiled source is located; used
274f227f7cSBarry Smith    in printing error messages.
284f227f7cSBarry Smith */
295615d1e5SSatish Balay #if !defined(__FUNC__)
3094a9d846SBarry Smith #define __FUNC__ "unknownfunction"
314f227f7cSBarry Smith #endif
324f227f7cSBarry Smith 
334f227f7cSBarry Smith /*
34329ffe3dSLois Curfman McInnes      These are the generic error codes. These error codes are used
35329ffe3dSLois Curfman McInnes      many different places in the PETSc source code.
3645d48df9SBarry Smith 
3745d48df9SBarry Smith      In addition, each specific error in the code has an error
38126a7499SLois Curfman McInnes      message: a specific, unique error code.  (The specific error
39126a7499SLois Curfman McInnes      code is not yet in use; these will be generated automatically and
404f227f7cSBarry Smith      embed an integer into the PetscError() calls. For non-English
41329ffe3dSLois Curfman McInnes      error messages, that integer will be extracted and used to look up the
424f227f7cSBarry Smith      appropriate error message in the local language from a file.)
4345d48df9SBarry Smith 
4454a8ef01SBarry Smith */
4545d48df9SBarry Smith #define PETSC_ERR_MEM             55   /* unable to allocate requested memory */
4647794344SBarry Smith #define PETSC_ERR_SUP             56   /* no support for requested operation */
4745d48df9SBarry Smith #define PETSC_ERR_SIG             59   /* signal received */
48f1caa5a4SBarry Smith #define PETSC_ERR_FP              72   /* floating point exception */
49a8c6a408SBarry Smith #define PETSC_ERR_COR             74   /* corrupted PETSc object */
50a8c6a408SBarry Smith #define PETSC_ERR_LIB             76   /* error in library called by PETSc */
51329ffe3dSLois Curfman McInnes #define PETSC_ERR_PLIB            77   /* PETSc library generated inconsistent data */
52329ffe3dSLois Curfman McInnes #define PETSC_ERR_MEMC            78   /* memory corruption */
5345d48df9SBarry Smith 
5445d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ         60   /* nonconforming object sizes used in operation */
5545d48df9SBarry Smith #define PETSC_ERR_ARG_IDN         61   /* two arguments not allowed to be the same */
56a8c6a408SBarry Smith #define PETSC_ERR_ARG_WRONG       62   /* wrong argument (but object probably ok) */
5745d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT     64   /* null or corrupted PETSc object as argument */
5845d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE  63   /* input argument, out of range */
594f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR      68   /* invalid pointer argument */
604f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE 69   /* two args must be same object type */
61d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE  73   /* object in argument is in wrong state, e.g. unassembled mat */
62a8c6a408SBarry Smith #define PETSC_ERR_ARG_INCOMP      75   /* two arguments are incompatible */
634f227f7cSBarry Smith 
644f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN       65   /* unable to open file */
654f227f7cSBarry Smith #define PETSC_ERR_FILE_READ       66   /* unable to read from file */
664f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE      67   /* unable to write to file */
67a8c6a408SBarry Smith #define PETSC_ERR_FILE_UNEXPECTED 79   /* unexpected data in file */
6845d48df9SBarry Smith 
69329ffe3dSLois Curfman McInnes #define PETSC_ERR_KSP_BRKDWN      70   /* break down in a Krylov method */
704f227f7cSBarry Smith 
71329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_LU_ZRPVT    71   /* detected a zero pivot during LU factorization */
72329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_CH_ZRPVT    71   /* detected a zero pivot during Cholesky factorization */
7354a8ef01SBarry Smith 
743a40ed3dSBarry Smith #if defined(USE_PETSC_DEBUG)
75c22c1629SBarry Smith #define SETERRQ(n,p,s) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);}
76c22c1629SBarry Smith #define SETERRA(n,p,s) {int _ierr = PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);\
7754a8ef01SBarry Smith                           MPI_Abort(PETSC_COMM_WORLD,_ierr);}
78e3372554SBarry Smith #define CHKERRQ(n)     {if (n) SETERRQ(n,0,(char *)0);}
79e3372554SBarry Smith #define CHKERRA(n)     {if (n) SETERRA(n,0,(char *)0);}
80e3372554SBarry Smith #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,0,(char*)0);
81e3372554SBarry Smith #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,0,(char*)0);
8254a8ef01SBarry Smith #else
83e3372554SBarry Smith #define SETERRQ(n,p,s) ;
84e3372554SBarry Smith #define SETERRA(n,p,s) ;
854f227f7cSBarry Smith #define CHKERRQ(n)     ;
864f227f7cSBarry Smith #define CHKERRA(n)     ;
874f227f7cSBarry Smith #define CHKPTRQ(p)     ;
884f227f7cSBarry Smith #define CHKPTRA(p)     ;
8954a8ef01SBarry Smith #endif
9054a8ef01SBarry Smith 
91e3372554SBarry Smith extern int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
92e3372554SBarry Smith extern int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
93e3372554SBarry Smith extern int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void* );
94e3372554SBarry Smith extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
95e3372554SBarry Smith extern int PetscError(int,char*,char*,char*,int,int,char*);
96e3372554SBarry Smith extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
97cf256101SBarry Smith extern int PetscPopErrorHandler(void);
9854a8ef01SBarry Smith 
9954a8ef01SBarry Smith extern int PetscDefaultSignalHandler(int,void*);
10054a8ef01SBarry Smith extern int PetscPushSignalHandler(int (*)(int,void *),void*);
101cf256101SBarry Smith extern int PetscPopSignalHandler(void);
10254a8ef01SBarry Smith #define PETSC_FP_TRAP_OFF    0
10354a8ef01SBarry Smith #define PETSC_FP_TRAP_ON     1
10454a8ef01SBarry Smith extern int PetscSetFPTrap(int);
1050513a670SBarry Smith extern int PetscInitializeNans(Scalar*,int);
1060513a670SBarry Smith extern int PetscInitializeLargeInts(int *,int);
10754a8ef01SBarry Smith 
1083a40ed3dSBarry Smith /*
1093a40ed3dSBarry Smith       Allows the code to build a stack frame as it runs
1103a40ed3dSBarry Smith */
1113a40ed3dSBarry Smith #if defined(USE_PETSC_STACK)
1123a40ed3dSBarry Smith 
1133a40ed3dSBarry Smith typedef struct  {
1145cd90555SBarry Smith   char **function;
1155cd90555SBarry Smith   char **file;
1165cd90555SBarry Smith   char **directory;
1175cd90555SBarry Smith   int  *line;
1183a40ed3dSBarry Smith } PetscStack;
1193a40ed3dSBarry Smith 
1203a40ed3dSBarry Smith extern int        petscstacksize_max;
1213a40ed3dSBarry Smith extern int        petscstacksize;
1223a40ed3dSBarry Smith extern PetscStack *petscstack;
1233a40ed3dSBarry Smith 
124*6d385327SIbrahima Ba #if !defined(HAVE_AMS)
125*6d385327SIbrahima Ba 
1263a40ed3dSBarry Smith #define PetscFunctionBegin \
1273a40ed3dSBarry Smith   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
1285cd90555SBarry Smith     petscstack->function[petscstacksize]  = __FUNC__; \
1295cd90555SBarry Smith     petscstack->file[petscstacksize]      = __FILE__; \
1305cd90555SBarry Smith     petscstack->directory[petscstacksize] = __SDIR__; \
1315cd90555SBarry Smith     petscstack->line[petscstacksize]      = __LINE__; \
1323a40ed3dSBarry Smith     petscstacksize++; \
1333a40ed3dSBarry Smith   }}
1343a40ed3dSBarry Smith 
1355cd90555SBarry Smith #define PetscStackPush(n) \
1365cd90555SBarry Smith   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
1375cd90555SBarry Smith     petscstack->function[petscstacksize]  = n; \
1385cd90555SBarry Smith     petscstack->file[petscstacksize]      = 0; \
1395cd90555SBarry Smith     petscstack->directory[petscstacksize] = 0; \
1405cd90555SBarry Smith     petscstack->line[petscstacksize]      = 0; \
1415cd90555SBarry Smith     petscstacksize++; \
1425cd90555SBarry Smith   }}
1433a40ed3dSBarry Smith 
144d64ed03dSBarry Smith #define PetscStackPop \
1455cd90555SBarry Smith   {if (petscstack && petscstacksize > 0) {     \
1465cd90555SBarry Smith     petscstacksize--; \
1475cd90555SBarry Smith     petscstack->function[petscstacksize]  = 0; \
1485cd90555SBarry Smith     petscstack->file[petscstacksize]      = 0; \
1495cd90555SBarry Smith     petscstack->directory[petscstacksize] = 0; \
1505cd90555SBarry Smith     petscstack->line[petscstacksize]      = 0; \
1515cd90555SBarry Smith   }};
152d64ed03dSBarry Smith 
1535cd90555SBarry Smith #define PetscFunctionReturn(a) \
1545cd90555SBarry Smith   {PetscStackPop; \
1555cd90555SBarry Smith   return(a);}
156d64ed03dSBarry Smith 
157d64ed03dSBarry Smith #define PetscStackActive (petscstack != 0)
158d64ed03dSBarry Smith 
1593a40ed3dSBarry Smith #else
1603a40ed3dSBarry Smith 
161*6d385327SIbrahima Ba /* Duplicate Code for HAVE_AMS */
162*6d385327SIbrahima Ba extern AMS_Comm stack_comm;
163*6d385327SIbrahima Ba extern AMS_Memory stack_mem;
164*6d385327SIbrahima Ba extern stack_err;
165*6d385327SIbrahima Ba 
166*6d385327SIbrahima Ba #define PetscFunctionBegin \
167*6d385327SIbrahima Ba   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
168*6d385327SIbrahima Ba     if (!(stack_mem < 0)) \
169*6d385327SIbrahima Ba         stack_err = AMS_Memory_take_access(stack_mem);\
170*6d385327SIbrahima Ba     petscstack->function[petscstacksize]  = __FUNC__; \
171*6d385327SIbrahima Ba     petscstack->file[petscstacksize]      = __FILE__; \
172*6d385327SIbrahima Ba     petscstack->directory[petscstacksize] = __SDIR__; \
173*6d385327SIbrahima Ba     petscstack->line[petscstacksize]      = __LINE__; \
174*6d385327SIbrahima Ba     petscstacksize++; \
175*6d385327SIbrahima Ba     if (!(stack_mem < 0)) \
176*6d385327SIbrahima Ba         stack_err = AMS_Memory_grant_access(stack_mem);\
177*6d385327SIbrahima Ba   }}
178*6d385327SIbrahima Ba 
179*6d385327SIbrahima Ba #define PetscStackPush(n) \
180*6d385327SIbrahima Ba   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
181*6d385327SIbrahima Ba     if (!(stack_mem < 0)) \
182*6d385327SIbrahima Ba         stack_err = AMS_Memory_take_access(stack_mem);\
183*6d385327SIbrahima Ba     petscstack->function[petscstacksize]  = n; \
184*6d385327SIbrahima Ba     petscstack->file[petscstacksize]      = 0; \
185*6d385327SIbrahima Ba     petscstack->directory[petscstacksize] = 0; \
186*6d385327SIbrahima Ba     petscstack->line[petscstacksize]      = 0; \
187*6d385327SIbrahima Ba     petscstacksize++; \
188*6d385327SIbrahima Ba     if (!(stack_mem < 0)) \
189*6d385327SIbrahima Ba         stack_err = AMS_Memory_grant_access(stack_mem);\
190*6d385327SIbrahima Ba   }}
191*6d385327SIbrahima Ba 
192*6d385327SIbrahima Ba #define PetscStackPop \
193*6d385327SIbrahima Ba   {if (petscstack && petscstacksize > 0) {     \
194*6d385327SIbrahima Ba     if (!(stack_mem < 0)) \
195*6d385327SIbrahima Ba         stack_err = AMS_Memory_take_access(stack_mem);\
196*6d385327SIbrahima Ba     petscstacksize--; \
197*6d385327SIbrahima Ba     petscstack->function[petscstacksize]  = 0; \
198*6d385327SIbrahima Ba     petscstack->file[petscstacksize]      = 0; \
199*6d385327SIbrahima Ba     petscstack->directory[petscstacksize] = 0; \
200*6d385327SIbrahima Ba     petscstack->line[petscstacksize]      = 0; \
201*6d385327SIbrahima Ba     if (!(stack_mem < 0)) \
202*6d385327SIbrahima Ba         stack_err = AMS_Memory_grant_access(stack_mem);\
203*6d385327SIbrahima Ba   }};
204*6d385327SIbrahima Ba 
205*6d385327SIbrahima Ba #define PetscFunctionReturn(a) \
206*6d385327SIbrahima Ba   {PetscStackPop; \
207*6d385327SIbrahima Ba   return(a);}
208*6d385327SIbrahima Ba 
209*6d385327SIbrahima Ba #define PetscStackActive (petscstack != 0)
210*6d385327SIbrahima Ba 
211*6d385327SIbrahima Ba #endif
212*6d385327SIbrahima Ba 
213*6d385327SIbrahima Ba #else
214*6d385327SIbrahima Ba 
2153a40ed3dSBarry Smith #define PetscFunctionBegin
2163a40ed3dSBarry Smith #define PetscFunctionReturn(a)  return(a)
217d64ed03dSBarry Smith #define PetscStackPop
218d64ed03dSBarry Smith #define PetscStackPush(f)
219d64ed03dSBarry Smith #define PetscStackActive        0
2203a40ed3dSBarry Smith 
2213a40ed3dSBarry Smith #endif
2223a40ed3dSBarry Smith 
2233a40ed3dSBarry Smith extern int PetscStackCreate(int);
2243a40ed3dSBarry Smith extern int PetscStackView(Viewer);
225cf256101SBarry Smith extern int PetscStackDestroy(void);
2263a40ed3dSBarry Smith 
22754a8ef01SBarry Smith #endif
228