From 93e2d26d901f7f2f673b595e066b92293bea1c00 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 21 Jun 2024 18:46:55 -0600 Subject: [PATCH 1/2] Harden Plugins::ManagerBase::update() against exceptions. --- include/aspect/plugins.h | 51 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/include/aspect/plugins.h b/include/aspect/plugins.h index 86d77fc9f1e..d9cae19ec2c 100644 --- a/include/aspect/plugins.h +++ b/include/aspect/plugins.h @@ -262,9 +262,56 @@ namespace aspect template void ManagerBase::update() { - for (const auto &plugin : plugin_objects) + // call the update() functions of all plugins: + for (const auto &p : plugin_objects) { - plugin->update(); + try + { + p->update (); + } + + // plugins that throw exceptions usually do not result in + // anything good because they result in an unwinding of the stack + // and, if only one processor triggers an exception, the + // destruction of objects often causes a deadlock. thus, if + // an exception is generated, catch it, print an error message, + // and abort the program + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on MPI process <" + << dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) + << "> while running plugin <" + << typeid(*p).name() + << ">: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + // terminate the program! + MPI_Abort (MPI_COMM_WORLD, 1); + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on MPI process <" + << dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) + << "> while running plugin <" + << typeid(*p).name() + << ">: " << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + // terminate the program! + MPI_Abort (MPI_COMM_WORLD, 1); + } } } From 613d5a8837c5436aeb9562991d001d5394102045 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sat, 22 Jun 2024 17:07:37 -0600 Subject: [PATCH 2/2] Adjust tests. --- .../screen-output | 11 ++--------- tests/find_mesh_refinement_fail_1/screen-output | 11 ++--------- tests/find_postprocess_fail_1/screen-output | 16 +++++++++------- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/tests/find_boundary_composition_model_fail_1/screen-output b/tests/find_boundary_composition_model_fail_1/screen-output index 564c6e457a9..6ee723c0416 100644 --- a/tests/find_boundary_composition_model_fail_1/screen-output +++ b/tests/find_boundary_composition_model_fail_1/screen-output @@ -9,20 +9,13 @@ Loading shared library <./libfind_boundary_composition_model_fail_1.debug.so> Number of active cells: 64 (on 4 levels) Number of degrees of freedom: 1,526 (578+81+289+289+289) ---------------------------------------------------------- -TimerOutput objects finalize timed values printed to the -screen by communicating over MPI in their destructors. -Since an exception is currently uncaught, this -synchronization (and subsequent output) will be skipped -to avoid a possible deadlock. ---------------------------------------------------------- ---------------------------------------------------- -Exception 'ExcMessage("You asked the object managing a collection of plugins for a " "plugin object of type <" + boost::core::demangle(typeid(PluginType).name()) + "> " "that could not be found in the current model. You need to " "activate this plugin in the input file for it to be " "available.")' on rank 0 on processing: +Exception on MPI process <0> while running plugin : -------------------------------------------------------- -An error occurred in line <291> of file in function +An error occurred in line <338> of file in function (line in output replaced by default.sh script) The violated condition was: has_matching_plugin_object () diff --git a/tests/find_mesh_refinement_fail_1/screen-output b/tests/find_mesh_refinement_fail_1/screen-output index 19c819a25e6..4da556d2b01 100644 --- a/tests/find_mesh_refinement_fail_1/screen-output +++ b/tests/find_mesh_refinement_fail_1/screen-output @@ -9,20 +9,13 @@ Loading shared library <./libfind_mesh_refinement_fail_1.debug.so> Number of active cells: 64 (on 4 levels) Number of degrees of freedom: 948 (578+81+289) ---------------------------------------------------------- -TimerOutput objects finalize timed values printed to the -screen by communicating over MPI in their destructors. -Since an exception is currently uncaught, this -synchronization (and subsequent output) will be skipped -to avoid a possible deadlock. ---------------------------------------------------------- ---------------------------------------------------- -Exception 'ExcMessage("You asked the object managing a collection of plugins for a " "plugin object of type <" + boost::core::demangle(typeid(PluginType).name()) + "> " "that could not be found in the current model. You need to " "activate this plugin in the input file for it to be " "available.")' on rank 0 on processing: +Exception on MPI process <0> while running plugin : -------------------------------------------------------- -An error occurred in line <291> of file in function +An error occurred in line <338> of file in function (line in output replaced by default.sh script) The violated condition was: has_matching_plugin_object () diff --git a/tests/find_postprocess_fail_1/screen-output b/tests/find_postprocess_fail_1/screen-output index cd2519d67ab..3a359a0523a 100644 --- a/tests/find_postprocess_fail_1/screen-output +++ b/tests/find_postprocess_fail_1/screen-output @@ -1,19 +1,21 @@ +----------------------------------------------------------------------------- +----------------------------------------------------------------------------- +----------------------------------------------------------------------------- Loading shared library <./libfind_postprocess_fail_1.debug.so> +----------------------------------------------------------------------------- +----------------------------------------------------------------------------- Number of active cells: 64 (on 4 levels) Number of degrees of freedom: 948 (578+81+289) -TimerOutput objects finalize timed values printed to the -screen by communicating over MPI in their destructors. -Since an exception is currently uncaught, this -synchronization (and subsequent output) will be skipped -to avoid a possible deadlock. -Exception 'ExcMessage("You asked the object managing a collection of plugins for a " "plugin object of type <" + boost::core::demangle(typeid(PluginType).name()) + "> " "that could not be found in the current model. You need to " "activate this plugin in the input file for it to be " "available.")' on rank 0 on processing: +---------------------------------------------------- +Exception on MPI process <0> while running plugin : -An error occurred in file in function +-------------------------------------------------------- +An error occurred in line <338> of file in function (line in output replaced by default.sh script) The violated condition was: has_matching_plugin_object ()