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: #undef __FUNCT__
38: /*@C
39: PetscErrorMessage - returns the text string associated with a PETSc error code.
41: Not Collective
43: Input Parameter:
44: . errnum - the error code
46: Output Parameter:
47: + text - the error message (PETSC_NULL if not desired)
48: - specific - the specific error message that was set with SETERRxxx() or PetscError(). (PETSC_NULL if not desired)
50: Level: developer
52: Concepts: error handler^messages
54: .seealso: PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(),
55: PetscAbortErrorHandler(), PetscTraceBackErrorHandler()
56: @*/
57: int PetscErrorMessage(int errnum,char **text,char **specific)
58: {
60: if (text && errnum >= PETSC_ERR_MEM && errnum <= PETSC_ERR_MEM_MALLOC_0) {
61: *text = PetscErrorStrings[errnum-PETSC_ERR_MEM];
62: } else if (text) *text = 0;
64: if (specific) {
65: *specific = PetscErrorBaseMessage;
66: }
67: return(0);
68: }
70: #undef __FUNCT__
72: /*@C
73: PetscIgnoreErrorHandler - Ignores the error, allows program to continue as if error did not occure
75: Not Collective
77: Input Parameters:
78: + line - the line number of the error (indicated by __LINE__)
79: . func - the function where error is detected (indicated by __FUNCT__)
80: . file - the file in which the error was detected (indicated by __FILE__)
81: . dir - the directory of the file (indicated by __SDIR__)
82: . mess - an error text string, usually just printed to the screen
83: . n - the generic error number
84: . p - specific error number
85: - ctx - error handler context
87: Level: developer
89: Notes:
90: Most users need not directly employ this routine and the other error
91: handlers, but can instead use the simplified interface SETERRQ, which has
92: the calling sequence
93: $ SETERRQ(number,p,mess)
95: Notes for experienced users:
96: Use PetscPushErrorHandler() to set the desired error handler. The
97: currently available PETSc error handlers include PetscTraceBackErrorHandler(),
98: PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler(), and PetscStopErrorHandler()
100: Concepts: error handler^traceback
101: Concepts: traceback^generating
103: .seealso: PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(),
104: PetscAbortErrorHandler(), PetscTraceBackErrorHandler()
105: @*/
106: int PetscIgnoreErrorHandler(int line,char *fun,char* file,char *dir,int n,int p,char *mess,void *ctx)
107: {
109: PetscFunctionReturn(n);
110: }
113: #undef __FUNCT__
115: /*@C
117: PetscTraceBackErrorHandler - Default error handler routine that generates
118: a traceback on error detection.
120: Not Collective
122: Input Parameters:
123: + line - the line number of the error (indicated by __LINE__)
124: . func - the function where error is detected (indicated by __FUNCT__)
125: . file - the file in which the error was detected (indicated by __FILE__)
126: . dir - the directory of the file (indicated by __SDIR__)
127: . mess - an error text string, usually just printed to the screen
128: . n - the generic error number
129: . p - specific error number
130: - ctx - error handler context
132: Level: developer
134: Notes:
135: Most users need not directly employ this routine and the other error
136: handlers, but can instead use the simplified interface SETERRQ, which has
137: the calling sequence
138: $ SETERRQ(number,p,mess)
140: Notes for experienced users:
141: Use PetscPushErrorHandler() to set the desired error handler. The
142: currently available PETSc error handlers include PetscTraceBackErrorHandler(),
143: PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler(), and PetscStopErrorHandler()
145: Concepts: error handler^traceback
146: Concepts: traceback^generating
148: .seealso: PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(),
149: PetscAbortErrorHandler()
150: @*/
151: int PetscTraceBackErrorHandler(int line,char *fun,char* file,char *dir,int n,int p,char *mess,void *ctx)
152: {
153: PetscLogDouble mem,rss;
154: int rank;
155: PetscTruth flg1,flg2;
158: MPI_Comm_rank(MPI_COMM_WORLD,&rank);
160: (*PetscErrorPrintf)("[%d]PETSC ERROR: %s() line %d in %s%sn",rank,fun,line,dir,file);
161: if (p == 1) {
162: if (n == PETSC_ERR_MEM) {
163: (*PetscErrorPrintf)("[%d]PETSC ERROR: Out of memory. This could be due to allocatingn",rank);
164: (*PetscErrorPrintf)("[%d]PETSC ERROR: too large an object or bleeding by not properlyn",rank);
165: (*PetscErrorPrintf)("[%d]PETSC ERROR: destroying unneeded objects.n",rank);
166: PetscTrSpace(&mem,PETSC_NULL,PETSC_NULL);
167: PetscGetResidentSetSize(&rss);
168: PetscOptionsHasName(PETSC_NULL,"-trdump",&flg1);
169: PetscOptionsHasName(PETSC_NULL,"-trmalloc_log",&flg2);
170: if (flg2) {
171: PetscTrLogDump(stdout);
172: } else if (flg1) {
173: (*PetscErrorPrintf)("[%d]PETSC ERROR: Memory allocated %d Memory used by process %dn",rank,(int)mem,(int)rss);
174: PetscTrDump(stdout);
175: } else {
176: (*PetscErrorPrintf)("[%d]PETSC ERROR: Memory allocated %d Memory used by process %dn",rank,(int)mem,(int)rss);
177: (*PetscErrorPrintf)("[%d]PETSC ERROR: Try running with -trdump or -trmalloc_log for info.n",rank);
178: }
179: } else {
180: char *text;
181: PetscErrorMessage(n,&text,PETSC_NULL);
182: if (text) (*PetscErrorPrintf)("[%d]PETSC ERROR: %s!n",rank,text);
183: }
184: if (mess) {
185: (*PetscErrorPrintf)("[%d]PETSC ERROR: %s!n",rank,mess);
186: }
187: }
188: PetscFunctionReturn(n);
189: }