Skip to content

Commit

Permalink
Adjust phase control test to test singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
nikwit committed Dec 10, 2024
1 parent ae1f09a commit 6944ebe
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/DevGuide/Parallelization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions tests/Unit/Parallel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

#pragma once

#include "Framework/TestingFramework.hpp"

#include <cstddef>
Expand Down Expand Up @@ -165,7 +167,7 @@ struct ComponentAlpha {

template <typename Metavariables>
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;

Expand Down Expand Up @@ -274,7 +276,7 @@ struct TerminateAndRestart {
const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
const ParallelComponent* const /*meta*/) {
if (db::get<Tags::Step>(box) % interval == 0) {
if(db::get<Tags::Step>(box) < 15) {
if (db::get<Tags::Step>(box) < 15) {
Parallel::simple_action<Actions::RestartMe<ParallelComponent>>(
Parallel::get_parallel_component<OtherComponent>(cache));

Expand Down Expand Up @@ -335,9 +337,12 @@ struct Testing {
// 7: Register | none
// 10: none | Solve
// 14: none | Register and Solve
template <typename ComponentBetaChareType>
struct TestMetavariables {
using component_list = tmpl::list<ComponentAlpha<TestMetavariables>,
ComponentBeta<TestMetavariables>>;
using component_beta_chare_type = ComponentBetaChareType;
using component_list =
tmpl::list<ComponentAlpha<TestMetavariables<ComponentBetaChareType>>,
ComponentBeta<TestMetavariables<ComponentBetaChareType>>>;

struct factory_creation
: tt::ConformsTo<Options::protocols::FactoryCreation> {
Expand All @@ -364,7 +369,8 @@ struct TestMetavariables {
}

static std::string expected_log(
tmpl::type_<ComponentAlpha<TestMetavariables>> /*meta*/) {
tmpl::type_<
ComponentAlpha<TestMetavariables<ComponentBetaChareType>>> /*meta*/) {
return "Running phase: Initialization\n" +
repeat("Running phase: Evolve\n", 2_st) +
"Terminate and Restart\n"
Expand Down Expand Up @@ -397,7 +403,8 @@ struct TestMetavariables {
}

static std::string expected_log(
tmpl::type_<ComponentBeta<TestMetavariables>> /*meta*/) {
tmpl::type_<
ComponentBeta<TestMetavariables<ComponentBetaChareType>>> /*meta*/) {
return "Running phase: Initialization\n" +
repeat("Running phase: Evolve\n", 3_st) + // steps 1-3 -> Solve
"Running phase: Solve\n"
Expand Down Expand Up @@ -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<TestMetavariables>();
Parallel::charmxx::register_init_node_and_proc(
{&register_factory_classes_with_charm<TestMetavariables>}, {});
}
// [charm_init_funcs_example]
17 changes: 17 additions & 0 deletions tests/Unit/Parallel/Test_AlgorithmPhaseControlNodegroup.cpp
Original file line number Diff line number Diff line change
@@ -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::Algorithms::Nodegroup>>();
Parallel::charmxx::register_init_node_and_proc(
{&register_factory_classes_with_charm<
TestMetavariables<Parallel::Algorithms::Nodegroup>>},
{});
}
// [charm_init_funcs_example]
15 changes: 15 additions & 0 deletions tests/Unit/Parallel/Test_AlgorithmPhaseControlSingleton.cpp
Original file line number Diff line number Diff line change
@@ -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::Algorithms::Singleton>>();
Parallel::charmxx::register_init_node_and_proc(
{&register_factory_classes_with_charm<
TestMetavariables<Parallel::Algorithms::Singleton>>},
{});
}
19 changes: 19 additions & 0 deletions tests/Unit/Parallel/Test_AlgorithmPhaseControlSingleton.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6944ebe

Please sign in to comment.