From cd7f036ab635f70b336b138d5ce74548499820d8 Mon Sep 17 00:00:00 2001 From: Kyle Nelli Date: Mon, 14 Oct 2024 21:31:30 -0700 Subject: [PATCH] Change TerminatePhase return value Now TerminatePhase returns Parallel::AlgorithmExecution::Halt. Also added a new action PausePhase which returns Parallel::AlgorithmExecution::Pause if that is needed. This changes how the algorithm ends at the end of a phase. --- src/ParallelAlgorithms/Actions/CMakeLists.txt | 1 + src/ParallelAlgorithms/Actions/PausePhase.hpp | 44 +++++++++++++++++++ .../Actions/TerminatePhase.hpp | 11 +++-- .../Test_SubdomainOperator.cpp | 10 ++--- .../DiscontinuousGalerkin/Test_DgOperator.cpp | 3 +- .../Test_AnalyticBoundaryCommunication.cpp | 4 +- .../Actions/Test_H5BoundaryCommunication.cpp | 4 +- ...Test_InitializeCharacteristicEvolution.cpp | 2 +- ...lizeKleinGordonCharacteristicEvolution.cpp | 2 +- .../Test_InitializeWorldtubeBoundary.cpp | 6 +-- .../Test_InsertInterpolationScriData.cpp | 2 +- ...est_KleinGordonH5BoundaryCommunication.cpp | 4 +- .../Cce/Actions/Test_RequestBoundaryData.cpp | 4 +- .../Test_RequestKleinGordonBoundaryData.cpp | 2 +- .../ParallelAlgorithms/Actions/CMakeLists.txt | 1 + .../Actions/Test_PausePhase.cpp | 38 ++++++++++++++++ .../Time/Actions/Test_SelfStartActions.cpp | 15 +++++-- 17 files changed, 122 insertions(+), 31 deletions(-) create mode 100644 src/ParallelAlgorithms/Actions/PausePhase.hpp create mode 100644 tests/Unit/ParallelAlgorithms/Actions/Test_PausePhase.cpp diff --git a/src/ParallelAlgorithms/Actions/CMakeLists.txt b/src/ParallelAlgorithms/Actions/CMakeLists.txt index 5b84978b537a..8bb48f5a879c 100644 --- a/src/ParallelAlgorithms/Actions/CMakeLists.txt +++ b/src/ParallelAlgorithms/Actions/CMakeLists.txt @@ -18,6 +18,7 @@ spectre_target_headers( InitializeItems.hpp LimiterActions.hpp MutateApply.hpp + PausePhase.hpp RandomizeVariables.hpp SetData.hpp TerminatePhase.hpp diff --git a/src/ParallelAlgorithms/Actions/PausePhase.hpp b/src/ParallelAlgorithms/Actions/PausePhase.hpp new file mode 100644 index 000000000000..413c076b1262 --- /dev/null +++ b/src/ParallelAlgorithms/Actions/PausePhase.hpp @@ -0,0 +1,44 @@ +// Distributed under the MIT License. +// See LICENSE.txt for details. + +#pragma once + +#include + +#include "Parallel/AlgorithmExecution.hpp" + +/// \cond +namespace tuples { +template +struct TaggedTuple; +} // namespace tuples +namespace Parallel { +template +class GlobalCache; +} // namespace Parallel +/// \endcond + +namespace Parallel::Actions { + +/*! + * \ingroup ActionsGroup + * \brief Pause the algorithm by returning + * `Parallel::AlgorithmExecution::Pause`. + */ +struct PausePhase { + template + static Parallel::iterable_action_return_t apply( + DataBox& /*box*/, const tuples::TaggedTuple& /*inboxes*/, + const Parallel::GlobalCache& /*cache*/, + const ArrayIndex& /*array_index*/, + // NOLINTNEXTLINE(readability-avoid-const-params-in-decls) + const ActionList /*meta*/, + // NOLINTNEXTLINE(readability-avoid-const-params-in-decls) + const ParallelComponent* const /*meta*/) { + return {Parallel::AlgorithmExecution::Pause, std::nullopt}; + } +}; + +} // namespace Parallel::Actions diff --git a/src/ParallelAlgorithms/Actions/TerminatePhase.hpp b/src/ParallelAlgorithms/Actions/TerminatePhase.hpp index 10211ca35cdb..064aa4376a64 100644 --- a/src/ParallelAlgorithms/Actions/TerminatePhase.hpp +++ b/src/ParallelAlgorithms/Actions/TerminatePhase.hpp @@ -18,12 +18,12 @@ class GlobalCache; } // namespace Parallel /// \endcond -namespace Parallel { -namespace Actions { +namespace Parallel::Actions { /*! * \ingroup ActionsGroup - * \brief Terminate the algorithm to proceed to the next phase. + * \brief Halt the algorithm and wait to proceed to the next phase by returning + * `Parallel::AlgorithmExecution::Halt` */ struct TerminatePhase { template , init_subdomain_action, init_random_subdomain_data_action, - Parallel::Actions::TerminatePhase, + Parallel::Actions::PausePhase, // Full DG operator typename dg_operator::apply_actions, - Parallel::Actions::TerminatePhase, + Parallel::Actions::PausePhase, // Subdomain operator ApplySubdomainOperator, TestSubdomainOperatorMatrix, - Parallel::Actions::TerminatePhase>>>; + Parallel::Actions::PausePhase>>>; }; template @@ -605,8 +606,7 @@ void test_subdomain_operator( {initial_ref_levs, initial_extents, SubdomainOperator{}, typename subdomain_operator_applied_to_fields_tag::type{}, override_boundary_conditions}); - while ( - not ActionTesting::get_terminate(runner, element_id)) { + for (size_t i = 0; i < 4 + tmpl::size::value; i++) { ActionTesting::next_action(make_not_null(&runner), element_id); } diff --git a/tests/Unit/Elliptic/DiscontinuousGalerkin/Test_DgOperator.cpp b/tests/Unit/Elliptic/DiscontinuousGalerkin/Test_DgOperator.cpp index 5e2d863c6633..0e28115b1a3f 100644 --- a/tests/Unit/Elliptic/DiscontinuousGalerkin/Test_DgOperator.cpp +++ b/tests/Unit/Elliptic/DiscontinuousGalerkin/Test_DgOperator.cpp @@ -46,6 +46,7 @@ #include "Parallel/Phase.hpp" #include "ParallelAlgorithms/Actions/Goto.hpp" #include "ParallelAlgorithms/Actions/InitializeItems.hpp" +#include "ParallelAlgorithms/Actions/PausePhase.hpp" #include "ParallelAlgorithms/Actions/SetData.hpp" #include "ParallelAlgorithms/Actions/TerminatePhase.hpp" #include "ParallelAlgorithms/Amr/Actions/Component.hpp" @@ -156,7 +157,7 @@ struct ElementArray { System, fixed_sources_tag>, ::Actions::Label, typename dg_operator::apply_actions, IncrementTemporalId, - Parallel::Actions::TerminatePhase>>>; + Parallel::Actions::PausePhase>>>; }; template diff --git a/tests/Unit/Evolution/Systems/Cce/Actions/Test_AnalyticBoundaryCommunication.cpp b/tests/Unit/Evolution/Systems/Cce/Actions/Test_AnalyticBoundaryCommunication.cpp index 37eb95e28d7b..ec4db33ac3dd 100644 --- a/tests/Unit/Evolution/Systems/Cce/Actions/Test_AnalyticBoundaryCommunication.cpp +++ b/tests/Unit/Evolution/Systems/Cce/Actions/Test_AnalyticBoundaryCommunication.cpp @@ -209,10 +209,10 @@ SPECTRE_TEST_CASE( std::make_unique<::TimeSteppers::DormandPrince5>())); // Run the initializations - for (size_t i = 0; i < 6; ++i) { + for (size_t i = 0; i < 5; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } - for (size_t i = 0; i < 3; ++i) { + for (size_t i = 0; i < 2; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } runner.set_phase(Parallel::Phase::Evolve); diff --git a/tests/Unit/Evolution/Systems/Cce/Actions/Test_H5BoundaryCommunication.cpp b/tests/Unit/Evolution/Systems/Cce/Actions/Test_H5BoundaryCommunication.cpp index f8454ca033c5..b14d9edba6a4 100644 --- a/tests/Unit/Evolution/Systems/Cce/Actions/Test_H5BoundaryCommunication.cpp +++ b/tests/Unit/Evolution/Systems/Cce/Actions/Test_H5BoundaryCommunication.cpp @@ -257,10 +257,10 @@ SPECTRE_TEST_CASE("Unit.Evolution.Systems.Cce.Actions.H5BoundaryCommunication", false, false, std::optional{})); // this should run the initializations - for (size_t i = 0; i < 5; ++i) { + for (size_t i = 0; i < 4; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } - for (size_t i = 0; i < 2; ++i) { + for (size_t i = 0; i < 1; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } ActionTesting::set_phase(make_not_null(&runner), Parallel::Phase::Evolve); diff --git a/tests/Unit/Evolution/Systems/Cce/Actions/Test_InitializeCharacteristicEvolution.cpp b/tests/Unit/Evolution/Systems/Cce/Actions/Test_InitializeCharacteristicEvolution.cpp index f3a21ee4f914..196ba588dbb9 100644 --- a/tests/Unit/Evolution/Systems/Cce/Actions/Test_InitializeCharacteristicEvolution.cpp +++ b/tests/Unit/Evolution/Systems/Cce/Actions/Test_InitializeCharacteristicEvolution.cpp @@ -198,7 +198,7 @@ SPECTRE_TEST_CASE( target_step_size, scri_plus_interpolation_order); // this should run the initialization - for (size_t i = 0; i < 6; ++i) { + for (size_t i = 0; i < 5; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } ActionTesting::set_phase(make_not_null(&runner), Parallel::Phase::Evolve); diff --git a/tests/Unit/Evolution/Systems/Cce/Actions/Test_InitializeKleinGordonCharacteristicEvolution.cpp b/tests/Unit/Evolution/Systems/Cce/Actions/Test_InitializeKleinGordonCharacteristicEvolution.cpp index cf5dd6cbc5b3..f1a62e029228 100644 --- a/tests/Unit/Evolution/Systems/Cce/Actions/Test_InitializeKleinGordonCharacteristicEvolution.cpp +++ b/tests/Unit/Evolution/Systems/Cce/Actions/Test_InitializeKleinGordonCharacteristicEvolution.cpp @@ -183,7 +183,7 @@ void test_klein_gordon_cce_initialization(const gsl::not_null gen) { target_step_size, scri_plus_interpolation_order); // go through the action list - for (size_t i = 0; i < 7; ++i) { + for (size_t i = 0; i < 6; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } ActionTesting::set_phase(make_not_null(&runner), Parallel::Phase::Evolve); diff --git a/tests/Unit/Evolution/Systems/Cce/Actions/Test_InitializeWorldtubeBoundary.cpp b/tests/Unit/Evolution/Systems/Cce/Actions/Test_InitializeWorldtubeBoundary.cpp index 74ef0b695d18..5624812640e6 100644 --- a/tests/Unit/Evolution/Systems/Cce/Actions/Test_InitializeWorldtubeBoundary.cpp +++ b/tests/Unit/Evolution/Systems/Cce/Actions/Test_InitializeWorldtubeBoundary.cpp @@ -128,7 +128,7 @@ void test_h5_initialization(const gsl::not_null gen) { false, false, std::optional{})); // this should run the initialization - for (size_t i = 0; i < 3; ++i) { + for (size_t i = 0; i < 2; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } ActionTesting::set_phase(make_not_null(&runner), Parallel::Phase::Evolve); @@ -177,7 +177,7 @@ void test_gh_initialization() { InterfaceManagers::GhLockstep{}); // this should run the initialization - for (size_t i = 0; i < 3; ++i) { + for (size_t i = 0; i < 2; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } runner.set_phase(Parallel::Phase::Evolve); @@ -210,7 +210,7 @@ void test_analytic_initialization() { static_cast>( std::make_unique<::TimeSteppers::Rk3HesthavenSsp>())); // this should run the initialization - for (size_t i = 0; i < 3; ++i) { + for (size_t i = 0; i < 2; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } runner.set_phase(Parallel::Phase::Evolve); diff --git a/tests/Unit/Evolution/Systems/Cce/Actions/Test_InsertInterpolationScriData.cpp b/tests/Unit/Evolution/Systems/Cce/Actions/Test_InsertInterpolationScriData.cpp index 648a17432984..908c951ea931 100644 --- a/tests/Unit/Evolution/Systems/Cce/Actions/Test_InsertInterpolationScriData.cpp +++ b/tests/Unit/Evolution/Systems/Cce/Actions/Test_InsertInterpolationScriData.cpp @@ -289,7 +289,7 @@ SPECTRE_TEST_CASE( ActionTesting::emplace_component>(&runner, 0); // the initialization actions - for (size_t i = 0; i < 6; ++i) { + for (size_t i = 0; i < 5; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } runner.set_phase(Parallel::Phase::Evolve); diff --git a/tests/Unit/Evolution/Systems/Cce/Actions/Test_KleinGordonH5BoundaryCommunication.cpp b/tests/Unit/Evolution/Systems/Cce/Actions/Test_KleinGordonH5BoundaryCommunication.cpp index 607437ed29e1..128be00aa9d9 100644 --- a/tests/Unit/Evolution/Systems/Cce/Actions/Test_KleinGordonH5BoundaryCommunication.cpp +++ b/tests/Unit/Evolution/Systems/Cce/Actions/Test_KleinGordonH5BoundaryCommunication.cpp @@ -236,10 +236,10 @@ void test_klein_gordon_h5_boundary_communication( std::optional{})); // this should run the initializations - for (size_t i = 0; i < 6; ++i) { + for (size_t i = 0; i < 5; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } - for (size_t i = 0; i < 2; ++i) { + for (size_t i = 0; i < 1; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } diff --git a/tests/Unit/Evolution/Systems/Cce/Actions/Test_RequestBoundaryData.cpp b/tests/Unit/Evolution/Systems/Cce/Actions/Test_RequestBoundaryData.cpp index 7154afdf526c..e2e410180e57 100644 --- a/tests/Unit/Evolution/Systems/Cce/Actions/Test_RequestBoundaryData.cpp +++ b/tests/Unit/Evolution/Systems/Cce/Actions/Test_RequestBoundaryData.cpp @@ -222,10 +222,10 @@ SPECTRE_TEST_CASE("Unit.Evolution.Systems.Cce.Actions.RequestBoundaryData", false, false, std::optional{})); // this should run the initializations - for (size_t i = 0; i < 5; ++i) { + for (size_t i = 0; i < 4; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } - for(size_t i = 0; i < 3; ++i) { + for (size_t i = 0; i < 2; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } ActionTesting::set_phase(make_not_null(&runner), Parallel::Phase::Evolve); diff --git a/tests/Unit/Evolution/Systems/Cce/Actions/Test_RequestKleinGordonBoundaryData.cpp b/tests/Unit/Evolution/Systems/Cce/Actions/Test_RequestKleinGordonBoundaryData.cpp index 33a8c1666df3..242451f1dc7b 100644 --- a/tests/Unit/Evolution/Systems/Cce/Actions/Test_RequestKleinGordonBoundaryData.cpp +++ b/tests/Unit/Evolution/Systems/Cce/Actions/Test_RequestKleinGordonBoundaryData.cpp @@ -204,7 +204,7 @@ void test_klein_gordon_boundary_data(const gsl::not_null gen) { std::optional{})); // this should run the initializations - for (size_t i = 0; i < 6; ++i) { + for (size_t i = 0; i < 5; ++i) { ActionTesting::next_action(make_not_null(&runner), 0); } for (size_t i = 0; i < 2; ++i) { diff --git a/tests/Unit/ParallelAlgorithms/Actions/CMakeLists.txt b/tests/Unit/ParallelAlgorithms/Actions/CMakeLists.txt index f7473563cfe3..7fd6be268c4a 100644 --- a/tests/Unit/ParallelAlgorithms/Actions/CMakeLists.txt +++ b/tests/Unit/ParallelAlgorithms/Actions/CMakeLists.txt @@ -9,6 +9,7 @@ set(LIBRARY_SOURCES Test_Goto.cpp Test_InitializeItems.cpp Test_MutateApply.cpp + Test_PausePhase.cpp Test_RandomizeVariables.cpp Test_SetData.cpp Test_TerminatePhase.cpp diff --git a/tests/Unit/ParallelAlgorithms/Actions/Test_PausePhase.cpp b/tests/Unit/ParallelAlgorithms/Actions/Test_PausePhase.cpp new file mode 100644 index 000000000000..834d2821ac2c --- /dev/null +++ b/tests/Unit/ParallelAlgorithms/Actions/Test_PausePhase.cpp @@ -0,0 +1,38 @@ +// Distributed under the MIT License. +// See LICENSE.txt for details. + +#include "Framework/TestingFramework.hpp" + +#include "Framework/ActionTesting.hpp" +#include "Parallel/Phase.hpp" +#include "ParallelAlgorithms/Actions/PausePhase.hpp" +#include "Utilities/TMPL.hpp" + +namespace { +template +struct Component { + using metavariables = Metavariables; + using chare_type = ActionTesting::MockArrayChare; + using array_index = int; + using phase_dependent_action_list = tmpl::list>>; +}; + +struct Metavariables { + using component_list = tmpl::list>; +}; +} // namespace + +SPECTRE_TEST_CASE("Unit.Parallel.Actions.PausePhase", + "[Unit][Parallel][Actions]") { + using component = Component; + + ActionTesting::MockRuntimeSystem runner{{}}; + ActionTesting::emplace_component(&runner, 0); + + ActionTesting::set_phase(make_not_null(&runner), Parallel::Phase::Testing); + + CHECK_FALSE(ActionTesting::get_terminate(runner, 0)); + ActionTesting::next_action(make_not_null(&runner), 0); + CHECK(ActionTesting::get_terminate(runner, 0)); +} diff --git a/tests/Unit/Time/Actions/Test_SelfStartActions.cpp b/tests/Unit/Time/Actions/Test_SelfStartActions.cpp index 360ab7465fb9..94a29cd067c9 100644 --- a/tests/Unit/Time/Actions/Test_SelfStartActions.cpp +++ b/tests/Unit/Time/Actions/Test_SelfStartActions.cpp @@ -25,6 +25,8 @@ #include "Parallel/AlgorithmExecution.hpp" #include "Parallel/Phase.hpp" #include "Parallel/PhaseDependentActionList.hpp" +#include "ParallelAlgorithms/Actions/PausePhase.hpp" +#include "ParallelAlgorithms/Actions/TerminatePhase.hpp" #include "Time/Actions/CleanHistory.hpp" #include "Time/Actions/RecordTimeStepperData.hpp" #include "Time/Actions/SelfStartActions.hpp" @@ -161,10 +163,15 @@ struct Component { Actions::CleanHistory, tmpl::conditional_t>>; - using action_list = tmpl::flatten< - tmpl::list, - step_actions>>; + // This test doesn't operate exactly like how SelfStart would normally work in + // an executable. Instead it jumps around quite a lot. Therefore to avoid any + // issues that TerminatePhase would cause, we just replace it with PausePhase. + using action_list = tmpl::replace< + tmpl::flatten< + tmpl::list, + step_actions>>, + Parallel::Actions::TerminatePhase, Parallel::Actions::PausePhase>; using phase_dependent_action_list = tmpl::list< Parallel::PhaseActions