QMCPACK
RunTimeControl< CLOCK > Class Template Reference
+ Collaboration diagram for RunTimeControl< CLOCK >:

Public Member Functions

 RunTimeControl (RunTimeManager< CLOCK > &rm, int maxCPUSecs, const std::string &stop_file_prefix, bool cleanup=true)
 constructor More...
 
bool checkStop (LoopTimer< CLOCK > &loop_timer)
 check if the run needs to stop because of walltime or stop control file. More...
 
std::string generateProgressMessage (const std::string &driverName, int block, int num_blocks) const
 generate terse progress messages More...
 
std::string generateStopMessage (const std::string &driverName, int block) const
 generate stop message explaining why More...
 
void runtime_padding (int runtime_padding)
 
void loop_margin (int loopMargin)
 

Private Types

enum  StopStatus { CONTINUE, MAX_SECONDS_PASSED, NOT_ENOUGH_TIME, STOP_FILE }
 

Private Member Functions

bool enough_time_for_next_iteration (LoopTimer< CLOCK > &loop_timer)
 
bool stop_file_requested ()
 

Private Attributes

const int MaxCPUSecs
 
double m_runtime_safety_padding
 
double m_loop_margin
 
double m_loop_time
 
double m_elapsed
 
double m_remaining
 
RunTimeManager< CLOCK > & runtimeManager
 
const std::string stop_filename_
 the prefix of the stop file (stop_file_prefix + ".STOP") More...
 
enum qmcplusplus::RunTimeControl::StopStatus stop_status_
 

Detailed Description

template<class CLOCK = ChronoClock>
class qmcplusplus::RunTimeControl< CLOCK >

Definition at line 70 of file RunTimeManager.h.

Member Enumeration Documentation

◆ StopStatus

enum StopStatus
strongprivate
Enumerator
CONTINUE 
MAX_SECONDS_PASSED 
NOT_ENOUGH_TIME 
STOP_FILE 

Definition at line 82 of file RunTimeManager.h.

83  {
84  CONTINUE, // keep running
85  MAX_SECONDS_PASSED, // all already passed max_seconds
86  NOT_ENOUGH_TIME, // not enough time for next iteration
87  STOP_FILE, // reqsuted stop from a file
88  } stop_status_;
enum qmcplusplus::RunTimeControl::StopStatus stop_status_

Constructor & Destructor Documentation

◆ RunTimeControl()

RunTimeControl ( RunTimeManager< CLOCK > &  rm,
int  maxCPUSecs,
const std::string &  stop_file_prefix,
bool  cleanup = true 
)

constructor

Parameters
rmthe RunTimeManager attached to
maxCPUSecsmaxmimal allowed seconds from the beginning of the simulation
stop_file_prefixthe prefix of the stop file
cleanupif true, clean up stop files left from previous simulations. Rank 0 handle this.

Definition at line 67 of file RunTimeManager.cpp.

References RunTimeControl< CLOCK >::m_loop_margin, RunTimeControl< CLOCK >::m_runtime_safety_padding, and RunTimeControl< CLOCK >::stop_filename_.

71  : MaxCPUSecs(maxCPUSecs),
72  runtimeManager(rm),
73  stop_filename_(stop_file_prefix + ".STOP"),
75 {
76  if (stop_file_prefix.empty())
77  throw std::runtime_error("Stop control filename prefix must not be empty!");
78 
79  if (cleanup)
80  {
81  std::remove(stop_filename_.c_str());
82  if (std::ifstream(stop_filename_.c_str()))
83  throw std::runtime_error("Failed to delete the existing stop control file \"" + stop_filename_ +
84  "\", cannot continue!");
85  }
86 
87  m_runtime_safety_padding = 30.0; // generous 30 seconds to allow for shut down?
88  m_loop_margin = 1.1; // 10% margin on average loop time?
89 }
const std::string stop_filename_
the prefix of the stop file (stop_file_prefix + ".STOP")
RunTimeManager< CLOCK > & runtimeManager
enum qmcplusplus::RunTimeControl::StopStatus stop_status_

Member Function Documentation

◆ checkStop()

bool checkStop ( LoopTimer< CLOCK > &  loop_timer)

check if the run needs to stop because of walltime or stop control file.

it should be called at the end of each block in a driver.

Definition at line 125 of file RunTimeManager.cpp.

Referenced by qmcplusplus::TEST_CASE().

126 {
127  bool need_to_stop = false;
128  need_to_stop |= !enough_time_for_next_iteration(loop_timer);
129  need_to_stop |= stop_file_requested();
130  return need_to_stop;
131 }
bool enough_time_for_next_iteration(LoopTimer< CLOCK > &loop_timer)

◆ enough_time_for_next_iteration()

bool enough_time_for_next_iteration ( LoopTimer< CLOCK > &  loop_timer)
private

Definition at line 92 of file RunTimeManager.cpp.

