QMCPACK
test_runtime_manager.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2017 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
16 #include <stdio.h>
17 #include <string>
18 #include <vector>
19 
20 using namespace std::chrono_literals;
21 
22 namespace qmcplusplus
23 {
24 
25 // Convert duration input type to nanosecond duration
26 template<typename T>
28 {
29  return std::chrono::duration_cast<std::chrono::nanoseconds>(in);
30 }
31 
32 TEST_CASE("test_runtime_manager", "[utilities]")
33 {
34  // Use a local version rather than the global timer_manager, otherwise
35  // changes will persist from test to test.
37  FakeChronoClock::fake_chrono_clock_increment = convert_to_ns(1.0s);
38  double e = rm.elapsed();
39  CHECK(e == Approx(1.0));
40 }
41 
42 TEST_CASE("test_loop_timer", "[utilities]")
43 {
45  double it_time = loop.get_time_per_iteration();
46  CHECK(it_time == Approx(0.0));
47 
48  loop.start();
49  loop.stop();
50  it_time = loop.get_time_per_iteration();
51  CHECK(it_time == Approx(1.0));
52 
53  FakeChronoClock::fake_chrono_clock_increment = convert_to_ns(2.0s);
54  loop.start();
55  loop.stop();
56  it_time = loop.get_time_per_iteration();
57  CHECK(it_time == Approx(1.5)); // 2 iterations
58  // restore value
59  FakeChronoClock::fake_chrono_clock_increment = convert_to_ns(1.0s);
60 }
61 
62 TEST_CASE("test_loop_control", "[utilities]")
63 {
64  // fake clock advances every time "now" is called
66  int max_cpu_secs = 9;
67  RunTimeManager<FakeChronoClock> rm; // fake clock = 1
68  RunTimeControl<FakeChronoClock> rc(rm, max_cpu_secs, "dummy", false);
69  rc.runtime_padding(1.0);
70  REQUIRE(!rc.checkStop(loop)); // fake clock = 2
71 
72  loop.start(); // fake clock = 3
73  loop.stop(); // fake clock = 4
74  // fake clock = 5
75  // estimated time with margin and padding = 1.0 sec/it * 1.1 + 1.0 (pad) = 2.1
76  // remaining = 9 - 4.0 = 5.0 enough time for another loop.
77  REQUIRE(!rc.checkStop(loop));
78 
79  loop.start(); // fake clock = 6
80  loop.stop(); // fake clock = 7
81  // fake clock = 8
82  // estimated time with margin and padding = 1.0 sec/it * 1.1 + 1.0 = 2.1
83  // remaining = 9 - 8.0 = 1.0 not enough time for another loop
84  REQUIRE(rc.checkStop(loop));
85 
86  std::string msg = rc.generateStopMessage("QMC", 2);
87  REQUIRE(msg.size() > 0);
88 }
89 
90 
91 } // namespace qmcplusplus
void runtime_padding(int runtime_padding)
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::string generateStopMessage(const std::string &driverName, int block) const
generate stop message explaining why
FakeChronoClock::duration convert_to_ns(T in)
REQUIRE(std::filesystem::exists(filename))
std::chrono::nanoseconds duration
Definition: Clock.h:32
Class for determining elapsed run time enabling simulations to adjust to time limits.
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
bool checkStop(LoopTimer< CLOCK > &loop_timer)
check if the run needs to stop because of walltime or stop control file.
double get_time_per_iteration() const
TEST_CASE("test_loop_control", "[utilities]")