Actual source code: errtrace.c

  1: /*$Id: errtrace.c,v 1.24 2001/04/10 19:34:27 bsmith Exp $*/

  3: #include "petsc.h"           /*I "petsc.h" I*/

  5: static char *PetscErrorStrings[] = {
  6:   /*55 */ "Out of memory",
  7:           "No support for this operation for this object type",
  8:           "",
  9:   /*58 */ "",
 10:   /*59 */ "Signal received",
 11:   /*60 */  "Nonconforming object sizes",
 12:     "Argument aliasing not permitted",
 13:     "Invalid argument",
 14:   /*63 */    "Argument out of range",
 15:     "Null or corrupt argument",
 16:     "Unable to open file",
 17:     "Read from file failed",
 18:     "Write to file failed",
 19:     "Invalid pointer",
 20:   /*69 */      "Arguments must have same type",
 21:     "Detected breakdown in Krylov method",
 22:   /*71 */    "Detected zero pivot in LU factorization",
 23:   /*72 */    "Floating point exception",
 24:   /*73 */    "Object is in wrong state",
 25:     "Corrupted Petsc object",
 26:     "Arguments are incompatible",
 27:     "Error in external library",
 28:   /*77 */    "Petsc has generated inconsistent data",
 29:     "Memory corruption",
 30:     "Unexpected data in file",
 31:   /*80 */ "Arguments must have same communicators",
 32:   /*81 */ "Detected zero pivot in Cholesky factorization"};

 34: extern char PetscErrorBaseMessage[1024];

 36: /*@C
 37:    PetscErrorMessage - returns the text string associated with a PETSc error code.

 39:    Not Collective

 41:    Input Parameter:
 42: .   errnum - the error code

 44:    Output Parameter: 
 45: +  text - the error message (PETSC_NULL if not desired) 
 46: -  specific - the specific error message that was set with SETERRxxx() or PetscError().  (PETSC_NULL if not desired) 

 48:    Level: developer

 50:    Concepts: error handler^messages

 52: .seealso:  PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(), 
 53:           PetscAbortErrorHandler(), PetscTraceBackErrorHandler()
 54:  @*/
 55: int PetscErrorMessage(int errnum,char **text,char **specific)
 56: {
 58:   if (text && errnum >= PETSC_ERR_MEM && errnum <= PETSC_ERR_MAT_CH_ZRPVT) {
 59:     *text = PetscErrorStrings[errnum-PETSC_ERR_MEM];
 60:   } else if (text) *text = 0;

 62:   if (specific) {
 63:     *specific = PetscErrorBaseMessage;
 64:   }
 65:   return(0);
 66: }


 69: /*@C
 70:    PetscTraceBackErrorHandler - Default error handler routine that generates
 71:    a traceback on error detection.

 73:    Not Collective

 75:    Input Parameters:
 76: +  line - the line number of the error (indicated by __LINE__)
 77: .  file - the file in which the error was detected (indicated by __FILE__)
 78: .  dir - the directory of the file (indicated by __SDIR__)
 79: .  mess - an error text string, usually just printed to the screen
 80: .  n - the generic error number
 81: .  p - specific error number
 82: -  ctx - error handler context

 84:    Level: developer

 86:    Notes:
 87:    Most users need not directly employ this routine and the other error 
 88:    handlers, but can instead use the simplified interface SETERRQ, which has 
 89:    the calling sequence
 90: $     SETERRQ(number,p,mess)

 92:    Notes for experienced users:
 93:    Use PetscPushErrorHandler() to set the desired error handler.  The
 94:    currently available PETSc error handlers include PetscTraceBackErrorHandler(),
 95:    PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler(), and PetscStopErrorHandler()

 97:    Concepts: error handler^traceback
 98:    Concepts: traceback^generating

100: .seealso:  PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(), 
101:           PetscAbortErrorHandler()
102:  @*/
103: int PetscTraceBackErrorHandler(int line,char *fun,char* file,char *dir,int n,int p,char *mess,void *ctx)
104: {
105:   PetscLogDouble    mem,rss;
106:   int               rank;
107:   PetscTruth        flg1,flg2;

110:   MPI_Comm_rank(MPI_COMM_WORLD,&rank);

112:   (*PetscErrorPrintf)("[%d]PETSC ERROR: %s() line %d in %s%sn",rank,fun,line,dir,file);
113:   if (p == 1) {
114:     if (n == PETSC_ERR_MEM) {
115:       (*PetscErrorPrintf)("[%d]PETSC ERROR:   Out of memory. This could be due to allocatingn",rank);
116:       (*PetscErrorPrintf)("[%d]PETSC ERROR:   too large an object or bleeding by not properlyn",rank);
117:       (*PetscErrorPrintf)("[%d]PETSC ERROR:   destroying unneeded objects.n",rank);
118:       PetscTrSpace(&mem,PETSC_NULL,PETSC_NULL);
119:       PetscGetResidentSetSize(&rss);
120:       PetscOptionsHasName(PETSC_NULL,"-trdump",&flg1);
121:       PetscOptionsHasName(PETSC_NULL,"-trmalloc_log",&flg2);
122:       if (flg2) {
123:         PetscTrLogDump(stdout);
124:       } else if (flg1) {
125:         (*PetscErrorPrintf)("[%d]PETSC ERROR:   Memory allocated %d Memory used by process %dn",rank,(int)mem,(int)rss);
126:         PetscTrDump(stdout);
127:       } else {
128:         (*PetscErrorPrintf)("[%d]PETSC ERROR:   Memory allocated %d Memory used by process %dn",rank,(int)mem,(int)rss);
129:         (*PetscErrorPrintf)("[%d]PETSC ERROR:   Try running with -trdump or -trmalloc_log for info.n",rank);
130:       }
131:     } else {
132:         char *text;
133:         PetscErrorMessage(n,&text,PETSC_NULL);
134:         if (text) (*PetscErrorPrintf)("[%d]PETSC ERROR:   %s!n",rank,text);
135:     }
136:     if (mess) {
137:       (*PetscErrorPrintf)("[%d]PETSC ERROR:   %s!n",rank,mess);
138:     }
139:   }
140:   PetscFunctionReturn(n);
141: }