Skip to content

Commit

Permalink
make walker log timers granular
Browse files Browse the repository at this point in the history
  • Loading branch information
PDoakORNL committed Feb 7, 2025
1 parent 83f0cb2 commit 99f9370
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 62 deletions.
24 changes: 7 additions & 17 deletions src/QMCDrivers/DMC/DMCBatched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,8 @@ void DMCBatched::advanceWalkers(const StateForThread& sft,
crowd.accumulate(step_context.get_random_gen());
}

{
ScopedTimer walker_log_timer(timers.walker_log_timer);
// collect walker logs
crowd.collectStepWalkerLog(sft.global_step);
}
// collect walker logs
crowd.collectStepWalkerLog(sft.global_step);

{ // T-moves
ScopedTimer tmove_timer(dmc_timers.tmove_timer);
Expand Down Expand Up @@ -461,14 +458,10 @@ bool DMCBatched::run()

//initialize WalkerLogManager and collectors
WalkerLogManager wlog_manager(walker_logs_input, allow_walker_logs, get_root_name(), myComm);

{
ScopedTimer walker_log_timer(timers_.walker_log_timer);
for (auto& crowd : crowds_)
crowd->setWalkerLogCollector(wlog_manager.makeCollector());
//register walker log collectors into the manager
wlog_manager.startRun(Crowd::getWalkerLogCollectorRefs(crowds_));
}
for (auto& crowd : crowds_)
crowd->setWalkerLogCollector(wlog_manager.makeCollector());
//register walker log collectors into the manager
wlog_manager.startRun(Crowd::getWalkerLogCollectorRefs(crowds_));

StateForThread dmc_state(qmcdriver_input_, *drift_modifier_, *branch_engine_, population_, steps_per_block_,
serializing_crowd_walkers_);
Expand Down Expand Up @@ -539,10 +532,7 @@ bool DMCBatched::run()
if (qmcdriver_input_.get_measure_imbalance())
measureImbalance("Block " + std::to_string(block));
endBlock();
{
ScopedTimer walker_log_timer(timers_.walker_log_timer);
wlog_manager.writeBuffers();
}
wlog_manager.writeBuffers();
recordBlock(block);
}

Expand Down
4 changes: 1 addition & 3 deletions src/QMCDrivers/QMCDriverNew.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase
NewTimer& startup_timer;
NewTimer& production_timer;
NewTimer& resource_timer;
NewTimer& walker_log_timer;
DriverTimers(const std::string& prefix)
: checkpoint_timer(createGlobalTimer(prefix + "CheckPoint", timer_level_medium)),
run_steps_timer(createGlobalTimer(prefix + "RunSteps", timer_level_medium)),
Expand All @@ -387,8 +386,7 @@ class QMCDriverNew : public QMCDriverInterface, public MPIObjectBase
endblock_timer(createGlobalTimer(prefix + "BlockEndDataAggregation", timer_level_medium)),
startup_timer(createGlobalTimer(prefix + "Startup", timer_level_medium)),
production_timer(createGlobalTimer(prefix + "Production", timer_level_medium)),
resource_timer(createGlobalTimer(prefix + "Resources", timer_level_medium)),
walker_log_timer(createGlobalTimer(prefix + "Walker Logging", timer_level_fine))
resource_timer(createGlobalTimer(prefix + "Resources", timer_level_medium))
{}
};