References LoopTimer< CLOCK >::get_time_per_iteration().

93 {
94  m_loop_time = loop_timer.get_time_per_iteration();
95  m_elapsed = runtimeManager.elapsed();
96 
97  if (m_elapsed >= MaxCPUSecs)
98  {
100  return false;
101  }
102 
104  bool enough_time = true;
106  enough_time = false;
107 
109  return enough_time;
110 }
RunTimeManager< CLOCK > & runtimeManager
enum qmcplusplus::RunTimeControl::StopStatus stop_status_

◆ generateProgressMessage()

std::string generateProgressMessage ( const std::string &  driverName,
int  block,
int  num_blocks 
) const

generate terse progress messages

Definition at line 134 of file RunTimeManager.cpp.

References qmcplusplus::log(), and qmcplusplus::hdf::num_blocks.

137 {
138  std::stringstream log;
139  if (block == 0 || block + 1 == num_blocks / 4 || block + 1 == num_blocks / 2 || block + 1 == (num_blocks * 3) / 4 ||
140  block + 1 == num_blocks)
141  {
142  log << "Completed block " << std::setw(4) << block + 1 << " of " << num_blocks << " average "
143  << std::setprecision(4) << m_loop_time << " secs/block after " << std::setprecision(4) << m_elapsed << " secs"
144  << std::endl;
145  }
146  return log.str();
147 }
const char num_blocks[]
Definition: HDFVersion.h:44
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)

◆ generateStopMessage()

std::string generateStopMessage ( const std::string &  driverName,
int  block 
) const

generate stop message explaining why

Definition at line 150 of file RunTimeManager.cpp.

References qmcplusplus::log().

Referenced by qmcplusplus::TEST_CASE().

151 {
152  std::stringstream log;
153  log << "RunTimeControl takes action in " << driverName << " driver." << std::endl;
155  log << "Time limit reached. Stopping after block " << block << std::endl
156  << "Hard limit (seconds) " << MaxCPUSecs << ", elapsed (seconds) " << m_elapsed << std::endl;
158  {
159  log << "Insufficient time for next block. Stopping after block " << block << std::endl;
160  log << " Iteration time per " << driverName << " block (seconds) = " << m_loop_time << std::endl;
161  log << " Elapsed time (seconds) = " << m_elapsed << std::endl;
162  log << " Remaining time (seconds) = " << m_remaining << std::endl;
163  }
165  log << "Stop requested from the control file \"" + stop_filename_ + "\", stopping after block " << block
166  << std::endl;
167  else
168  throw std::runtime_error("Unidentified stop status!");
169 
170  return log.str();
171 }
const std::string stop_filename_
the prefix of the stop file (stop_file_prefix + ".STOP")
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)
enum qmcplusplus::RunTimeControl::StopStatus stop_status_

◆ loop_margin()

void loop_margin ( int  loopMargin)
inline

Definition at line 114 of file RunTimeManager.h.

114 { m_loop_margin = loopMargin; }

◆ runtime_padding()

void runtime_padding ( int  runtime_padding)
inline

◆ stop_file_requested()

bool stop_file_requested ( )
private

Definition at line 113 of file RunTimeManager.cpp.

114 {
115  if (std::ifstream(stop_filename_.c_str()))
116  {
118  return true;
119  }
120  else
121  return false;
122 }
const std::string stop_filename_
the prefix of the stop file (stop_file_prefix + ".STOP")
enum qmcplusplus::RunTimeControl::StopStatus stop_status_

Member Data Documentation

◆ m_elapsed

double m_elapsed
private

Definition at line 76 of file RunTimeManager.h.

◆ m_loop_margin

double m_loop_margin
private

Definition at line 74 of file RunTimeManager.h.

Referenced by RunTimeControl< CLOCK >::RunTimeControl().

◆ m_loop_time

double m_loop_time
private

Definition at line 75 of file RunTimeManager.h.

◆ m_remaining

double m_remaining
private

Definition at line 77 of file RunTimeManager.h.

◆ m_runtime_safety_padding

double m_runtime_safety_padding
private

Definition at line 73 of file RunTimeManager.h.

Referenced by RunTimeControl< CLOCK >::RunTimeControl().

◆ MaxCPUSecs

const int MaxCPUSecs
private

Definition at line 72 of file RunTimeManager.h.

◆ runtimeManager

RunTimeManager<CLOCK>& runtimeManager
private

Definition at line 78 of file RunTimeManager.h.

◆ stop_filename_

const std::string stop_filename_
private

the prefix of the stop file (stop_file_prefix + ".STOP")

Definition at line 80 of file RunTimeManager.h.

Referenced by RunTimeControl< CLOCK >::RunTimeControl().

◆ stop_status_

enum qmcplusplus::RunTimeControl::StopStatus stop_status_
private

The documentation for this class was generated from the following files: