Skip to content

Commit

Permalink
Merge pull request #5314 from ye-luo/adjust-timer
Browse files Browse the repository at this point in the history
Move timers after no-op early return in WalkerLog classes
  • Loading branch information
prckent authored Feb 13, 2025
2 parents 043aaf6 + 7187560 commit 37ba639
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/QMCDrivers/WalkerLogCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ void WalkerLogCollector::init()

void WalkerLogCollector::startBlock()
{
ScopedTimer timer(walker_log_collector_timers_[Timer::START]);
if (!state_.logs_active)
return; // no-op for driver if logs are inactive

ScopedTimer timer(walker_log_collector_timers_[Timer::START]);

if (state_.verbose)
app_log() << "WalkerLogCollector::startBlock " << std::endl;
resetBuffers(); // resize buffers to zero rows
Expand All @@ -62,11 +64,11 @@ void WalkerLogCollector::collect(const MCPWalker& walker,
const QMCHamiltonian& ham,
int step)
{
ScopedTimer timer(walker_log_collector_timers_[Timer::COLLECT]);

if (!state_.logs_active)
return; // no-op for driver if logs are inactive

ScopedTimer timer(walker_log_collector_timers_[Timer::COLLECT]);

// only collect walker data at steps matching the period (default 1)
int current_step = (step == -1) ? pset.current_step : step;
if (current_step % state_.step_period != 0)
Expand Down
16 changes: 11 additions & 5 deletions src/QMCDrivers/WalkerLogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ std::unique_ptr<WalkerLogCollector> WalkerLogManager::makeCollector() const

void WalkerLogManager::startRun(RefVector<WalkerLogCollector>&& collectors)
{
ScopedTimer timer(walker_log_timers_[Timer::START]);
collectors_in_run_ = std::move(collectors);
if (!state.logs_active)
return; // no-op for driver if logs are inactive

ScopedTimer timer(walker_log_timers_[Timer::START]);

collectors_in_run_ = std::move(collectors);
if (collectors_in_run_.empty())
throw std::runtime_error("BUG collectors are empty but walker logs are active");
if (state.verbose)
Expand All @@ -105,9 +107,11 @@ void WalkerLogManager::startRun(RefVector<WalkerLogCollector>&& collectors)

void WalkerLogManager::stopRun()
{
ScopedTimer timer(walker_log_timers_[Timer::STOP]);
if (!state.logs_active)
return; // no-op for driver if logs are inactive

ScopedTimer timer(walker_log_timers_[Timer::STOP]);

if (state.verbose)
app_log() << "WalkerLogManager::stopRun " << std::endl;
collectors_in_run_.clear();
Expand All @@ -118,10 +122,11 @@ void WalkerLogManager::stopRun()

void WalkerLogManager::writeBuffers()
{
ScopedTimer timer(walker_log_timers_[Timer::WRITE]);
const RefVector<WalkerLogCollector>& collectors = collectors_in_run_;
if (!state.logs_active)
return; // no-op for driver if logs are inactive

ScopedTimer timer(walker_log_timers_[Timer::WRITE]);

if (state.verbose)
app_log() << "WalkerLogManager::writeBuffers " << std::endl;

Expand All @@ -144,6 +149,7 @@ void WalkerLogManager::writeBuffers()
wmed_particle_real_buffer.resetBuffer();
}

const RefVector<WalkerLogCollector>& collectors = collectors_in_run_;
// collect energy information and extract info from min/max/median energy walkers
if (write_min_data || write_max_data || write_med_data)
{
Expand Down

0 comments on commit 37ba639

Please sign in to comment.