36 std::shared_ptr<System::System>
const &system,
37 std::optional<Variant> &active_actor,
38 std::shared_ptr<T>
const &actor, F &&on_actor_change) {
39 std::optional<Variant> other = actor;
40 auto const activate = [&system](
auto &leaf) {
41 leaf->bind_system(system);
42 leaf->on_activation();
44 auto const deactivate = [&system](
auto &leaf) {
45 leaf->detach_system(system);
47 auto const cleanup_if_any_rank_failed = [&](
bool failed) {
48 if (boost::mpi::all_reduce(comm, failed, std::logical_or<>())) {
50 active_actor.swap(other);
52 std::visit([&](
auto &leaf) { activate(leaf); }, *active_actor);
58 active_actor.swap(other);
60 std::visit([&](
auto &leaf) { deactivate(leaf); }, *other);
64 cleanup_if_any_rank_failed(
false);
66 cleanup_if_any_rank_failed(
true);
void add_actor(boost::mpi::communicator const &comm, std::shared_ptr< System::System > const &system, std::optional< Variant > &active_actor, std::shared_ptr< T > const &actor, F &&on_actor_change)