xref: /petsc/include/petscerror.h (revision b707bbf75cc3274e79cd1f90f52be59b33e8fb44)
1*b707bbf7SBarry Smith /* $Id: petscerror.h,v 1.33 1999/06/30 22:52:56 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 
10aa482453SBarry Smith #if defined(PETSC_HAVE_AMS)
116d385327SIbrahima Ba #include "ams.h"
126d385327SIbrahima Ba #endif
136d385327SIbrahima 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 
74aa482453SBarry Smith #if defined(PETSC_USE_DEBUG)
75c22c1629SBarry Smith #define SETERRA(n,p,s) {int _ierr = PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);\
76fdb4a956SSatish Balay                           MPI_Abort(PETSC_COMM_WORLD,_ierr);}
779a00fa46SSatish Balay #define SETERRQ(n,p,s)              {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s);}
789a00fa46SSatish Balay #define SETERRQ1(n,p,s,a1)          {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s,a1);}
799a00fa46SSatish Balay #define SETERRQ2(n,p,s,a1,a2)       {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s,a1,a2);}
809a00fa46SSatish Balay #define SETERRQ3(n,p,s,a1,a2,a3)    {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s,a1,a2,a3);}
819a00fa46SSatish Balay #define SETERRQ4(n,p,s,a1,a2,a3,a4) {return PetscError(__LINE__,__FUNC__,__FILE__,__SDIR__,n,p,s,a1,a2,a3,a4);}
829a00fa46SSatish Balay 
83e3372554SBarry Smith #define CHKERRQ(n)     {if (n) SETERRQ(n,0,(char *)0);}
84e3372554SBarry Smith #define CHKERRA(n)     {if (n) SETERRA(n,0,(char *)0);}
85e3372554SBarry Smith #define CHKPTRQ(p)     if (!p) SETERRQ(PETSC_ERR_MEM,0,(char*)0);
86e3372554SBarry Smith #define CHKPTRA(p)     if (!p) SETERRA(PETSC_ERR_MEM,0,(char*)0);
8785614651SBarry Smith 
8885614651SBarry Smith #define CHKMEMQ {int __ierr = PetscTrValid(__LINE__,__FUNC__,__FILE__,__SDIR__); CHKERRQ(__ierr);}
8985614651SBarry Smith #define CHKMEMA {int __ierr = PetscTrValid(__LINE__,__FUNC__,__FILE__,__SDIR__); CHKERRA(__ierr);}
9085614651SBarry Smith 
9154a8ef01SBarry Smith #else
92e3372554SBarry Smith #define SETERRQ(n,p,s) ;
93cf949a74SBarry Smith #define SETERRQ1(n,p,s,a1) ;
94cf949a74SBarry Smith #define SETERRQ2(n,p,s,a1,a2) ;
95cf949a74SBarry Smith #define SETERRQ3(n,p,s,a1,a2,a3) ;
96cf949a74SBarry Smith #define SETERRQ4(n,p,s,a1,a2,a3,a4) ;
97e3372554SBarry Smith #define SETERRA(n,p,s) ;
9885614651SBarry Smith 
994f227f7cSBarry Smith #define CHKERRQ(n)     ;
1004f227f7cSBarry Smith #define CHKERRA(n)     ;
1014f227f7cSBarry Smith #define CHKPTRQ(p)     ;
1024f227f7cSBarry Smith #define CHKPTRA(p)     ;
10385614651SBarry Smith 
10485614651SBarry Smith #define CHKMEMQ        ;
10585614651SBarry Smith #define CHKMEMA        ;
10685614651SBarry Smith 
10754a8ef01SBarry Smith #endif
10854a8ef01SBarry Smith 
109e3372554SBarry Smith extern int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
110e3372554SBarry Smith extern int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
111e3372554SBarry Smith extern int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void* );
112e3372554SBarry Smith extern int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
1139a00fa46SSatish Balay extern int PetscError(int,char*,char*,char*,int,int,char*,...);
114e3372554SBarry Smith extern int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
115cf256101SBarry Smith extern int PetscPopErrorHandler(void);
11654a8ef01SBarry Smith 
11754a8ef01SBarry Smith extern int PetscDefaultSignalHandler(int,void*);
11854a8ef01SBarry Smith extern int PetscPushSignalHandler(int (*)(int,void *),void*);
119cf256101SBarry Smith extern int PetscPopSignalHandler(void);
12054a8ef01SBarry Smith #define PETSC_FP_TRAP_OFF    0
12154a8ef01SBarry Smith #define PETSC_FP_TRAP_ON     1
12254a8ef01SBarry Smith extern int PetscSetFPTrap(int);
1230513a670SBarry Smith extern int PetscInitializeNans(Scalar*,int);
1240513a670SBarry Smith extern int PetscInitializeLargeInts(int *,int);
12554a8ef01SBarry Smith 
1263a40ed3dSBarry Smith /*
1273a40ed3dSBarry Smith       Allows the code to build a stack frame as it runs
1283a40ed3dSBarry Smith */
129aa482453SBarry Smith #if defined(PETSC_USE_STACK)
1303a40ed3dSBarry Smith 
1313a40ed3dSBarry Smith typedef struct  {
1325cd90555SBarry Smith   char **function;
1335cd90555SBarry Smith   char **file;
1345cd90555SBarry Smith   char **directory;
1355cd90555SBarry Smith   int  *line;
1363a40ed3dSBarry Smith } PetscStack;
1373a40ed3dSBarry Smith 
1383a40ed3dSBarry Smith extern int        petscstacksize_max;
1393a40ed3dSBarry Smith extern int        petscstacksize;
1403a40ed3dSBarry Smith extern PetscStack *petscstack;
1413a40ed3dSBarry Smith 
142aa482453SBarry Smith #if !defined(PETSC_HAVE_AMS)
1436d385327SIbrahima Ba 
1443a40ed3dSBarry Smith #define PetscFunctionBegin \
145beb17490SBarry Smith   {\
14606d1fe2cSBarry Smith    if (petscstack && (petscstacksize < petscstacksize_max)) {    \
1475cd90555SBarry Smith     petscstack->function[petscstacksize]  = __FUNC__; \
1485cd90555SBarry Smith     petscstack->file[petscstacksize]      = __FILE__; \
1495cd90555SBarry Smith     petscstack->directory[petscstacksize] = __SDIR__; \
1505cd90555SBarry Smith     petscstack->line[petscstacksize]      = __LINE__; \
1513a40ed3dSBarry Smith     petscstacksize++; \
1523a40ed3dSBarry Smith   }}
1533a40ed3dSBarry Smith 
1545cd90555SBarry Smith #define PetscStackPush(n) \
1555cd90555SBarry Smith   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
1565cd90555SBarry Smith     petscstack->function[petscstacksize]  = n; \
1572e8a6d31SBarry Smith     petscstack->file[petscstacksize]      = "unknown"; \
1582e8a6d31SBarry Smith     petscstack->directory[petscstacksize] = "unknown"; \
1595cd90555SBarry Smith     petscstack->line[petscstacksize]      = 0; \
1605cd90555SBarry Smith     petscstacksize++; \
1615cd90555SBarry Smith   }}
1623a40ed3dSBarry Smith 
163d64ed03dSBarry Smith #define PetscStackPop \
1645cd90555SBarry Smith   {if (petscstack && petscstacksize > 0) {     \
1655cd90555SBarry Smith     petscstacksize--; \
1665cd90555SBarry Smith     petscstack->function[petscstacksize]  = 0; \
1675cd90555SBarry Smith     petscstack->file[petscstacksize]      = 0; \
1685cd90555SBarry Smith     petscstack->directory[petscstacksize] = 0; \
1695cd90555SBarry Smith     petscstack->line[petscstacksize]      = 0; \
1705cd90555SBarry Smith   }};
171d64ed03dSBarry Smith 
1725cd90555SBarry Smith #define PetscFunctionReturn(a) \
173beb17490SBarry Smith   {\
17406d1fe2cSBarry Smith   PetscStackPop; \
1755cd90555SBarry Smith   return(a);}
176d64ed03dSBarry Smith 
177d64ed03dSBarry Smith #define PetscStackActive (petscstack != 0)
178d64ed03dSBarry Smith 
1793a40ed3dSBarry Smith #else
1803a40ed3dSBarry Smith 
18106d1fe2cSBarry Smith /*
18206d1fe2cSBarry Smith     Duplicate Code for when the ALICE Memory Snooper (AMS)
183aa482453SBarry Smith   is being used. When PETSC_HAVE_AMS is defined.
18406d1fe2cSBarry Smith 
18506d1fe2cSBarry Smith      stack_mem is the AMS memory that contains fields for the
18606d1fe2cSBarry Smith                number of stack frames and names of the stack frames
18706d1fe2cSBarry Smith */
18806d1fe2cSBarry Smith 
1896d385327SIbrahima Ba extern AMS_Memory stack_mem;
19006d1fe2cSBarry Smith extern int        stack_err;
1916d385327SIbrahima Ba 
1926d385327SIbrahima Ba #define PetscFunctionBegin \
193beb17490SBarry Smith   {\
19406d1fe2cSBarry Smith    if (petscstack && (petscstacksize < petscstacksize_max)) {    \
19506d1fe2cSBarry Smith     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
1966d385327SIbrahima Ba     petscstack->function[petscstacksize]  = __FUNC__; \
1976d385327SIbrahima Ba     petscstack->file[petscstacksize]      = __FILE__; \
1986d385327SIbrahima Ba     petscstack->directory[petscstacksize] = __SDIR__; \
1996d385327SIbrahima Ba     petscstack->line[petscstacksize]      = __LINE__; \
2006d385327SIbrahima Ba     petscstacksize++; \
20106d1fe2cSBarry Smith     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
2026d385327SIbrahima Ba   }}
2036d385327SIbrahima Ba 
2046d385327SIbrahima Ba #define PetscStackPush(n) \
2056d385327SIbrahima Ba   {if (petscstack && (petscstacksize < petscstacksize_max)) {    \
20606d1fe2cSBarry Smith     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
2076d385327SIbrahima Ba     petscstack->function[petscstacksize]  = n; \
2082e8a6d31SBarry Smith     petscstack->file[petscstacksize]      = "unknown"; \
2092e8a6d31SBarry Smith     petscstack->directory[petscstacksize] = "unknown"; \
2106d385327SIbrahima Ba     petscstack->line[petscstacksize]      = 0; \
2116d385327SIbrahima Ba     petscstacksize++; \
21206d1fe2cSBarry Smith     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
2136d385327SIbrahima Ba   }}
2146d385327SIbrahima Ba 
2156d385327SIbrahima Ba #define PetscStackPop \
2166d385327SIbrahima Ba   {if (petscstack && petscstacksize > 0) {     \
21706d1fe2cSBarry Smith     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);\
2186d385327SIbrahima Ba     petscstacksize--; \
2196d385327SIbrahima Ba     petscstack->function[petscstacksize]  = 0; \
2206d385327SIbrahima Ba     petscstack->file[petscstacksize]      = 0; \
2216d385327SIbrahima Ba     petscstack->directory[petscstacksize] = 0; \
2226d385327SIbrahima Ba     petscstack->line[petscstacksize]      = 0; \
22306d1fe2cSBarry Smith     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);\
2246d385327SIbrahima Ba   }};
2256d385327SIbrahima Ba 
2266d385327SIbrahima Ba #define PetscFunctionReturn(a) \
227beb17490SBarry Smith   {\
22806d1fe2cSBarry Smith   PetscStackPop; \
2296d385327SIbrahima Ba   return(a);}
2306d385327SIbrahima Ba 
2316d385327SIbrahima Ba #define PetscStackActive (petscstack != 0)
2326d385327SIbrahima Ba 
2336d385327SIbrahima Ba #endif
2346d385327SIbrahima Ba 
2356d385327SIbrahima Ba #else
2366d385327SIbrahima Ba 
2373a40ed3dSBarry Smith #define PetscFunctionBegin
2383a40ed3dSBarry Smith #define PetscFunctionReturn(a)  return(a)
239d64ed03dSBarry Smith #define PetscStackPop
240d64ed03dSBarry Smith #define PetscStackPush(f)
241d64ed03dSBarry Smith #define PetscStackActive        0
2423a40ed3dSBarry Smith 
2433a40ed3dSBarry Smith #endif
2443a40ed3dSBarry Smith 
2453a40ed3dSBarry Smith extern int PetscStackCreate(int);
2463a40ed3dSBarry Smith extern int PetscStackView(Viewer);
247cf256101SBarry Smith extern int PetscStackDestroy(void);
248f2b01315SBarry Smith extern int PetscStackPublish(void);
249f2b01315SBarry Smith extern int PetscStackDepublish(void);
2503a40ed3dSBarry Smith 
25106d1fe2cSBarry Smith /*
252*b707bbf7SBarry Smith           For locking, unlocking and destroying AMS memories associated with
25306d1fe2cSBarry Smith     PETSc objects
25406d1fe2cSBarry Smith */
25506d1fe2cSBarry Smith 
256aa482453SBarry Smith #if defined(PETSC_HAVE_AMS)
25706d1fe2cSBarry Smith #define PetscAMSTakeAccess(obj)   \
25806d1fe2cSBarry Smith     ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_take_access(((PetscObject)(obj))->amem));
25906d1fe2cSBarry Smith #define PetscAMSGrantAccess(obj)  \
26006d1fe2cSBarry Smith     ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_grant_access(((PetscObject)(obj))->amem));
261*b707bbf7SBarry Smith #define PetscAMSDestroy(obj)  \
262*b707bbf7SBarry Smith     ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_destroy(((PetscObject)(obj))->amem));
26306d1fe2cSBarry Smith #else
26406d1fe2cSBarry Smith #define PetscAMSTakeAccess(obj)
26506d1fe2cSBarry Smith #define PetscAMSGrantAccess(obj)
266*b707bbf7SBarry Smith #define PetscAMSDestroy(obj)
26754a8ef01SBarry Smith #endif
26806d1fe2cSBarry Smith 
26906d1fe2cSBarry Smith #endif
27006d1fe2cSBarry Smith 
271