Actual source code: errtrace.c

      1: #define PETSC_DLL

     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: PetscErrorCode PETSC_DLLEXPORT PetscIgnoreErrorHandler(int line,const char *fun,const char* file,const char *dir,PetscErrorCode 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: PetscErrorCode PETSC_DLLEXPORT PetscTraceBackErrorHandler(int line,const char *fun,const char* file,const char *dir,PetscErrorCode n,int p,const char *mess,void *ctx)
     88: {
     89:   PetscLogDouble    mem,rss;
     90:   PetscTruth        flg1,flg2;

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