Skip to content

Commit

Permalink
Merge pull request #5932 from bangerth/manager-update
Browse files Browse the repository at this point in the history
Harden Plugins::ManagerBase::update() against exceptions.
  • Loading branch information
gassmoeller authored Jun 23, 2024
2 parents 1a96fc7 + 613d5a8 commit 70d0a8b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 27 deletions.
51 changes: 49 additions & 2 deletions include/aspect/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,56 @@ namespace aspect
template <typename InterfaceType>
void ManagerBase<InterfaceType>::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);
}
}
}

Expand Down
11 changes: 2 additions & 9 deletions tests/find_boundary_composition_model_fail_1/screen-output
Original file line number Diff line number Diff line change
Expand Up @@ -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 <N6aspect19BoundaryTemperature4Box2ILi2EEE>:

--------------------------------------------------------
An error occurred in line <291> of file </home/bangerth/p/deal.II/1/projects/aspect/include/aspect/plugins.h> in function
An error occurred in line <338> of file </home/bangerth/p/deal.II/1/projects/aspect/include/aspect/plugins.h> in function
(line in output replaced by default.sh script)
The violated condition was:
has_matching_plugin_object<PluginType> ()
Expand Down
11 changes: 2 additions & 9 deletions tests/find_mesh_refinement_fail_1/screen-output
Original file line number Diff line number Diff line change
Expand Up @@ -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 <N6aspect19BoundaryTemperature4Box2ILi2EEE>:

--------------------------------------------------------
An error occurred in line <291> of file </home/bangerth/p/deal.II/1/projects/aspect/include/aspect/plugins.h> in function
An error occurred in line <338> of file </home/bangerth/p/deal.II/1/projects/aspect/include/aspect/plugins.h> in function
(line in output replaced by default.sh script)
The violated condition was:
has_matching_plugin_object<PluginType> ()
Expand Down
16 changes: 9 additions & 7 deletions tests/find_postprocess_fail_1/screen-output
Original file line number Diff line number Diff line change
@@ -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 <N6aspect19BoundaryTemperature4Box2ILi2EEE>:

An error occurred in file <plugins.h> in function
--------------------------------------------------------
An error occurred in line <338> of file </home/bangerth/p/deal.II/1/projects/aspect/include/aspect/plugins.h> in function
(line in output replaced by default.sh script)
The violated condition was:
has_matching_plugin_object<PluginType> ()
Expand Down

0 comments on commit 70d0a8b

Please sign in to comment.