8
8
9
9
#include " DataStructures/DataBox/DataBox.hpp"
10
10
#include " Framework/TestCreation.hpp"
11
+ #include " Framework/TestHelpers.hpp"
11
12
#include " Options/Protocols/FactoryCreation.hpp"
12
13
#include " Parallel/ExitCode.hpp"
13
14
#include " Parallel/GlobalCache.hpp"
@@ -56,14 +57,12 @@ SPECTRE_TEST_CASE("Unit.Parallel.PhaseControl.CheckpointAndExitAfterWallclock",
56
57
{
57
58
INFO (" Test initialize phase change decision data" );
58
59
PhaseChangeDecisionData phase_change_decision_data{
59
- Parallel::Phase::Execute, true , 1.0 , true ,
60
- Parallel::ExitCode::Complete};
60
+ Parallel::Phase::Execute, true , true , Parallel::ExitCode::Complete};
61
61
phase_change0.initialize_phase_data <Metavariables>(
62
62
make_not_null (&phase_change_decision_data));
63
- // extra parens in the check prevent Catch from trying to stream the tuple
64
- CHECK ((phase_change_decision_data ==
65
- PhaseChangeDecisionData{std::nullopt, std::nullopt, false , true ,
66
- Parallel::ExitCode::Complete}));
63
+ CHECK (phase_change_decision_data ==
64
+ PhaseChangeDecisionData{std::nullopt, false , true ,
65
+ Parallel::ExitCode::Complete});
67
66
}
68
67
{
69
68
INFO (" Wallclock time < big trigger time" );
@@ -72,93 +71,76 @@ SPECTRE_TEST_CASE("Unit.Parallel.PhaseControl.CheckpointAndExitAfterWallclock",
72
71
// the PhaseChange with a big trigger time.
73
72
// (this assumes the test doesn't take 1h to get here)
74
73
PhaseChangeDecisionData phase_change_decision_data{
75
- std::nullopt, std::nullopt, true , true , Parallel::ExitCode::Complete};
74
+ std::nullopt, true , true , Parallel::ExitCode::Complete};
76
75
const auto decision_result = phase_change1.arbitrate_phase_change (
77
76
make_not_null (&phase_change_decision_data), Parallel::Phase::Execute,
78
77
cache);
79
- CHECK (( decision_result == std::nullopt) );
80
- CHECK (( phase_change_decision_data ==
81
- PhaseChangeDecisionData{std::nullopt, std::nullopt, false , true ,
82
- Parallel::ExitCode::Complete}) );
78
+ CHECK (decision_result == std::nullopt);
79
+ CHECK (phase_change_decision_data ==
80
+ PhaseChangeDecisionData{std::nullopt, false , true ,
81
+ Parallel::ExitCode::Complete});
83
82
}
84
83
{
85
84
INFO (" Wallclock time > small trigger time" );
86
85
// Now check case where wallclock time > trigger wallclock time, using
87
86
// the PhaseChange with a tiny trigger time.
88
87
// (this assumes the test takes at least a few cycles to get here)
89
88
PhaseChangeDecisionData phase_change_decision_data{
90
- std::nullopt, std::nullopt, true , true , Parallel::ExitCode::Complete};
89
+ std::nullopt, true , true , Parallel::ExitCode::Complete};
91
90
const auto decision_result = phase_change0.arbitrate_phase_change (
92
91
make_not_null (&phase_change_decision_data), Parallel::Phase::Execute,
93
92
cache);
94
- CHECK ((decision_result ==
95
- std::make_pair (
96
- Parallel::Phase::WriteCheckpoint,
97
- PhaseControl::ArbitrationStrategy::RunPhaseImmediately)));
98
- // It's impossible to know what the elapsed wallclock time will be, so we
99
- // check the tags one by one...
100
- CHECK ((tuples::get<PhaseControl::Tags::RestartPhase>(
101
- phase_change_decision_data) == Parallel::Phase::Execute));
102
- // Check recorded time in range: 0 second < time < 1 second
103
- // (this assumes test run duration falls in this time window)
104
- CHECK (tuples::get<PhaseControl::Tags::WallclockHoursAtCheckpoint>(
105
- phase_change_decision_data) > 0.0 );
106
- const double one_second = 1.0 / 3600.0 ;
107
- CHECK (tuples::get<PhaseControl::Tags::WallclockHoursAtCheckpoint>(
108
- phase_change_decision_data) < one_second);
109
- CHECK (tuples::get<PhaseControl::Tags::CheckpointAndExitRequested>(
110
- phase_change_decision_data) == false );
93
+ CHECK (
94
+ decision_result ==
95
+ std::make_pair (Parallel::Phase::WriteCheckpoint,
96
+ PhaseControl::ArbitrationStrategy::RunPhaseImmediately));
97
+ CHECK (phase_change_decision_data ==
98
+ PhaseChangeDecisionData{Parallel::Phase::Execute, false , true ,
99
+ Parallel::ExitCode::Complete});
111
100
}
112
101
{
113
102
INFO (" Restarting from checkpoint" );
114
103
// Check behavior following the checkpoint phase
115
- // First check case where wallclock time < recorded time, which corresponds
116
- // to restarting from a checkpoint. Should update options next.
117
- // (this assumes the test doesn't take 1h to get here)
104
+ const PhaseControl::CheckpointAndExitAfterWallclock phase_change_restart =
105
+ serialize_and_deserialize (phase_change0);
118
106
PhaseChangeDecisionData phase_change_decision_data{
119
- Parallel::Phase::Execute, 1.0 , false , true ,
120
- Parallel::ExitCode::Complete};
121
- auto decision_result = phase_change0.arbitrate_phase_change (
107
+ Parallel::Phase::Execute, false , true , Parallel::ExitCode::Complete};
108
+ auto decision_result = phase_change_restart.arbitrate_phase_change (
122
109
make_not_null (&phase_change_decision_data),
123
110
Parallel::Phase::WriteCheckpoint, cache);
124
- CHECK (( decision_result ==
125
- std::make_pair (
126
- Parallel::Phase::UpdateOptionsAtRestartFromCheckpoint,
127
- PhaseControl::ArbitrationStrategy::PermitAdditionalJumps) ));
128
- CHECK (( phase_change_decision_data ==
129
- PhaseChangeDecisionData{Parallel::Phase::Execute, 1.0 , false , true ,
130
- Parallel::ExitCode::Complete}) );
111
+ CHECK (decision_result ==
112
+ std::make_pair (
113
+ Parallel::Phase::UpdateOptionsAtRestartFromCheckpoint,
114
+ PhaseControl::ArbitrationStrategy::PermitAdditionalJumps));
115
+ CHECK (phase_change_decision_data ==
116
+ PhaseChangeDecisionData{Parallel::Phase::Execute, false , true ,
117
+ Parallel::ExitCode::Complete});
131
118
132
119
// Now, from update phase, go back to Execute
133
- decision_result = phase_change0 .arbitrate_phase_change (
120
+ decision_result = phase_change_restart .arbitrate_phase_change (
134
121
make_not_null (&phase_change_decision_data),
135
122
Parallel::Phase::UpdateOptionsAtRestartFromCheckpoint, cache);
136
- CHECK (( decision_result ==
137
- std::make_pair (
138
- Parallel::Phase::Execute,
139
- PhaseControl::ArbitrationStrategy::PermitAdditionalJumps) ));
140
- CHECK (( phase_change_decision_data ==
141
- PhaseChangeDecisionData{std::nullopt, std::nullopt, false , true ,
142
- Parallel::ExitCode::Complete}) );
123
+ CHECK (decision_result ==
124
+ std::make_pair (
125
+ Parallel::Phase::Execute,
126
+ PhaseControl::ArbitrationStrategy::PermitAdditionalJumps));
127
+ CHECK (phase_change_decision_data ==
128
+ PhaseChangeDecisionData{std::nullopt, false , true ,
129
+ Parallel::ExitCode::Complete});
143
130
}
144
131
{
145
132
INFO (" Exiting after checkpoint" );
146
- // Now check case where wallclock time > recorded time, which corresponds to
147
- // having just written a checkpoint. We want to exit with exit code 2 now.
148
- // (this assumes the test takes at least a few cycles to get here)
149
133
PhaseChangeDecisionData phase_change_decision_data{
150
- Parallel::Phase::Execute, 1e-15 , false , true ,
151
- Parallel::ExitCode::Complete};
134
+ Parallel::Phase::Execute, false , true , Parallel::ExitCode::Complete};
152
135
const auto decision_result = phase_change0.arbitrate_phase_change (
153
136
make_not_null (&phase_change_decision_data),
154
137
Parallel::Phase::WriteCheckpoint, cache);
155
- CHECK ((decision_result ==
156
- std::make_pair (
157
- Parallel::Phase::Exit,
158
- PhaseControl::ArbitrationStrategy::RunPhaseImmediately)));
159
138
CHECK (
160
- (phase_change_decision_data ==
161
- PhaseChangeDecisionData{Parallel::Phase::Execute, 1e-15 , false , true ,
162
- Parallel::ExitCode::ContinueFromCheckpoint}));
139
+ decision_result ==
140
+ std::make_pair (Parallel::Phase::Exit,
141
+ PhaseControl::ArbitrationStrategy::RunPhaseImmediately));
142
+ CHECK (phase_change_decision_data ==
143
+ PhaseChangeDecisionData{Parallel::Phase::Execute, false , true ,
144
+ Parallel::ExitCode::ContinueFromCheckpoint});
163
145
}
164
146
}
0 commit comments