16 #include <deal.II/base/exceptions.h> 17 #include <deal.II/base/logstream.h> 18 #include <deal.II/base/mpi.h> 19 #include <deal.II/base/utilities.h> 27 #ifdef DEAL_II_WITH_MPI 31 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 32 # include <execinfo.h> 35 #ifdef DEAL_II_HAVE_LIBSTDCXX_DEMANGLER 39 DEAL_II_NAMESPACE_OPEN
44 std::string additional_assert_output;
49 additional_assert_output = p;
52 bool show_stacktrace =
true;
57 show_stacktrace =
false;
60 bool abort_on_exception =
true;
65 abort_on_exception =
false;
79 , n_stacktrace_frames(0)
82 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 83 for (
unsigned int i = 0;
104 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 105 for (
unsigned int i = 0;
140 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 151 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 180 out <<
"An error occurred in line <" <<
line <<
"> of file <" <<
file 181 <<
"> in function" << std::endl
182 <<
" " <<
function << std::endl
183 <<
"The violated condition was: " << std::endl
184 <<
" " <<
cond << std::endl;
198 if (std::strstr(
cond,
"::ExcMessage") !=
nullptr)
199 out <<
"The name and call sequence of the exception was:" << std::endl
200 <<
" " <<
exc << std::endl;
203 out <<
"Additional information: " << std::endl;
211 out <<
" (none)" << std::endl;
222 if (deal_II_exceptions::show_stacktrace ==
false)
227 out <<
"Stacktrace:" << std::endl <<
"-----------" << std::endl;
235 ((std::string(
stacktrace[frame]).find(
"ExceptionBase") !=
236 std::string::npos) ||
237 (std::string(
stacktrace[frame]).find(
"deal_II_exceptions") !=
242 const unsigned int first_significant_frame = frame;
245 out <<
'#' << frame - first_significant_frame <<
" ";
250 std::string stacktrace_entry(
stacktrace[frame]);
251 const unsigned int pos_start = stacktrace_entry.find(
'('),
252 pos_end = stacktrace_entry.find(
'+');
253 std::string functionname =
254 stacktrace_entry.substr(pos_start + 1, pos_end - pos_start - 1);
256 stacktrace_entry = stacktrace_entry.substr(0, pos_start);
257 stacktrace_entry +=
": ";
263 #ifdef DEAL_II_HAVE_LIBSTDCXX_DEMANGLER 266 abi::__cxa_demangle(functionname.c_str(),
nullptr,
nullptr, &status);
268 if ((status == 0) && (functionname !=
"main"))
270 std::string realname(p);
277 while (realname.find(
", boost::tuples::null_type>") !=
279 realname.erase(realname.find(
", boost::tuples::null_type>"),
280 std::string(
", boost::tuples::null_type").size());
282 stacktrace_entry += realname;
285 stacktrace_entry += functionname;
291 stacktrace_entry += functionname;
295 out << stacktrace_entry << std::endl;
298 if (functionname ==
"main")
313 std::ostringstream converter;
315 converter << std::endl
316 <<
"--------------------------------------------------------" 325 if (!deal_II_exceptions::additional_assert_output.empty())
328 <<
"--------------------------------------------------------" 330 << deal_II_exceptions::additional_assert_output << std::endl;
333 converter <<
"--------------------------------------------------------" 341 what_str =
"ExceptionBase::generate_message () failed";
347 #ifdef DEAL_II_WITH_MPI 350 ExcMPI::ExcMPI(
const int error_code)
351 : error_code(error_code)
355 ExcMPI::print_info(std::ostream &out)
const 357 char error_name[MPI_MAX_ERROR_STRING];
358 error_name[0] =
'\0';
359 int resulting_length = MPI_MAX_ERROR_STRING;
361 bool error_name_known =
false;
364 if (error_code < MPI_ERR_LASTCODE)
369 int ierr = MPI_Error_class(error_code, &error_class);
370 error_name_known = (ierr == MPI_SUCCESS);
374 if (error_name_known)
376 ierr = MPI_Error_string(error_class, error_name, &resulting_length);
377 error_name_known = error_name_known && (ierr == MPI_SUCCESS);
381 out <<
"deal.II encountered an error while calling an MPI function." 383 if (error_name_known)
385 out <<
"The description of the error provided by MPI is \"" 386 << error_name <<
"\"." << std::endl;
391 <<
"This error code is not equal to any of the standard MPI error codes." 394 out <<
"The numerical value of the original error code is " << error_code
398 #endif // DEAL_II_WITH_MPI 406 std::cerr << exc.
what() << std::endl;
420 #ifdef DEAL_II_WITH_MPI 422 MPI_Initialized(&is_initialized);
431 <<
"Calling MPI_Abort now.\n" 432 <<
"To break execution in a GDB session, execute 'break MPI_Abort' before " 433 <<
"running. You can also put the following into your ~/.gdbinit:\n" 434 <<
" set breakpoint pending on\n" 435 <<
" break MPI_Abort\n" 436 <<
" set breakpoint pending auto" << std::endl;
438 MPI_Abort(MPI_COMM_WORLD,
454 if (::deal_II_exceptions::abort_on_exception)
460 deallog <<
"Exception: " <<
exc.get_exc_name() << std::endl;
461 deallog <<
exc.what() << std::endl;
469 if (::deal_II_exceptions::abort_on_exception)
480 #ifdef DEAL_II_WITH_CUDA 485 case CUSPARSE_STATUS_NOT_INITIALIZED:
487 return "The cuSPARSE library was not initialized";
489 case CUSPARSE_STATUS_ALLOC_FAILED:
491 return "Resource allocation failed inside the cuSPARSE library";
493 case CUSPARSE_STATUS_INVALID_VALUE:
495 return "An unsupported value of parameter was passed to the function";
497 case CUSPARSE_STATUS_ARCH_MISMATCH:
499 return "The function requires a feature absent from the device architecture";
501 case CUSPARSE_STATUS_MAPPING_ERROR:
503 return "An access to GPU memory space failed";
505 case CUSPARSE_STATUS_EXECUTION_FAILED:
507 return "The GPU program failed to execute";
509 case CUSPARSE_STATUS_INTERNAL_ERROR:
511 return "An internal cuSPARSE operation failed";
513 case CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED:
515 return "The matrix type is not supported by this function";
519 return "Unknown error";
532 case CUSOLVER_STATUS_NOT_INITIALIZED:
534 return "The cuSolver library was not initialized";
536 case CUSOLVER_STATUS_ALLOC_FAILED:
538 return "Resource allocation failed inside the cuSolver library";
540 case CUSOLVER_STATUS_INVALID_VALUE:
542 return "An unsupported value of a parameter was passed to the function";
544 case CUSOLVER_STATUS_ARCH_MISMATCH:
546 return "The function requires a feature absent from the device architecture";
548 case CUSOLVER_STATUS_EXECUTION_FAILED:
550 return "The GPU program failed to execute";
552 case CUSOLVER_STATUS_INTERNAL_ERROR:
554 return "An internal cuSolver operation failed";
556 case CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED:
558 return "The matrix type is not supported by this function";
562 return "Unknown error";
573 DEAL_II_NAMESPACE_CLOSE
void print_exc_data(std::ostream &out) const
void suppress_stacktrace_in_exceptions()
std::string get_cusolver_error_string(const cusolverStatus_t error_code)
void set_additional_assert_output(const char *const p)
void * raw_stacktrace[25]
void set_fields(const char *file, const int line, const char *function, const char *cond, const char *exc_name)
void generate_message() const
virtual void print_info(std::ostream &out) const
void do_issue_error_nothrow(const ExceptionBase &e) noexcept
std::string get_cusparse_error_string(const cusparseStatus_t error_code)
virtual ~ExceptionBase() noexceptoverride
virtual const char * what() const noexceptoverride
void print_stack_trace(std::ostream &out) const
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
void abort(const ExceptionBase &exc)
const char * get_exc_name() const
void disable_abort_on_exception()