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 PetscMPIAbortErrorHandler() 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 static char version[256]; 53 static FILE *PetscErrorPrintfFILE = stdout; 54 55 #undef __FUNCT__ 56 #define __FUNCT__ "PetscErrorPrintfInitialize" 57 /* 58 Initializes arch, hostname, username,date so that system calls do NOT need 59 to be made during the error handler. 60 */ 61 PetscErrorCode PETSC_DLLEXPORT PetscErrorPrintfInitialize() 62 { 63 PetscErrorCode ierr; 64 PetscTruth use_stderr; 65 66 PetscFunctionBegin; 67 ierr = PetscGetArchType(arch,10);CHKERRQ(ierr); 68 ierr = PetscGetHostName(hostname,64);CHKERRQ(ierr); 69 ierr = PetscGetUserName(username,16);CHKERRQ(ierr); 70 ierr = PetscGetProgramName(pname,PETSC_MAX_PATH_LEN);CHKERRQ(ierr); 71 ierr = PetscGetDate(date,64);CHKERRQ(ierr); 72 ierr = PetscGetVersion(&version,256);CHKERRQ(ierr); 73 74 ierr = PetscOptionsHasName(PETSC_NULL,"-error_output_stderr",&use_stderr);CHKERRQ(ierr); 75 if (use_stderr) { 76 PetscErrorPrintfFILE = stderr; 77 } else { 78 PetscErrorPrintfFILE = PETSC_STDOUT; 79 } 80 PetscErrorPrintfInitializeCalled = PETSC_TRUE; 81 PetscFunctionReturn(0); 82 } 83 84 #undef __FUNCT__ 85 #define __FUNCT__ "PetscErrorPrintfNone" 86 PetscErrorCode PETSC_DLLEXPORT PetscErrorPrintfNone(const char format[],...) 87 { 88 return 0; 89 } 90 91 #undef __FUNCT__ 92 #define __FUNCT__ "PetscErrorPrintfDefault" 93 PetscErrorCode PETSC_DLLEXPORT PetscErrorPrintfDefault(const char format[],...) 94 { 95 va_list Argp; 96 static PetscTruth PetscErrorPrintfCalled = PETSC_FALSE; 97 98 /* 99 This function does not call PetscFunctionBegin and PetscFunctionReturn() because 100 it may be called by PetscStackView(). 101 102 This function does not do error checking because it is called by the error handlers. 103 */ 104 105 if (!PetscErrorPrintfCalled) { 106 PetscErrorPrintfCalled = PETSC_TRUE; 107 108 /* 109 On the SGI machines and Cray T3E, if errors are generated "simultaneously" by 110 different processors, the messages are printed all jumbled up; to try to 111 prevent this we have each processor wait based on their rank 112 */ 113 #if defined(PETSC_CAN_SLEEP_AFTER_ERROR) 114 { 115 PetscMPIInt rank; 116 if (PetscGlobalRank > 8) rank = 8; else rank = PetscGlobalRank; 117 PetscSleep(rank); 118 } 119 #endif 120 } 121 122 PetscFPrintf(PETSC_COMM_SELF,PetscErrorPrintfFILE,"[%d]PETSC ERROR: ",PetscGlobalRank); 123 va_start(Argp,format); 124 PetscVFPrintf(PetscErrorPrintfFILE,format,Argp); 125 va_end(Argp); 126 127 return 0; 128 } 129 130 131 132 #undef __FUNCT__ 133 #define __FUNCT__ "PetscTraceBackErrorHandler" 134 /*@C 135 136 PetscTraceBackErrorHandler - Default error handler routine that generates 137 a traceback on error detection. 138 139 Not Collective 140 141 Input Parameters: 142 + line - the line number of the error (indicated by __LINE__) 143 . func - the function where error is detected (indicated by __FUNCT__) 144 . file - the file in which the error was detected (indicated by __FILE__) 145 . dir - the directory of the file (indicated by __SDIR__) 146 . mess - an error text string, usually just printed to the screen 147 . n - the generic error number 148 . p - specific error number 149 - ctx - error handler context 150 151 Level: developer 152 153 Notes: 154 Most users need not directly employ this routine and the other error 155 handlers, but can instead use the simplified interface SETERRQ, which has 156 the calling sequence 157 $ SETERRQ(number,p,mess) 158 159 Notes for experienced users: 160 Use PetscPushErrorHandler() to set the desired error handler. The 161 currently available PETSc error handlers include PetscTraceBackErrorHandler(), 162 PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler(), and PetscMPIAbortErrorHandler() 163 164 Concepts: error handler^traceback 165 Concepts: traceback^generating 166 167 .seealso: PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(), 168 PetscAbortErrorHandler() 169 @*/ 170 PetscErrorCode PETSC_DLLEXPORT PetscTraceBackErrorHandler(int line,const char *fun,const char* file,const char *dir,PetscErrorCode n,int p,const char *mess,void *ctx) 171 { 172 PetscLogDouble mem,rss; 173 PetscTruth flg1,flg2; 174 175 PetscFunctionBegin; 176 177 if (p == 1) { 178 (*PetscErrorPrintf)("--------------------- Error Message ------------------------------------\n"); 179 if (n == PETSC_ERR_MEM) { 180 (*PetscErrorPrintf)("Out of memory. This could be due to allocating\n"); 181 (*PetscErrorPrintf)("too large an object or bleeding by not properly\n"); 182 (*PetscErrorPrintf)("destroying unneeded objects.\n"); 183 PetscMallocGetCurrentUsage(&mem); 184 PetscMemoryGetCurrentUsage(&rss); 185 PetscOptionsHasName(PETSC_NULL,"-malloc_dump",&flg1); 186 PetscOptionsHasName(PETSC_NULL,"-malloc_log",&flg2); 187 if (flg2) { 188 PetscMallocDumpLog(stdout); 189 } else { 190 (*PetscErrorPrintf)("Memory allocated %D Memory used by process %D\n",(PetscInt)mem,(PetscInt)rss); 191 if (flg1) { 192 PetscMallocDump(stdout); 193 } else { 194 (*PetscErrorPrintf)("Try running with -malloc_dump or -malloc_log for info.\n"); 195 } 196 } 197 } else { 198 const char *text; 199 PetscErrorMessage(n,&text,PETSC_NULL); 200 if (text) (*PetscErrorPrintf)("%s!\n",text); 201 } 202 if (mess) { 203 (*PetscErrorPrintf)("%s!\n",mess); 204 } 205 (*PetscErrorPrintf)("------------------------------------------------------------------------\n"); 206 (*PetscErrorPrintf)("%s\n",version); 207 (*PetscErrorPrintf)("See docs/changes/index.html for recent updates.\n"); 208 (*PetscErrorPrintf)("See docs/faq.html for hints about trouble shooting.\n"); 209 (*PetscErrorPrintf)("See docs/index.html for manual pages.\n"); 210 (*PetscErrorPrintf)("------------------------------------------------------------------------\n"); 211 if (PetscErrorPrintfInitializeCalled) { 212 (*PetscErrorPrintf)("%s on a %s named %s by %s %s\n",pname,arch,hostname,username,date); 213 } 214 (*PetscErrorPrintf)("Libraries linked from %s\n",PETSC_LIB_DIR); 215 (*PetscErrorPrintf)("Configure run at %s\n",petscconfigureruntime); 216 (*PetscErrorPrintf)("Configure options %s\n",petscconfigureoptions); 217 (*PetscErrorPrintf)("------------------------------------------------------------------------\n"); 218 } 219 220 221 /* first line in stack trace? */ 222 (*PetscErrorPrintf)("%s() line %d in %s%s\n",fun,line,dir,file); 223 224 225 PetscFunctionReturn(n); 226 } 227 228