Actual source code: errtrace.c
1: #define PETSC_DLL
3: #include petscsys.h
4: #include "petscconfiginfo.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 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: }
48: /* ---------------------------------------------------------------------------------------*/
50: static char arch[10],hostname[64],username[16],pname[PETSC_MAX_PATH_LEN],date[64];
51: static PetscTruth PetscErrorPrintfInitializeCalled = PETSC_FALSE;
52: static char version[256];
56: /*
57: Initializes arch, hostname, username,date so that system calls do NOT need
58: to be made during the error handler.
59: */
60: PetscErrorCode PetscErrorPrintfInitialize()
61: {
65: PetscGetArchType(arch,10);
66: PetscGetHostName(hostname,64);
67: PetscGetUserName(username,16);
68: PetscGetProgramName(pname,PETSC_MAX_PATH_LEN);
69: PetscGetDate(date,64);
70: PetscGetVersion(&version,256);
71: PetscErrorPrintfInitializeCalled = PETSC_TRUE;
72: return(0);
73: }
79: /*@C
81: PetscTraceBackErrorHandler - Default error handler routine that generates
82: a traceback on error detection.
84: Not Collective
86: Input Parameters:
87: + line - the line number of the error (indicated by __LINE__)
88: . func - the function where error is detected (indicated by __FUNCT__)
89: . file - the file in which the error was detected (indicated by __FILE__)
90: . dir - the directory of the file (indicated by __SDIR__)
91: . mess - an error text string, usually just printed to the screen
92: . n - the generic error number
93: . p - specific error number
94: - ctx - error handler context
96: Level: developer
98: Notes:
99: Most users need not directly employ this routine and the other error
100: handlers, but can instead use the simplified interface SETERRQ, which has
101: the calling sequence
102: $ SETERRQ(number,p,mess)
104: Notes for experienced users:
105: Use PetscPushErrorHandler() to set the desired error handler. The
106: currently available PETSc error handlers include PetscTraceBackErrorHandler(),
107: PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler(), and PetscStopErrorHandler()
109: Concepts: error handler^traceback
110: Concepts: traceback^generating
112: .seealso: PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(),
113: PetscAbortErrorHandler()
114: @*/
115: PetscErrorCode PetscTraceBackErrorHandler(int line,const char *fun,const char* file,const char *dir,PetscErrorCode n,int p,const char *mess,void *ctx)
116: {
117: PetscLogDouble mem,rss;
118: PetscTruth flg1,flg2;
122: if (p == 1) {
123: (*PetscErrorPrintf)("--------------------- Error Message ------------------------------------\n");
124: if (n == PETSC_ERR_MEM) {
125: (*PetscErrorPrintf)("Out of memory. This could be due to allocating\n");
126: (*PetscErrorPrintf)("too large an object or bleeding by not properly\n");
127: (*PetscErrorPrintf)("destroying unneeded objects.\n");
128: PetscMallocGetCurrentUsage(&mem);
129: PetscMemoryGetCurrentUsage(&rss);
130: PetscOptionsHasName(PETSC_NULL,"-malloc_dump",&flg1);
131: PetscOptionsHasName(PETSC_NULL,"-malloc_log",&flg2);
132: if (flg2) {
133: PetscMallocDumpLog(stdout);
134: } else {
135: (*PetscErrorPrintf)("Memory allocated %D Memory used by process %D\n",(PetscInt)mem,(PetscInt)rss);
136: if (flg1) {
137: PetscMallocDump(stdout);
138: } else {
139: (*PetscErrorPrintf)("Try running with -malloc_dump or -malloc_log for info.\n");
140: }
141: }
142: } else {
143: const char *text;
144: PetscErrorMessage(n,&text,PETSC_NULL);
145: if (text) (*PetscErrorPrintf)("%s!\n",text);
146: }
147: if (mess) {
148: (*PetscErrorPrintf)("%s!\n",mess);
149: }
150: (*PetscErrorPrintf)("------------------------------------------------------------------------\n");
151: (*PetscErrorPrintf)("%s\n",version);
152: (*PetscErrorPrintf)("See docs/changes/index.html for recent updates.\n");
153: (*PetscErrorPrintf)("See docs/faq.html for hints about trouble shooting.\n");
154: (*PetscErrorPrintf)("See docs/index.html for manual pages.\n");
155: (*PetscErrorPrintf)("------------------------------------------------------------------------\n");
156: if (PetscErrorPrintfInitializeCalled) {
157: (*PetscErrorPrintf)("%s on a %s named %s by %s %s\n",pname,arch,hostname,username,date);
158: }
159: (*PetscErrorPrintf)("Libraries linked from %s\n",PETSC_LIB_DIR);
160: (*PetscErrorPrintf)("Configure run at %s\n",petscconfigureruntime);
161: (*PetscErrorPrintf)("Configure options %s\n",petscconfigureoptions);
162: (*PetscErrorPrintf)("------------------------------------------------------------------------\n");
163: }
166: /* first line in stack trace? */
167: (*PetscErrorPrintf)("%s() line %d in %s%s\n",fun,line,dir,file);
170: PetscFunctionReturn(n);
171: }