Actual source code: petscerror.h

  1: /* $Id: petscerror.h,v 1.59 2001/09/07 20:13:16 bsmith Exp $ */
  2: /*
  3:     Contains all error handling code for PETSc.
  4: */

 8:  #include petsc.h

 10: #if defined(PETSC_HAVE_AMS)
 11: #include "ams.h"
 12: #endif

 14: /*
 15:    Defines the directory where the compiled source is located; used
 16:    in printing error messages. Each makefile has an entry 
 17:    LOCDIR          =  thedirectory
 18:    and bmake/common_variables includes in CCPPFLAGS -D__SDIR__='"${LOCDIR}"'
 19:    which is a flag passed to the C/C++ compilers.
 20: */
 23: #endif

 25: /*
 26:    Defines the function where the compiled source is located; used 
 27:    in printing error messages.
 28: */
 29: #endif

 31: /* 
 32:      These are the generic error codes. These error codes are used
 33:      many different places in the PETSc source code.

 35: */
 36: #define PETSC_ERR_MEM             55   /* unable to allocate requested memory */
 37: #define PETSC_ERR_SUP             56   /* no support for requested operation */
 38: #define PETSC_ERR_SIG             59   /* signal received */
 39: #define PETSC_ERR_FP              72   /* floating point exception */
 40: #define PETSC_ERR_COR             74   /* corrupted PETSc object */
 41: #define PETSC_ERR_LIB             76   /* error in library called by PETSc */
 42: #define PETSC_ERR_PLIB            77   /* PETSc library generated inconsistent data */
 43: #define PETSC_ERR_MEMC            78   /* memory corruption */
 44: #define PETSC_ERR_MAX_ITER        82   /* Maximum iterations reached */

 46: #define PETSC_ERR_ARG_SIZ         60   /* nonconforming object sizes used in operation */
 47: #define PETSC_ERR_ARG_IDN         61   /* two arguments not allowed to be the same */
 48: #define PETSC_ERR_ARG_WRONG       62   /* wrong argument (but object probably ok) */
 49: #define PETSC_ERR_ARG_CORRUPT     64   /* null or corrupted PETSc object as argument */
 50: #define PETSC_ERR_ARG_OUTOFRANGE  63   /* input argument, out of range */
 51: #define PETSC_ERR_ARG_BADPTR      68   /* invalid pointer argument */
 52: #define PETSC_ERR_ARG_NOTSAMETYPE 69   /* two args must be same object type */
 53: #define PETSC_ERR_ARG_NOTSAMECOMM 80   /* two args must be same communicators */
 54: #define PETSC_ERR_ARG_WRONGSTATE  73   /* object in argument is in wrong state, e.g. unassembled mat */
 55: #define PETSC_ERR_ARG_INCOMP      75   /* two arguments are incompatible */

 57: #define PETSC_ERR_FILE_OPEN       65   /* unable to open file */
 58: #define PETSC_ERR_FILE_READ       66   /* unable to read from file */
 59: #define PETSC_ERR_FILE_WRITE      67   /* unable to write to file */
 60: #define PETSC_ERR_FILE_UNEXPECTED 79   /* unexpected data in file */

 62: #define PETSC_ERR_KSP_BRKDWN      70   /* break down in a Krylov method */

 64: #define PETSC_ERR_MAT_LU_ZRPVT    71   /* detected a zero pivot during LU factorization */
 65: #define PETSC_ERR_MAT_CH_ZRPVT    81   /* detected a zero pivot during Cholesky factorization */

 67: #define PETSC_ERR_MESH_NULL_ELEM  84   /* Element had no interior */

 69: #define PETSC_ERR_DISC_SING_JAC   83   /* Singular element Jacobian */

 71: #if defined(PETSC_USE_DEBUG)



 75: #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
 76: extern  int __gierr;
 77: #define _   __g
 79: #endif

 81: #else
 82: #define SETERRQ(n,s) ;
 83: #define SETERRQ1(n,s,a1) ;
 84: #define SETERRQ2(n,s,a1,a2) ;
 85: #define SETERRQ3(n,s,a1,a2,a3) ;
 86: #define SETERRQ4(n,s,a1,a2,a3,a4) ;
 87: #define SETERRABORT(comm,n,s) ;

 89: #define CHKERRQ(n)     ;
 90: #define CHKERRABORT(comm,n) ;
 91: #define CHKERRCONTINUE(n) ;

 93: #define CHKMEMQ        ;

 95: #if !defined(PETSC_SKIP_UNDERSCORE_CHKERR)
 96: #define _   
 98: #endif 

100: #endif

102: EXTERN int PetscErrorMessage(int,char**,char **);
103: EXTERN int PetscTraceBackErrorHandler(int,char*,char*,char*,int,int,char*,void*);
104: EXTERN int PetscIgnoreErrorHandler(int,char*,char*,char*,int,int,char*,void*);
105: EXTERN int PetscEmacsClientErrorHandler(int,char*,char*,char*,int,int,char*,void*);
106: EXTERN int PetscStopErrorHandler(int,char*,char*,char*,int,int,char*,void*);
107: EXTERN int PetscAbortErrorHandler(int,char*,char*,char*,int,int,char*,void*);
108: EXTERN int PetscAttachDebuggerErrorHandler(int,char*,char*,char*,int,int,char*,void*);
109: EXTERN int PetscError(int,char*,char*,char*,int,int,char*,...) PETSC_PRINTF_FORMAT_CHECK(7,8);
110: EXTERN int PetscPushErrorHandler(int (*handler)(int,char*,char*,char*,int,int,char*,void*),void*);
111: EXTERN int PetscPopErrorHandler(void);
112: EXTERN int PetscDefaultSignalHandler(int,void*);
113: EXTERN int PetscPushSignalHandler(int (*)(int,void *),void*);
114: EXTERN int PetscPopSignalHandler(void);