Expand Down
40 changes: 39 additions & 1 deletion src/QMCDrivers/WalkerLogBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2024 QMCPACK developers.
// Copyright (c) 2025 QMCPACK developers.
//
// File developed by: Ye Luo, [email protected], Argonne National Laboratory
// Peter W. Doak, [email protected], Oak Ridge National Laboratory
//
// File created by: Ye Luo, [email protected], Argonne National Laboratory
//////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -15,6 +16,43 @@
namespace qmcplusplus
{

template<typename T>
WalkerLogBuffer<T>::WalkerLogBuffer()
: walker_log_buffer_timers_(getGlobalTimerManager(), create_names(my_name_), timer_level_medium)
{
label = "?";
first_collect = true;
walker_data_size = 0;
quantity_index = 0;
resetBuffer();
}

/// collect data for a single walker quantity of scalar type into the current buffer row
template<typename T>
void WalkerLogBuffer<T>::collect(const std::string& name, const T& value)
{
ScopedTimer timer(walker_log_buffer_timers_[Timer::COLLECT]);

size_t irow = 0;
if (first_collect)
{ // cache walker quantity info on first collect
WalkerQuantityInfo wqi_(name, 1, walker_data_size);
quantity_info.push_back(wqi_);
walker_data_size = wqi_.buffer_end;
resetRowSize(walker_data_size);
}
else
{ // make a new buffer row if needed
if (quantity_index == 0)
makeNewRow();
irow = buffer.size(0) - 1;
}
// place the scalar walker quantity into the current buffer row
auto& wqi = quantity_info[quantity_index];
buffer(irow, wqi.buffer_start) = value;
quantity_index++;
}

template class WalkerLogBuffer<WLog::Int>;
template class WalkerLogBuffer<WLog::Real>;

Expand Down
71 changes: 36 additions & 35 deletions src/QMCDrivers/WalkerLogBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2024 QMCPACK developers.
// Copyright (c) 2025 QMCPACK developers.
//
// File developed by: Jaron T. Krogel, [email protected], Oak Ridge National Laboratory
//
Expand All @@ -15,16 +15,14 @@


#include <Configuration.h>
#include <unordered_set>
#include "OhmmsPETE/OhmmsArray.h"
#include "hdf/hdf_archive.h"

#include <unordered_set>

#include "Utilities/TimerManager.h"

namespace qmcplusplus
{


/// Basic data types for walker log data
struct WLog
{
Expand Down Expand Up @@ -119,6 +117,27 @@ class WalkerLogBuffer
hsize_t hdf_file_pointer;

private:
static constexpr std::string_view my_name_{"WalkerLogBuffer"};
enum Timer
{
COLLECT = 0,
ADD_ROW,
WRITE,
RESET,
MAKE_NEW_ROW
};
static constexpr std::array<std::string_view, 5> suffixes_{"collect", "add_row", "write", "reset", "make_new_row"};
static TimerNameList_t<Timer> create_names(const std::string_view& my_name)
{
TimerNameList_t<Timer> timer_names;
using namespace std::string_literals;
std::string prefix{"WalkerLog:"s + std::string{my_name} + "::"s};
for (std::size_t i = 0; i < suffixes_.size(); ++i)
timer_names.push_back({static_cast<Timer>(i), prefix + std::string{suffixes_[i]}});
return timer_names;
}
TimerList_t walker_log_buffer_timers_;

/// index of current quantity during WalkerLogCollector::collect()
size_t quantity_index;
/** buffer row location data for each walker quantity
Expand All @@ -131,14 +150,7 @@ class WalkerLogBuffer
Array<T, 2> buffer;

public:
WalkerLogBuffer()
{
label = "?";
first_collect = true;
walker_data_size = 0;
quantity_index = 0;
resetBuffer();
}
WalkerLogBuffer();

/// current number of rows in the data buffer
inline size_t nrows() { return buffer.size(0); }
Expand All @@ -163,33 +175,14 @@ class WalkerLogBuffer
inline bool sameAs(const WalkerLogBuffer<T>& ref) { return buffer.size(1) == ref.buffer.size(1); }

/// collect data for a single walker quantity of scalar type into the current buffer row
inline void collect(const std::string& name, const T& value)
{
size_t irow = 0;
if (first_collect)
{ // cache walker quantity info on first collect
WalkerQuantityInfo wqi_(name, 1, walker_data_size);
quantity_info.push_back(wqi_);
walker_data_size = wqi_.buffer_end;
resetRowSize(walker_data_size);
}
else
{ // make a new buffer row if needed
if (quantity_index == 0)
makeNewRow();
irow = buffer.size(0) - 1;
}
// place the scalar walker quantity into the current buffer row
auto& wqi = quantity_info[quantity_index];
buffer(irow, wqi.buffer_start) = value;
quantity_index++;
}

void collect(const std::string& name, const T& value);

/// collect data for a single walker quantity of array type into the current buffer row
template<unsigned D>
inline void collect(const std::string& name, Array<T, D> arr)
{
ScopedTimer timer(walker_log_buffer_timers_[Timer::COLLECT]);

size_t n1 = arr.size(0);
size_t n2, n3, n4;
n2 = n3 = n4 = 0;
Expand Down Expand Up @@ -228,6 +221,7 @@ class WalkerLogBuffer
template<unsigned D>
inline void collect(const std::string& name, Array<std::complex<T>, D> arr)
{
ScopedTimer timer(walker_log_buffer_timers_[Timer::COLLECT]);
size_t n1 = arr.size(0);
size_t n2, n3, n4;
n2 = n3 = n4 = 0;
Expand Down Expand Up @@ -271,6 +265,7 @@ class WalkerLogBuffer
/// add a data row from another buffer to this one
inline void addRow(WalkerLogBuffer<T> other, size_t i)
{
ScopedTimer timer(walker_log_buffer_timers_[Timer::ADD_ROW]);
auto& other_buffer = other.buffer;
if (first_collect)
{
Expand All @@ -293,6 +288,8 @@ class WalkerLogBuffer
/// write a summary of quantities in the buffer
inline void writeSummary(std::string pad = " ")
{
ScopedTimer timer(walker_log_buffer_timers_[Timer::WRITE]);

Check warning on line 291 in src/QMCDrivers/WalkerLogBuffer.h

View check run for this annotation

Codecov / codecov/patch

src/QMCDrivers/WalkerLogBuffer.h#L291

Added line #L291 was not covered by tests

std::string pad2 = pad + " ";
std::string pad3 = pad2 + " ";
app_log() << std::endl;
Expand Down Expand Up @@ -341,6 +338,7 @@ class WalkerLogBuffer
/// write the buffer data into the HDF file
inline void writeHDF(hdf_archive& f, hsize_t& file_pointer)
{
ScopedTimer timer(walker_log_buffer_timers_[Timer::WRITE]);
auto& top = label;
hsize_t dims[2];
dims[0] = buffer.size(0);
Expand All @@ -358,6 +356,7 @@ class WalkerLogBuffer
/// make space as quantities are added to the buffer for the first time
inline void resetRowSize(size_t row_size)
{
ScopedTimer timer(walker_log_buffer_timers_[Timer::RESET]);
auto nrows = buffer.size(0);
if (nrows == 0)
nrows++;
Expand All @@ -378,6 +377,8 @@ class WalkerLogBuffer
/// allocate a full new row at the end of the buffer
inline void makeNewRow()
{
ScopedTimer timer(walker_log_buffer_timers_[Timer::MAKE_NEW_ROW]);

size_t nrows = buffer.size(0);
size_t row_size = buffer.size(1);
if (row_size == 0)
Expand Down
9 changes: 7 additions & 2 deletions src/QMCDrivers/WalkerLogCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2024 QMCPACK developers.
// Copyright (c) 2025 QMCPACK developers.
//
// File developed by: Jaron T. Krogel, [email protected], Oak Ridge National Laboratory
//
Expand All @@ -23,7 +23,7 @@ namespace qmcplusplus

using MCPWalker = Walker<QMCTraits, PtclOnLatticeTraits>;

WalkerLogCollector::WalkerLogCollector(const WalkerLogState& state) : state_(state) { init(); }
WalkerLogCollector::WalkerLogCollector(const WalkerLogState& state) : walker_log_collector_timers_(getGlobalTimerManager(), create_names(my_name_), timer_level_medium), state_(state) { init(); }


void WalkerLogCollector::init()
Expand All @@ -43,6 +43,7 @@ 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
if (state_.verbose)
Expand All @@ -57,6 +58,8 @@ 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

Expand Down Expand Up @@ -175,6 +178,8 @@ void WalkerLogCollector::resetBuffers()

void WalkerLogCollector::checkBuffers()
{
ScopedTimer timer(walker_log_collector_timers_[Timer::CHECK_BUFFERS]);

if (state_.verbose)
app_log() << "WalkerLogCollector::checkBuffers" << std::endl;
size_t nrows = walker_property_int_buffer.nrows();
Expand Down
23 changes: 21 additions & 2 deletions src/QMCDrivers/WalkerLogCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2024 QMCPACK developers.
// Copyright (c) 2025 QMCPACK developers.
//
// File developed by: Jaron T. Krogel, [email protected], Oak Ridge National Laboratory
//
Expand All @@ -14,7 +14,7 @@
#define QMCPLUSPLUS_WALKERLOGCOLLECTOR_H

#include "WalkerLogBuffer.h"

#include "Utilities/TimerManager.h"

namespace qmcplusplus
{
Expand Down Expand Up @@ -68,6 +68,25 @@ class WalkerLogCollector
int energy_index;

private:
static constexpr std::string_view my_name_{"WalkerLogCollector"};
enum Timer
{
START = 0,
COLLECT,
CHECK_BUFFERS
};
static constexpr std::array<std::string_view, 3> suffixes_{"start", "collect", "check_buffers"};
static TimerNameList_t<Timer> create_names(const std::string_view& my_name)
{
TimerNameList_t<Timer> timer_names;
using namespace std::string_literals;
std::string prefix{"WalkerLog:"s + std::string{my_name} + "::"s};
for (std::size_t i = 0; i < suffixes_.size(); ++i)
timer_names.push_back({static_cast<Timer>(i), prefix + std::string{suffixes_[i]}});
return timer_names;
}
TimerList_t walker_log_collector_timers_;

// temporary (contiguous) storage for awful ParticleAttrib<> quantities
/// tmp storage for walker positions
Array<WLog::Real, 2> Rtmp;
Expand Down
Loading

0 comments on commit 99f9370

Please sign in to comment.