/*@C PetscTraceBackErrorHandler - Default error handler routine that generates a traceback on error detection. Not Collective Input Parameters: + comm - communicator over which error occurred . line - the line number of the error (indicated by __LINE__) . func - the function where error is detected (indicated by __FUNCT__) . file - the file in which the error was detected (indicated by __FILE__) . mess - an error text string, usually just printed to the screen . n - the generic error number . p - PETSC_ERROR_INITIAL if this is the first call the error handler, otherwise PETSC_ERROR_REPEAT - ctx - error handler context Level: developer Notes: Most users need not directly employ this routine and the other error handlers, but can instead use the simplified interface SETERRQ, which has the calling sequence $ SETERRQ(comm,number,n,mess) Notes for experienced users: Use PetscPushErrorHandler() to set the desired error handler. The currently available PETSc error handlers include PetscTraceBackErrorHandler(), PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler(), and PetscMPIAbortErrorHandler() Concepts: error handler^traceback Concepts: traceback^generating .seealso: PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler() @*/ PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm comm,int line,const char *fun,const char *file,PetscErrorCode n,PetscErrorType p,const char *mess,void *ctx) { PetscLogDouble mem,rss; PetscBool flg1 = PETSC_FALSE,flg2 = PETSC_FALSE,flg3 = PETSC_FALSE; PetscMPIInt rank = 0; PetscFunctionBegin; if (comm != PETSC_COMM_SELF) MPI_Comm_rank(comm,&rank); if (!rank) { PetscBool ismain,isunknown; static int cnt = 1; if (p == PETSC_ERROR_INITIAL) { PetscErrorPrintfHilight(); (*PetscErrorPrintf)("--------------------- Error Message --------------------------------------------------------------\n"); PetscErrorPrintfNormal(); if (n == PETSC_ERR_MEM) { (*PetscErrorPrintf)("Out of memory. This could be due to allocating\n"); (*PetscErrorPrintf)("too large an object or bleeding by not properly\n"); (*PetscErrorPrintf)("destroying unneeded objects.\n"); PetscMallocGetCurrentUsage(&mem); PetscMemoryGetCurrentUsage(&rss); PetscOptionsGetBool(NULL,"-malloc_dump",&flg1,NULL); PetscOptionsGetBool(NULL,"-malloc_log",&flg2,NULL); PetscOptionsHasName(NULL,"-malloc_log_threshold",&flg3); if (flg2 || flg3) PetscMallocDumpLog(stdout); else { (*PetscErrorPrintf)("Memory allocated %.0f Memory used by process %.0f\n",mem,rss); if (flg1) PetscMallocDump(stdout); else (*PetscErrorPrintf)("Try running with -malloc_dump or -malloc_log for info.\n"); } } else { const char *text; PetscErrorMessage(n,&text,NULL); if (text) (*PetscErrorPrintf)("%s\n",text); } if (mess) (*PetscErrorPrintf)("%s\n",mess); (*PetscErrorPrintf)("See http://www.mcs.anl.gov/petsc/documentation/faq.html for trouble shooting.\n"); (*PetscErrorPrintf)("%s\n",version); if (PetscErrorPrintfInitializeCalled) (*PetscErrorPrintf)("%s on a %s named %s by %s %s\n",pname,arch,hostname,username,date); (*PetscErrorPrintf)("Configure options %s\n",petscconfigureoptions); } /* print line of stack trace */ (*PetscErrorPrintf)("#%d %s() line %d in %s\n",cnt++,fun,line,file); PetscStrncmp(fun,"main",4,&ismain); PetscStrncmp(fun,"unknown",7,&isunknown); if (ismain || isunknown) { PetscOptionsViewError(); PetscErrorPrintfHilight(); (*PetscErrorPrintf)("----------------End of Error Message -------send entire error message to [email protected]\n"); PetscErrorPrintfNormal(); } } else { /* do not print error messages since process 0 will print them, sleep before aborting so will not accidently kill process 0*/ PetscSleep(10.0); abort(); } PetscFunctionReturn(n); }
/*@C PetscTraceBackErrorHandler - Default error handler routine that generates a traceback on error detection. Not Collective Input Parameters: + comm - communicator over which error occurred . line - the line number of the error (indicated by __LINE__) . func - the function where error is detected (indicated by __FUNCT__) . file - the file in which the error was detected (indicated by __FILE__) . dir - the directory of the file (indicated by __SDIR__) . mess - an error text string, usually just printed to the screen . n - the generic error number . p - PETSC_ERROR_INITIAL if this is the first call the the error handler, otherwise PETSC_ERROR_REPEAT - ctx - error handler context Level: developer Notes: Most users need not directly employ this routine and the other error handlers, but can instead use the simplified interface SETERRQ, which has the calling sequence $ SETERRQ(comm,number,n,mess) Notes for experienced users: Use PetscPushErrorHandler() to set the desired error handler. The currently available PETSc error handlers include PetscTraceBackErrorHandler(), PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler(), and PetscMPIAbortErrorHandler() Concepts: error handler^traceback Concepts: traceback^generating .seealso: PetscPushErrorHandler(), PetscAttachDebuggerErrorHandler(), PetscAbortErrorHandler() @*/ PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm comm,int line,const char *fun,const char* file,const char *dir,PetscErrorCode n,PetscErrorType p,const char *mess,void *ctx) { PetscLogDouble mem,rss; PetscBool flg1 = PETSC_FALSE,flg2 = PETSC_FALSE,flg3 = PETSC_FALSE; PetscMPIInt rank = 0; PetscFunctionBegin; if (comm != PETSC_COMM_SELF) { MPI_Comm_rank(comm,&rank); } if (!rank) { if (p == PETSC_ERROR_INITIAL) { (*PetscErrorPrintf)("--------------------- Error Message ------------------------------------\n"); if (n == PETSC_ERR_MEM) { (*PetscErrorPrintf)("Out of memory. This could be due to allocating\n"); (*PetscErrorPrintf)("too large an object or bleeding by not properly\n"); (*PetscErrorPrintf)("destroying unneeded objects.\n"); PetscMallocGetCurrentUsage(&mem); PetscMemoryGetCurrentUsage(&rss); PetscOptionsGetBool(PETSC_NULL,"-malloc_dump",&flg1,PETSC_NULL); PetscOptionsGetBool(PETSC_NULL,"-malloc_log",&flg2,PETSC_NULL); PetscOptionsHasName(PETSC_NULL,"-malloc_log_threshold",&flg3); if (flg2 || flg3) { PetscMallocDumpLog(stdout); } else { (*PetscErrorPrintf)("Memory allocated %.0f Memory used by process %.0f\n",mem,rss); if (flg1) { PetscMallocDump(stdout); } else { (*PetscErrorPrintf)("Try running with -malloc_dump or -malloc_log for info.\n"); } } } else { const char *text; PetscErrorMessage(n,&text,PETSC_NULL); if (text) (*PetscErrorPrintf)("%s!\n",text); } if (mess) { (*PetscErrorPrintf)("%s!\n",mess); } (*PetscErrorPrintf)("------------------------------------------------------------------------\n"); (*PetscErrorPrintf)("%s\n",version); (*PetscErrorPrintf)("See docs/changes/index.html for recent updates.\n"); (*PetscErrorPrintf)("See docs/faq.html for hints about trouble shooting.\n"); (*PetscErrorPrintf)("See docs/index.html for manual pages.\n"); (*PetscErrorPrintf)("------------------------------------------------------------------------\n"); if (PetscErrorPrintfInitializeCalled) { (*PetscErrorPrintf)("%s on a %s named %s by %s %s\n",pname,arch,hostname,username,date); } (*PetscErrorPrintf)("Libraries linked from %s\n",PETSC_LIB_DIR); (*PetscErrorPrintf)("Configure run at %s\n",petscconfigureruntime); (*PetscErrorPrintf)("Configure options %s\n",petscconfigureoptions); (*PetscErrorPrintf)("------------------------------------------------------------------------\n"); } /* print line of stack trace */ (*PetscErrorPrintf)("%s() line %d in %s%s\n",fun,line,dir,file); } else { /* do not print error messages since process 0 will print them, sleep before aborting so will not accidently kill process 0*/ PetscSleep(10.0); abort(); } PetscFunctionReturn(n); }