Actual source code: errtrace.c
1: /*$Id: errtrace.c,v 1.25 2001/06/21 21:15:22 bsmith Exp $*/
3: #include petsc.h
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: }
68: /*@C
69: PetscIgnoreErrorHandler - Ignores the error, allows program to continue as if error did not occure
71: Not Collective
73: Input Parameters:
74: + line - the line number of the error (indicated by __LINE__)
75: . file - the file in which the error was detected (indicated by __FILE__)
76: . dir - the directory of the file (indicated by __SDIR__)
77: . mess - an error text string, usually just printed to the screen
78: . n - the generic error number
79: . p - specific error number
80: - ctx - error handler context
82: Level: developer
84: Notes:
85: Most users need not directly employ this routine and the other error
86: handlers, but can instead use the simplified interface SETERRQ, which has
87: the calling sequence
88: $ SETERRQ(number,p,mess)
90: Notes for experienced users:
91: Use PetscPushErrorHandler() to set the desired error handler. The
92: currently available PETSc error handlers include PetscTraceBackErrorHandler(),
93: PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler(), and PetscStopErrorHandler()
95: Concepts: error handler^traceback
96: Concepts: traceback^generating
98: .seealso: PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(),
99: PetscAbortErrorHandler(), PetscTraceBackErrorHandler()
100: @*/
101: int PetscIgnoreErrorHandler(int line,char *fun,char* file,char *dir,int n,int p,char *mess,void *ctx)
102: {
104: PetscFunctionReturn(n);
105: }
108: /*@C
110: PetscTraceBackErrorHandler - Default error handler routine that generates
111: a traceback on error detection.
113: Not Collective
115: Input Parameters:
116: + line - the line number of the error (indicated by __LINE__)
117: . file - the file in which the error was detected (indicated by __FILE__)
118: . dir - the directory of the file (indicated by __SDIR__)
119: . mess - an error text string, usually just printed to the screen
120: . n - the generic error number
121: . p - specific error number
122: - ctx - error handler context
124: Level: developer
126: Notes:
127: Most users need not directly employ this routine and the other error
128: handlers, but can instead use the simplified interface SETERRQ, which has
129: the calling sequence
130: $ SETERRQ(number,p,mess)
132: Notes for experienced users:
133: Use PetscPushErrorHandler() to set the desired error handler. The
134: currently available PETSc error handlers include PetscTraceBackErrorHandler(),
135: PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler(), and PetscStopErrorHandler()
137: Concepts: error handler^traceback
138: Concepts: traceback^generating
140: .seealso: PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(),
141: PetscAbortErrorHandler()
142: @*/
143: int PetscTraceBackErrorHandler(int line,char *fun,char* file,char *dir,int n,int p,char *mess,void *ctx)
144: {
145: PetscLogDouble mem,rss;
146: int rank;
147: PetscTruth flg1,flg2;
150: MPI_Comm_rank(MPI_COMM_WORLD,&rank);
152: (*PetscErrorPrintf)("[%d]PETSC ERROR: %s() line %d in %s%sn",rank,fun,line,dir,file);
153: if (p == 1) {
154: if (n == PETSC_ERR_MEM) {
155: (*PetscErrorPrintf)("[%d]PETSC ERROR: Out of memory. This could be due to allocatingn",rank);
156: (*PetscErrorPrintf)("[%d]PETSC ERROR: too large an object or bleeding by not properlyn",rank);
157: (*PetscErrorPrintf)("[%d]PETSC ERROR: destroying unneeded objects.n",rank);
158: PetscTrSpace(&mem,PETSC_NULL,PETSC_NULL);
159: PetscGetResidentSetSize(&rss);
160: PetscOptionsHasName(PETSC_NULL,"-trdump",&flg1);
161: PetscOptionsHasName(PETSC_NULL,"-trmalloc_log",&flg2);
162: if (flg2) {
163: PetscTrLogDump(stdout);
164: } else if (flg1) {
165: (*PetscErrorPrintf)("[%d]PETSC ERROR: Memory allocated %d Memory used by process %dn",rank,(int)mem,(int)rss);
166: PetscTrDump(stdout);
167: } else {
168: (*PetscErrorPrintf)("[%d]PETSC ERROR: Memory allocated %d Memory used by process %dn",rank,(int)mem,(int)rss);
169: (*PetscErrorPrintf)("[%d]PETSC ERROR: Try running with -trdump or -trmalloc_log for info.n",rank);
170: }
171: } else {
172: char *text;
173: PetscErrorMessage(n,&text,PETSC_NULL);
174: if (text) (*PetscErrorPrintf)("[%d]PETSC ERROR: %s!n",rank,text);
175: }
176: if (mess) {
177: (*PetscErrorPrintf)("[%d]PETSC ERROR: %s!n",rank,mess);
178: }
179: }
180: PetscFunctionReturn(n);
181: }