116: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
117: EXTERN int PetscSetFPTrap(PetscFPTrap);

119: /*
120:       Allows the code to build a stack frame as it runs
121: */
122: #if defined(PETSC_USE_STACK)

124: #define PETSCSTACKSIZE 15

126: typedef struct  {
127:   char *function[PETSCSTACKSIZE];
128:   char *file[PETSCSTACKSIZE];
129:   char *directory[PETSCSTACKSIZE];
130:   int  line[PETSCSTACKSIZE];
131:   int  currentsize;
132: } PetscStack;

134: extern PetscStack *petscstack;
135: EXTERN int PetscStackCopy(PetscStack*,PetscStack*);
136: EXTERN int PetscStackPrint(PetscStack*,FILE* fp);

138: #define PetscStackActive (petscstack != 0)

140: #if !defined(PETSC_HAVE_AMS)

143:   {
144:    if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    
145:     petscstack->file[petscstack->currentsize]      = __FILE__; 
146:     petscstack->directory[petscstack->currentsize] = __SDIR__; 
147:     petscstack->line[petscstack->currentsize]      = __LINE__; 
148:     petscstack->currentsize++; 
149:   }}

151: #define PetscStackPush(n) 
152:   {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    
153:     petscstack->function[petscstack->currentsize]  = n; 
154:     petscstack->file[petscstack->currentsize]      = "unknown"; 
155:     petscstack->directory[petscstack->currentsize] = "unknown"; 
156:     petscstack->line[petscstack->currentsize]      = 0; 
157:     petscstack->currentsize++; 
158:   }}

160: #define PetscStackPop 
161:   {if (petscstack && petscstack->currentsize > 0) {     
162:     petscstack->currentsize--; 
163:     petscstack->function[petscstack->currentsize]  = 0; 
164:     petscstack->file[petscstack->currentsize]      = 0; 
165:     petscstack->directory[petscstack->currentsize] = 0; 
166:     petscstack->line[petscstack->currentsize]      = 0; 
167:   }};

169: #define PetscFunctionReturn(a) 
170:   {
171:   PetscStackPop; 
172:   return(a);}

174: #define PetscFunctionReturnVoid() 
175:   {
176:   PetscStackPop; 
177:   return;}

179: #else

181: /*
182:     Duplicate Code for when the ALICE Memory Snooper (AMS)
183:   is being used. When PETSC_HAVE_AMS is defined.

185:      stack_mem is the AMS memory that contains fields for the 
186:                number of stack frames and names of the stack frames
187: */

189: extern AMS_Memory stack_mem;
190: extern int        stack_err;

193:   {
194:    if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    
195:     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);
196:     petscstack->file[petscstack->currentsize]      = __FILE__; 
197:     petscstack->directory[petscstack->currentsize] = __SDIR__; 
198:     petscstack->line[petscstack->currentsize]      = __LINE__; 
199:     petscstack->currentsize++; 
200:     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);
201:   }}

203: #define PetscStackPush(n) 
204:   {if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {    
205:     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);
206:     petscstack->function[petscstack->currentsize]  = n; 
207:     petscstack->file[petscstack->currentsize]      = "unknown"; 
208:     petscstack->directory[petscstack->currentsize] = "unknown"; 
209:     petscstack->line[petscstack->currentsize]      = 0; 
210:     petscstack->currentsize++; 
211:     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);
212:   }}

214: #define PetscStackPop 
215:   {if (petscstack && petscstack->currentsize > 0) {     
216:     if (!(stack_mem < 0)) stack_err = AMS_Memory_take_access(stack_mem);
217:     petscstack->currentsize--; 
218:     petscstack->function[petscstack->currentsize]  = 0; 
219:     petscstack->file[petscstack->currentsize]      = 0; 
220:     petscstack->directory[petscstack->currentsize] = 0; 
221:     petscstack->line[petscstack->currentsize]      = 0; 
222:     if (!(stack_mem < 0)) stack_err = AMS_Memory_grant_access(stack_mem);
223:   }};

225: #define PetscFunctionReturn(a) 
226:   {
227:   PetscStackPop; 
228:   return(a);}

230: #define PetscFunctionReturnVoid() 
231:   {
232:   PetscStackPop; 
233:   return;}


236: #endif

238: #else

241: #define PetscFunctionReturn(a)  return(a)
242: #define PetscFunctionReturnVoid() return()
243: #define PetscStackPop 
244: #define PetscStackPush(f) 
245: #define PetscStackActive        0

247: #endif

249: EXTERN int PetscStackCreate(void);
250: EXTERN int PetscStackView(PetscViewer);
251: EXTERN int PetscStackDestroy(void);
252: EXTERN int PetscStackPublish(void);
253: EXTERN int PetscStackDepublish(void);


256: #endif