Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include "Options/String.hpp" 7 : #include "Parallel/GlobalCache.hpp" 8 : #include "Parallel/Local.hpp" 9 : #include "ParallelAlgorithms/EventsAndTriggers/Event.hpp" 10 : #include "Utilities/Serialization/CharmPupable.hpp" 11 : #include "Utilities/TMPL.hpp" 12 : 13 : /// \cond 14 : namespace Parallel::Actions { 15 : struct SetTerminateOnElement; 16 : } // namespace Parallel::Actions 17 : /// \endcond 18 : 19 : namespace Events { 20 : /// \ingroup EventsAndTriggersGroup 21 : /// Sets the termination flag for the code to exit. 22 1 : class Completion : public Event { 23 : public: 24 : /// \cond 25 : explicit Completion(CkMigrateMessage* /*unused*/) {} 26 : using PUP::able::register_constructor; 27 : WRAPPED_PUPable_decl_template(Completion); // NOLINT 28 : /// \endcond 29 : 30 0 : using compute_tags_for_observation_box = tmpl::list<>; 31 0 : using options = tmpl::list<>; 32 0 : static constexpr Options::String help = { 33 : "Sets the termination flag for the code to exit."}; 34 : 35 0 : Completion() = default; 36 : 37 0 : using return_tags = tmpl::list<>; 38 0 : using argument_tags = tmpl::list<>; 39 : 40 : template <typename Metavariables, typename ArrayIndex, typename Component> 41 0 : void operator()(Parallel::GlobalCache<Metavariables>& cache, 42 : const ArrayIndex& array_index, 43 : const Component* const /*meta*/, 44 : const ObservationValue& /*observation_value*/) const { 45 : if constexpr (Parallel::is_nodegroup_v<Component>) { 46 : Parallel::local_synchronous_action< 47 : Parallel::Actions::SetTerminateOnElement>( 48 : Parallel::get_parallel_component<Component>(cache), 49 : make_not_null(&cache), array_index, true); 50 : } else { 51 : auto al_gore = Parallel::local( 52 : Parallel::get_parallel_component<Component>(cache)[array_index]); 53 : al_gore->set_terminate(true); 54 : } 55 : } 56 : 57 0 : using is_ready_argument_tags = tmpl::list<>; 58 : 59 : template <typename Metavariables, typename ArrayIndex, typename Component> 60 0 : bool is_ready(Parallel::GlobalCache<Metavariables>& /*cache*/, 61 : const ArrayIndex& /*array_index*/, 62 : const Component* const /*meta*/) const { 63 : return true; 64 : } 65 : 66 1 : bool needs_evolved_variables() const override { return false; } 67 : }; 68 : } // namespace Events