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
47 get_additional_assert_output()
49 static std::string additional_assert_output;
50 return additional_assert_output;
53 bool show_stacktrace =
true;
61 internals::get_additional_assert_output() = p;
67 internals::show_stacktrace =
false;
86 , n_stacktrace_frames(0)
89 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 99 , function(exc.function)
102 , stacktrace(nullptr)
104 n_stacktrace_frames(0)
108 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 141 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 152 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 181 out <<
"An error occurred in line <" <<
line <<
"> of file <" <<
file 182 <<
"> in function" << std::endl
183 <<
" " <<
function << std::endl
184 <<
"The violated condition was: " << std::endl
185 <<
" " <<
cond << std::endl;
199 if (std::strstr(
cond,
"::ExcMessage") !=
nullptr)
200 out <<
"The name and call sequence of the exception was:" << std::endl
201 <<
" " <<
exc << std::endl;
204 out <<
"Additional information: " << std::endl;
212 out <<
" (none)" << std::endl;
223 if (deal_II_exceptions::internals::show_stacktrace ==
false)
228 out <<
"Stacktrace:" << std::endl <<
"-----------" << std::endl;
236 ((std::string(
stacktrace[frame]).find(
"ExceptionBase") !=
237 std::string::npos) ||
238 (std::string(
stacktrace[frame]).find(
"deal_II_exceptions") !=
243 const unsigned int first_significant_frame = frame;
246 out <<
'#' << frame - first_significant_frame <<
" ";
251 std::string stacktrace_entry(
stacktrace[frame]);
252 const unsigned int pos_start = stacktrace_entry.find(
'('),
253 pos_end = stacktrace_entry.find(
'+');
254 std::string functionname =
255 stacktrace_entry.substr(pos_start + 1, pos_end - pos_start - 1);
257 stacktrace_entry = stacktrace_entry.substr(0, pos_start);
258 stacktrace_entry +=
": ";
264 #ifdef DEAL_II_HAVE_LIBSTDCXX_DEMANGLER 267 abi::__cxa_demangle(functionname.c_str(),
nullptr,
nullptr, &status);
269 if ((status == 0) && (functionname !=
"main"))
271 std::string realname(p);
278 while (realname.find(
", boost::tuples::null_type>") !=
280 realname.erase(realname.find(
", boost::tuples::null_type>"),
281 std::string(
", boost::tuples::null_type").size());
283 stacktrace_entry += realname;
286 stacktrace_entry += functionname;
292 stacktrace_entry += functionname;
296 out << stacktrace_entry << std::endl;
299 if (functionname ==
"main")
314 std::ostringstream converter;
316 converter << std::endl
317 <<
"--------------------------------------------------------" 326 if (!deal_II_exceptions::internals::get_additional_assert_output()
330 <<
"--------------------------------------------------------" 332 << deal_II_exceptions::internals::get_additional_assert_output()
336 converter <<
"--------------------------------------------------------" 344 what_str =
"ExceptionBase::generate_message () failed";
350 #ifdef DEAL_II_WITH_MPI 353 ExcMPI::ExcMPI(
const int error_code)
354 : error_code(error_code)
358 ExcMPI::print_info(std::ostream &out)
const 360 char error_name[MPI_MAX_ERROR_STRING];
361 error_name[0] =
'\0';
362 int resulting_length = MPI_MAX_ERROR_STRING;
364 bool error_name_known =
false;
367 if (error_code < MPI_ERR_LASTCODE)
372 int ierr = MPI_Error_class(error_code, &error_class);
373 error_name_known = (ierr == MPI_SUCCESS);
377 if (error_name_known)
379 ierr = MPI_Error_string(error_class, error_name, &resulting_length);
380 error_name_known = error_name_known && (ierr == MPI_SUCCESS);
384 out <<
"deal.II encountered an error while calling an MPI function." 386 if (error_name_known)
388 out <<
"The description of the error provided by MPI is \"" 389 << error_name <<
"\"." << std::endl;
394 <<
"This error code is not equal to any of the standard MPI error codes." 397 out <<
"The numerical value of the original error code is " << error_code
401 #endif // DEAL_II_WITH_MPI 411 std::cerr << exc.what() << std::endl;
425 #ifdef DEAL_II_WITH_MPI 427 MPI_Initialized(&is_initialized);
436 <<
"Calling MPI_Abort now.\n" 437 <<
"To break execution in a GDB session, execute 'break MPI_Abort' before " 438 <<
"running. You can also put the following into your ~/.gdbinit:\n" 439 <<
" set breakpoint pending on\n" 440 <<
" break MPI_Abort\n" 441 <<
" set breakpoint pending auto" << std::endl;
443 MPI_Abort(MPI_COMM_WORLD,
462 deallog <<
"Exception: " << exc.get_exc_name() << std::endl;
463 deallog << exc.what() << std::endl;
469 #ifdef DEAL_II_WITH_CUDA 475 case CUSPARSE_STATUS_NOT_INITIALIZED:
477 return "The cuSPARSE library was not initialized";
479 case CUSPARSE_STATUS_ALLOC_FAILED:
481 return "Resource allocation failed inside the cuSPARSE library";
483 case CUSPARSE_STATUS_INVALID_VALUE:
485 return "An unsupported value of parameter was passed to the function";
487 case CUSPARSE_STATUS_ARCH_MISMATCH:
489 return "The function requires a feature absent from the device architecture";
491 case CUSPARSE_STATUS_MAPPING_ERROR:
493 return "An access to GPU memory space failed";
495 case CUSPARSE_STATUS_EXECUTION_FAILED:
497 return "The GPU program failed to execute";
499 case CUSPARSE_STATUS_INTERNAL_ERROR:
501 return "An internal cuSPARSE operation failed";
503 case CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED:
505 return "The matrix type is not supported by this function";
509 return "Unknown error";
522 case CUSOLVER_STATUS_NOT_INITIALIZED:
524 return "The cuSolver library was not initialized";
526 case CUSOLVER_STATUS_ALLOC_FAILED:
528 return "Resource allocation failed inside the cuSolver library";
530 case CUSOLVER_STATUS_INVALID_VALUE:
532 return "An unsupported value of a parameter was passed to the function";
534 case CUSOLVER_STATUS_ARCH_MISMATCH:
536 return "The function requires a feature absent from the device architecture";
538 case CUSOLVER_STATUS_EXECUTION_FAILED:
540 return "The GPU program failed to execute";
542 case CUSOLVER_STATUS_INTERNAL_ERROR:
544 return "An internal cuSolver operation failed";
546 case CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED:
548 return "The matrix type is not supported by this function";
552 return "Unknown error";
563 DEAL_II_NAMESPACE_CLOSE
void suppress_stacktrace_in_exceptions()
virtual ~ExceptionBase() noexcept override
std::string get_cusolver_error_string(const cusolverStatus_t error_code)
void set_additional_assert_output(const char *const p)
void * raw_stacktrace[25]
virtual void print_info(std::ostream &out) const
virtual const char * what() const noexcept override
void set_fields(const char *file, const int line, const char *function, const char *cond, const char *exc_name)
void do_issue_error_nothrow(const ExceptionBase &e) noexcept
std::string get_cusparse_error_string(const cusparseStatus_t error_code)
void abort(const ExceptionBase &exc) noexcept
void print_stack_trace(std::ostream &out) const
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
bool allow_abort_on_exception
void print_exc_data(std::ostream &out) const
void generate_message() const
void disable_abort_on_exception()
const char * get_exc_name() const