xref: /petsc/src/sys/error/errtrace.c (revision f5ad10bcaccd2325c4d8965282b288be8a09912f)
1 #define PETSC_DLL
2 
3 #include "petsc.h"           /*I "petsc.h" I*/
4 
5 
6 #undef __FUNCT__
7 #define __FUNCT__ "PetscIgnoreErrorHandler"
8 /*@C
9    PetscIgnoreErrorHandler - Ignores the error, allows program to continue as if error did not occure
10 
11    Not Collective
12 
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
22 
23    Level: developer
24 
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)
30 
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()
35 
36    Concepts: error handler^traceback
37    Concepts: traceback^generating
38 
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 {
44   PetscFunctionBegin;
45   PetscFunctionReturn(n);
46 }
47 
48 
49 #undef __FUNCT__
50 #define __FUNCT__ "PetscTraceBackErrorHandler"
51 /*@C
52 
53    PetscTraceBackErrorHandler - Default error handler routine that generates
54    a traceback on error detection.
55 
56    Not Collective
57 
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
67 
68    Level: developer
69 
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)
75 
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()
80 
81    Concepts: error handler^traceback
82    Concepts: traceback^generating
83 
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;
91 
92   PetscFunctionBegin;
93 
94   if (p == 1) {
95     (*PetscErrorPrintf)("--------------- Error Message --------------\n");
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     (*PetscErrorPrintf)("--------------------------------------------\n");
123   }
124   (*PetscErrorPrintf)("%s() line %d in %s%s\n",fun,line,dir,file);
125   PetscFunctionReturn(n);
126 }
127 
128