1 #define PETSC_DLL 2 3 #include "petscsys.h" /*I "petscsys.h" I*/ 4 #include "petscconfiginfo.h" 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 50 static char arch[10],hostname[64],username[16],pname[PETSC_MAX_PATH_LEN],date[64]; 51 static PetscTruth PetscErrorPrintfInitializeCalled = PETSC_FALSE; 52 53 #undef __FUNCT__ 54 #define __FUNCT__ "PetscErrorPrintfInitialize" 55 /* 56 Initializes arch, hostname, username,date so that system calls do NOT need 57 to be made during the error handler. 58 */ 59 PetscErrorCode PETSC_DLLEXPORT PetscErrorPrintfInitialize() 60 { 61 PetscErrorCode ierr; 62 63 PetscFunctionBegin; 64 ierr = PetscGetArchType(arch,10);CHKERRQ(ierr); 65 ierr = PetscGetHostName(hostname,64);CHKERRQ(ierr); 66 ierr = PetscGetUserName(username,16);CHKERRQ(ierr); 67 ierr = PetscGetProgramName(pname,PETSC_MAX_PATH_LEN);CHKERRQ(ierr); 68 ierr = PetscGetDate(date,64);CHKERRQ(ierr); 69 PetscErrorPrintfInitializeCalled = PETSC_TRUE; 70 PetscFunctionReturn(0); 71 } 72 73 74 75 #undef __FUNCT__ 76 #define __FUNCT__ "PetscTraceBackErrorHandler" 77 /*@C 78 79 PetscTraceBackErrorHandler - Default error handler routine that generates 80 a traceback on error detection. 81 82 Not Collective 83 84 Input Parameters: 85 + line - the line number of the error (indicated by __LINE__) 86 . func - the function where error is detected (indicated by __FUNCT__) 87 . file - the file in which the error was detected (indicated by __FILE__) 88 . dir - the directory of the file (indicated by __SDIR__) 89 . mess - an error text string, usually just printed to the screen 90 . n - the generic error number 91 . p - specific error number 92 - ctx - error handler context 93 94 Level: developer 95 96 Notes: 97 Most users need not directly employ this routine and the other error 98 handlers, but can instead use the simplified interface SETERRQ, which has 99 the calling sequence 100 $ SETERRQ(number,p,mess) 101 102 Notes for experienced users: 103 Use PetscPushErrorHandler() to set the desired error handler. The 104 currently available PETSc error handlers include PetscTraceBackErrorHandler(), 105 PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler(), and PetscStopErrorHandler() 106 107 Concepts: error handler^traceback 108 Concepts: traceback^generating 109 110 .seealso: PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(), 111 PetscAbortErrorHandler() 112 @*/ 113 PetscErrorCode PETSC_DLLEXPORT PetscTraceBackErrorHandler(int line,const char *fun,const char* file,const char *dir,PetscErrorCode n,int p,const char *mess,void *ctx) 114 { 115 PetscLogDouble mem,rss; 116 PetscTruth flg1,flg2; 117 char version[256]; 118 PetscErrorCode ierr; 119 120 PetscFunctionBegin; 121 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 ierr = PetscGetVersion(&version); 151 (*PetscErrorPrintf)("------------------------------------------------------------------------\n"); 152 (*PetscErrorPrintf)("%s\n",version); 153 (*PetscErrorPrintf)("See docs/changes/index.html for recent updates.\n"); 154 (*PetscErrorPrintf)("See docs/faq.html for hints about trouble shooting.\n"); 155 (*PetscErrorPrintf)("See docs/index.html for manual pages.\n"); 156 (*PetscErrorPrintf)("------------------------------------------------------------------------\n"); 157 if (PetscErrorPrintfInitializeCalled) { 158 (*PetscErrorPrintf)("%s on a %s named %s by %s %s\n",pname,arch,hostname,username,date); 159 } 160 (*PetscErrorPrintf)("Libraries linked from %s\n",PETSC_LIB_DIR); 161 (*PetscErrorPrintf)("Configure run at %s\n",petscconfigureruntime); 162 (*PetscErrorPrintf)("Configure options %s\n",petscconfigureoptions); 163 (*PetscErrorPrintf)("------------------------------------------------------------------------\n"); 164 } 165 166 167 /* first line in stack trace? */ 168 (*PetscErrorPrintf)("%s() line %d in %s%s\n",fun,line,dir,file); 169 170 171 PetscFunctionReturn(n); 172 } 173 174