ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ScriptInterface::ParallelExceptionHandler Class Reference

Handle exceptions thrown in MPI parallel code. More...

#include <ParallelExceptionHandler.hpp>

Public Member Functions

 ParallelExceptionHandler (boost::mpi::communicator comm)
 
template<typename T >
void parallel_try_catch (std::function< void()> const &callback) const
 Handle exceptions in synchronous code.
 

Detailed Description

Handle exceptions thrown in MPI parallel code.

Instantiate this class inside the catch block and after the catch block, like so:

boost::mpi::communicator world;
std::shared_ptr<MyClass> obj;
context()->parallel_try_catch([&obj]() {
obj = std::make_shared<MyClass>(2., true);
});
Handle exceptions thrown in MPI parallel code.
void parallel_try_catch(std::function< void()> const &callback) const
Handle exceptions in synchronous code.

Exceptions are handled as follows:

  • the main rank throws: re-throw on main rank and throw Exception on all other ranks
  • one or more of the worker nodes throw: collect error messages from worker nodes and throw them on the main rank as a std::runtime_error, throw Exception on all other ranks

Throwing a Exception guarantees that the partially initialized script interface object won't be registered in the GlobalContext dictionary; this is the only side-effect on worker nodes, since the exception itself is otherwise silently ignored. On the main rank, the thrown exception is converted to a Python exception.

Definition at line 58 of file ParallelExceptionHandler.hpp.

Constructor & Destructor Documentation

◆ ParallelExceptionHandler()

ScriptInterface::ParallelExceptionHandler::ParallelExceptionHandler ( boost::mpi::communicator  comm)
inline

Definition at line 60 of file ParallelExceptionHandler.hpp.

Member Function Documentation

◆ parallel_try_catch()

template<typename T >
void ScriptInterface::ParallelExceptionHandler::parallel_try_catch ( std::function< void()> const &  callback) const
inline

Handle exceptions in synchronous code.

Error messages queued in the runtime error collector are flushed to standard error if the code throws on any rank.

Precondition
Must be called on all ranks.
The callback cannot invoke remote functions from the Communication::MpiCallbacks framework due to blocking communication (risk of MPI deadlock on worker nodes).
Parameters
[in]callbackCallback to execute synchronously on all ranks.

Definition at line 74 of file ParallelExceptionHandler.hpp.

Referenced by ScriptInterface::GlobalContext::parallel_try_catch(), and ScriptInterface::LocalContext::parallel_try_catch().


The documentation for this class was generated from the following files: