Actual source code: errtrace.c

  1: /*$Id: errtrace.c,v 1.25 2001/06/21 21:15:22 bsmith Exp $*/

 3:  #include petsc.h


  8: /*@C
  9:    PetscIgnoreErrorHandler - Ignores the error, allows program to continue as if error did not occure

 11:    Not Collective

 13:    Input Parameters:
 14: +  line - the line number of the error (indicated by __LINE__)
 15: .  func - the function where error is detected (indicated by __FUNCT__)
 16: .  file - the file in which the error was detected (indicated by __FILE__)
 17: .  dir - the directory of the file (indicated by __SDIR__)
 18: .  mess - an error text string, usually just printed to the screen
 19: .  n - the generic error number
 20: .  p - specific error number
 21: -  ctx - error handler context

 23:    Level: developer

 25:    Notes:
 26:    Most users need not directly employ this routine and the other error 
 27:    handlers, but can instead use the simplified interface SETERRQ, which has 
 28:    the calling sequence
 29: $     SETERRQ(number,p,mess)

 31:    Notes for experienced users:
 32:    Use PetscPushErrorHandler() to set the desired error handler.  The
 33:    currently available PETSc error handlers include PetscTraceBackErrorHandler(),
 34:    PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler(), and PetscStopErrorHandler()

 36:    Concepts: error handler^traceback
 37:    Concepts: traceback^generating

 39: .seealso:  PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(), 
 40:           PetscAbortErrorHandler(), PetscTraceBackErrorHandler()
 41:  @*/
 42: int PetscIgnoreErrorHandler(int line,const char *fun,const char* file,const char *dir,int n,int p,const char *mess,void *ctx)
 43: {
 45:   PetscFunctionReturn(n);
 46: }


 51: /*@C

 53:    PetscTraceBackErrorHandler - Default error handler routine that generates
 54:    a traceback on error detection.

 56:    Not Collective

 58:    Input Parameters:
 59: +  line - the line number of the error (indicated by __LINE__)
 60: .  func - the function where error is detected (indicated by __FUNCT__)
 61: .  file - the file in which the error was detected (indicated by __FILE__)
 62: .  dir - the directory of the file (indicated by __SDIR__)
 63: .  mess - an error text string, usually just printed to the screen
 64: .  n - the generic error number
 65: .  p - specific error number
 66: -  ctx - error handler context

 68:    Level: developer

 70:    Notes:
 71:    Most users need not directly employ this routine and the other error 
 72:    handlers, but can instead use the simplified interface SETERRQ, which has 
 73:    the calling sequence
 74: $     SETERRQ(number,p,mess)

 76:    Notes for experienced users:
 77:    Use PetscPushErrorHandler() to set the desired error handler.  The
 78:    currently available PETSc error handlers include PetscTraceBackErrorHandler(),
 79:    PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler(), and PetscStopErrorHandler()

 81:    Concepts: error handler^traceback
 82:    Concepts: traceback^generating

 84: .seealso:  PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(), 
 85:           PetscAbortErrorHandler()
 86:  @*/
 87: int PetscTraceBackErrorHandler(int line,const char *fun,const char* file,const char *dir,int n,int p,const char *mess,void *ctx)
 88: {
 89:   PetscLogDouble    mem,rss;
 90:   int               rank;
 91:   PetscTruth        flg1,flg2;

 94:   MPI_Comm_rank(MPI_COMM_WORLD,&rank);

 96:   (*PetscErrorPrintf)("[%d]PETSC ERROR: %s() line %d in %s%s\n",rank,fun,line,dir,file);
 97:   if (p == 1) {
 98:     if (n == PETSC_ERR_MEM) {
 99:       (*PetscErrorPrintf)("[%d]PETSC ERROR:   Out of memory. This could be due to allocating\n",rank);
100:       (*PetscErrorPrintf)("[%d]PETSC ERROR:   too large an object or bleeding by not properly\n",rank);
101:       (*PetscErrorPrintf)("[%d]PETSC ERROR:   destroying unneeded objects.\n",rank);
102:       PetscTrSpace(&mem,PETSC_NULL,PETSC_NULL);
103:       PetscGetResidentSetSize(&rss);
104:       PetscOptionsHasName(PETSC_NULL,"-trdump",&flg1);
105:       PetscOptionsHasName(PETSC_NULL,"-trmalloc_log",&flg2);
106:       if (flg2) {
107:         PetscTrLogDump(stdout);
108:       } else if (flg1) {
109:         (*PetscErrorPrintf)("[%d]PETSC ERROR:   Memory allocated %d Memory used by process %d\n",rank,(int)mem,(int)rss);
110:         PetscTrDump(stdout);
111:       } else {
112:         (*PetscErrorPrintf)("[%d]PETSC ERROR:   Memory allocated %d Memory used by process %d\n",rank,(int)mem,(int)rss);
113:         (*PetscErrorPrintf)("[%d]PETSC ERROR:   Try running with -trdump or -trmalloc_log for info.\n",rank);
114:       }
115:     } else {
116:         const char *text;
117:         PetscErrorMessage(n,&text,PETSC_NULL);
118:         if (text) (*PetscErrorPrintf)("[%d]PETSC ERROR:   %s!\n",rank,text);
119:     }
120:     if (mess) {
121:       (*PetscErrorPrintf)("[%d]PETSC ERROR:   %s!\n",rank,mess);
122:     }
123:   }
124:   PetscFunctionReturn(n);
125: }