From 6944ebef69f56491ff9d8ee3b8f08cc6257b4d51 Mon Sep 17 00:00:00 2001 From: Nikolas Date: Tue, 10 Dec 2024 20:29:08 +0100 Subject: [PATCH] Adjust phase control test to test singletons --- docs/DevGuide/Parallelization.md | 2 +- tests/Unit/Parallel/CMakeLists.txt | 7 +++-- ...rol.cpp => Test_AlgorithmPhaseControl.hpp} | 27 +++++++++---------- .../Test_AlgorithmPhaseControlNodegroup.cpp | 17 ++++++++++++ ... Test_AlgorithmPhaseControlNodegroup.yaml} | 0 .../Test_AlgorithmPhaseControlSingleton.cpp | 15 +++++++++++ .../Test_AlgorithmPhaseControlSingleton.yaml | 19 +++++++++++++ 7 files changed, 70 insertions(+), 17 deletions(-) rename tests/Unit/Parallel/{Test_AlgorithmPhaseControl.cpp => Test_AlgorithmPhaseControl.hpp} (96%) create mode 100644 tests/Unit/Parallel/Test_AlgorithmPhaseControlNodegroup.cpp rename tests/Unit/Parallel/{Test_AlgorithmPhaseControl.yaml => Test_AlgorithmPhaseControlNodegroup.yaml} (100%) create mode 100644 tests/Unit/Parallel/Test_AlgorithmPhaseControlSingleton.cpp create mode 100644 tests/Unit/Parallel/Test_AlgorithmPhaseControlSingleton.yaml diff --git a/docs/DevGuide/Parallelization.md b/docs/DevGuide/Parallelization.md index 0013a542ace8d..c866ca418cbde 100644 --- a/docs/DevGuide/Parallelization.md +++ b/docs/DevGuide/Parallelization.md @@ -866,4 +866,4 @@ also be run. Which functions are run on each node and core is set by calling `Parallel::charmxx::register_init_node_and_proc` in `CkRegisterMainModule()` with function pointers to the functions to be called. For example: -\snippet Test_AlgorithmPhaseControl.cpp charm_init_funcs_example +\snippet Test_AlgorithmPhaseControlNodegroup.cpp charm_init_funcs_example diff --git a/tests/Unit/Parallel/CMakeLists.txt b/tests/Unit/Parallel/CMakeLists.txt index dc9e6fb13c02c..4276258fad487 100644 --- a/tests/Unit/Parallel/CMakeLists.txt +++ b/tests/Unit/Parallel/CMakeLists.txt @@ -147,8 +147,11 @@ add_algorithm_test( "AlgorithmGlobalCache" INPUT_FILE "Test_AlgorithmGlobalCache.yaml") add_algorithm_test( - "AlgorithmPhaseControl" - INPUT_FILE "Test_AlgorithmPhaseControl.yaml") + "AlgorithmPhaseControlSingleton" + INPUT_FILE "Test_AlgorithmPhaseControlSingleton.yaml") +add_algorithm_test( + "AlgorithmPhaseControlNodegroup" + INPUT_FILE "Test_AlgorithmPhaseControlNodegroup.yaml") add_algorithm_test( "DynamicInsertionState" INPUT_FILE "Test_DynamicInsertionState.yaml") diff --git a/tests/Unit/Parallel/Test_AlgorithmPhaseControl.cpp b/tests/Unit/Parallel/Test_AlgorithmPhaseControl.hpp similarity index 96% rename from tests/Unit/Parallel/Test_AlgorithmPhaseControl.cpp rename to tests/Unit/Parallel/Test_AlgorithmPhaseControl.hpp index 3dac11f1141a3..f51d64c9f7af2 100644 --- a/tests/Unit/Parallel/Test_AlgorithmPhaseControl.cpp +++ b/tests/Unit/Parallel/Test_AlgorithmPhaseControl.hpp @@ -1,6 +1,8 @@ // Distributed under the MIT License. // See LICENSE.txt for details. +#pragma once + #include "Framework/TestingFramework.hpp" #include @@ -165,7 +167,7 @@ struct ComponentAlpha { template struct ComponentBeta { - using chare_type = Parallel::Algorithms::Nodegroup; + using chare_type = typename Metavariables::component_beta_chare_type; using metavariables = Metavariables; using array_index = size_t; @@ -274,7 +276,7 @@ struct TerminateAndRestart { const ArrayIndex& /*array_index*/, const ActionList /*meta*/, const ParallelComponent* const /*meta*/) { if (db::get(box) % interval == 0) { - if(db::get(box) < 15) { + if (db::get(box) < 15) { Parallel::simple_action>( Parallel::get_parallel_component(cache)); @@ -335,9 +337,12 @@ struct Testing { // 7: Register | none // 10: none | Solve // 14: none | Register and Solve +template struct TestMetavariables { - using component_list = tmpl::list, - ComponentBeta>; + using component_beta_chare_type = ComponentBetaChareType; + using component_list = + tmpl::list>, + ComponentBeta>>; struct factory_creation : tt::ConformsTo { @@ -364,7 +369,8 @@ struct TestMetavariables { } static std::string expected_log( - tmpl::type_> /*meta*/) { + tmpl::type_< + ComponentAlpha>> /*meta*/) { return "Running phase: Initialization\n" + repeat("Running phase: Evolve\n", 2_st) + "Terminate and Restart\n" @@ -397,7 +403,8 @@ struct TestMetavariables { } static std::string expected_log( - tmpl::type_> /*meta*/) { + tmpl::type_< + ComponentBeta>> /*meta*/) { return "Running phase: Initialization\n" + repeat("Running phase: Evolve\n", 3_st) + // steps 1-3 -> Solve "Running phase: Solve\n" @@ -429,11 +436,3 @@ struct TestMetavariables { // NOLINTNEXTLINE(google-runtime-references) void pup(PUP::er& /*p*/) {} }; - -// [charm_init_funcs_example] -extern "C" void CkRegisterMainModule() { - Parallel::charmxx::register_main_module(); - Parallel::charmxx::register_init_node_and_proc( - {®ister_factory_classes_with_charm}, {}); -} -// [charm_init_funcs_example] diff --git a/tests/Unit/Parallel/Test_AlgorithmPhaseControlNodegroup.cpp b/tests/Unit/Parallel/Test_AlgorithmPhaseControlNodegroup.cpp new file mode 100644 index 0000000000000..60f2bfe120239 --- /dev/null +++ b/tests/Unit/Parallel/Test_AlgorithmPhaseControlNodegroup.cpp @@ -0,0 +1,17 @@ +// Distributed under the MIT License. +// See LICENSE.txt for details. + +#include "Parallel/Test_AlgorithmPhaseControl.hpp" + +#include "Parallel/Algorithms/AlgorithmNodegroup.hpp" + +// [charm_init_funcs_example] +extern "C" void CkRegisterMainModule() { + Parallel::charmxx::register_main_module< + TestMetavariables>(); + Parallel::charmxx::register_init_node_and_proc( + {®ister_factory_classes_with_charm< + TestMetavariables>}, + {}); +} +// [charm_init_funcs_example] diff --git a/tests/Unit/Parallel/Test_AlgorithmPhaseControl.yaml b/tests/Unit/Parallel/Test_AlgorithmPhaseControlNodegroup.yaml similarity index 100% rename from tests/Unit/Parallel/Test_AlgorithmPhaseControl.yaml rename to tests/Unit/Parallel/Test_AlgorithmPhaseControlNodegroup.yaml diff --git a/tests/Unit/Parallel/Test_AlgorithmPhaseControlSingleton.cpp b/tests/Unit/Parallel/Test_AlgorithmPhaseControlSingleton.cpp new file mode 100644 index 0000000000000..f84f20b67d11a --- /dev/null +++ b/tests/Unit/Parallel/Test_AlgorithmPhaseControlSingleton.cpp @@ -0,0 +1,15 @@ +// Distributed under the MIT License. +// See LICENSE.txt for details. + +#include "Parallel/Test_AlgorithmPhaseControl.hpp" + +#include "Parallel/Algorithms/AlgorithmSingleton.hpp" + +extern "C" void CkRegisterMainModule() { + Parallel::charmxx::register_main_module< + TestMetavariables>(); + Parallel::charmxx::register_init_node_and_proc( + {®ister_factory_classes_with_charm< + TestMetavariables>}, + {}); +} diff --git a/tests/Unit/Parallel/Test_AlgorithmPhaseControlSingleton.yaml b/tests/Unit/Parallel/Test_AlgorithmPhaseControlSingleton.yaml new file mode 100644 index 0000000000000..d32d167ae301e --- /dev/null +++ b/tests/Unit/Parallel/Test_AlgorithmPhaseControlSingleton.yaml @@ -0,0 +1,19 @@ +# Distributed under the MIT License. +# See LICENSE.txt for details. + +--- +--- + +# note that this is a vector of pairs, so has the peculiar '- -' for the +# elements +PhaseChangeAndTriggers: + - Trigger: RegisterTrigger + PhaseChanges: + - VisitAndReturn(Register) + - Trigger: SolveTrigger + PhaseChanges: + - VisitAndReturn(Solve) + +ResourceInfo: + AvoidGlobalProc0: false + Singletons: Auto