QMCPACK
VMCBatched.h
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) 2020 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
8 //
9 // File refactored from VMC.h
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef QMCPLUSPLUS_VMCBATCHED_H
14 #define QMCPLUSPLUS_VMCBATCHED_H
15 
21 
22 #include "Utilities/Timer.h"
23 
24 namespace qmcplusplus
25 {
26 namespace testing
27 {
28 class VMCBatchedTest;
29 }
30 
31 /** @ingroup QMCDrivers ParticleByParticle
32  * @brief Implements a VMC using particle-by-particle move. Threaded execution.
33  */
34 class VMCBatched : public QMCDriverNew
35 {
36 public:
37  using Base = QMCDriverNew;
41 
42  /** To avoid 10's of arguments to runVMCStep
43  *
44  * There should be a division between const input to runVMCStep
45  * And step to step state
46  */
48  {
54  const size_t steps_per_block;
57  bool is_recomputing_block = false;
58 
60  const VMCDriverInput& vmci,
61  DriftModifierBase& drift_mod,
62  MCPopulation& pop,
63  const size_t steps_per_block)
64  : qmcdrv_input(qmci),
65  vmcdrv_input(vmci),
66  drift_modifier(drift_mod),
67  population(pop),
69  {}
70  };
71 
72 public:
73  /// Constructor.
74  VMCBatched(const ProjectData& project_data,
75  QMCDriverInput&& qmcdriver_input,
76  const std::optional<EstimatorManagerInput>& global_emi,
79  MCPopulation&& pop,
81  Communicate* comm);
82 
83  void process(xmlNodePtr node) override;
84 
85  bool run() override;
86 
87  /** Refactor of VMCUpdatePbyP in crowd context
88  *
89  * MCWalkerConfiguration layer removed.
90  * Obfuscation of state changes via buffer and MCWalkerconfiguration require this be tested well
91  */
92  template<CoordsType CT>
93  static void advanceWalkers(const StateForThread& sft,
94  Crowd& crowd,
95  DriverTimers& timers,
96  ContextForSteps& move_context,
97  bool recompute,
98  bool accumulate_this_step);
99 
100  // This is the task body executed at crowd scope
101  // it does not have access to object member variables by design
102  static void runVMCStep(int crowd_id,
103  const StateForThread& sft,
104  DriverTimers& timers,
105  UPtrVector<ContextForSteps>& context_for_steps,
106  UPtrVector<Crowd>& crowds);
107 
108  /** transitional interface on the way to better walker count adjustment handling.
109  * returns a closure taking walkers per rank and accomplishing what calc_default_local_walkers does.
110  */
111  auto getCDLW();
112 
113  /** Enable collecting samples during the VMC run
114  *
115  * strong assumption that VMCBatched driver has passed through process phase of
116  * initialization.
117  * A side effect of VMCBatched::process is that MCPopulation has created local walkers.
118  */
120 
121 private:
126  /// Copy constructor
127  VMCBatched(const VMCBatched&) = delete;
128  /// Copy operator (disabled).
129  VMCBatched& operator=(const VMCBatched&) = delete;
130 
131 
132  /// Storage for samples (later used in optimizer)
134  /// Sample collection flag
136  /** function to calculate samples per MPI rank
137  */
138  static size_t compute_samples_per_rank(const size_t num_blocks,
139  const size_t samples_per_block,
140  const size_t local_walkers);
141 
143 };
144 
145 extern std::ostream& operator<<(std::ostream& o_stream, const VMCBatched& vmc_batched);
146 } // namespace qmcplusplus
147 
148 #endif
bool run() override
Runs the actual VMC section.
Definition: VMCBatched.cpp:307
const QMCDriverInput & qmcdrv_input
Definition: VMCBatched.h:49
QMCDriverNew(const ProjectData &project_data, QMCDriverInput &&input, const std::optional< EstimatorManagerInput > &global_emi, WalkerConfigurations &wc, MCPopulation &&population, const std::string timer_prefix, Communicate *comm, const std::string &QMC_driver_type)
Constructor.
void process(xmlNodePtr node) override
QMCDriverNew driver second (3rd, 4th...) stage of constructing a valid driver.
Definition: VMCBatched.cpp:265
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QMCTraits::FullPrecRealType FullPrecRealType
if(!okay) throw std xmlNodePtr node
Input representation for VMC driver class runtime parameters.
QMCDriverNew Base class for Unified Drivers.
Definition: QMCDriverNew.h:75
Declaration of QMCDriverNew.
class ProjectData
Definition: ProjectData.h:36
A set of light weight walkers that are carried between driver sections and restart.
const char num_blocks[]
Definition: HDFVersion.h:44
this class implements drift modification
Timer class.
std::vector< std::unique_ptr< T > > UPtrVector
Driver synchronized step context.
Definition: Crowd.h:38
Attaches a unit to a Vector for IO.
VMCBatched(const ProjectData &project_data, QMCDriverInput &&qmcdriver_input, const std::optional< EstimatorManagerInput > &global_emi, VMCDriverInput &&input, WalkerConfigurations &wc, MCPopulation &&pop, SampleStack &samples_, Communicate *comm)
Constructor.
Definition: VMCBatched.cpp:30
bool collect_samples_
Sample collection flag.
Definition: VMCBatched.h:135
Wrapping information on parallelism.
Definition: Communicate.h:68
To avoid 10&#39;s of arguments to runVMCStep.
Definition: VMCBatched.h:47
static void advanceWalkers(const StateForThread &sft, Crowd &crowd, DriverTimers &timers, ContextForSteps &move_context, bool recompute, bool accumulate_this_step)
Refactor of VMCUpdatePbyP in crowd context.
Definition: VMCBatched.cpp:52
void enable_sample_collection()
Enable collecting samples during the VMC run.
Definition: VMCBatched.cpp:463
const VMCDriverInput & vmcdrv_input
Definition: VMCBatched.h:50
Thread local context for moving walkers.
std::ostream & operator<<(std::ostream &out, const AntiSymTensor< T, D > &rhs)
QTBase::PosType PosType
Definition: Configuration.h:61
QMCTraits::IndexType IndexType
Definition: QMCDriverNew.h:79
StateForThread(const QMCDriverInput &qmci, const VMCDriverInput &vmci, DriftModifierBase &drift_mod, MCPopulation &pop, const size_t steps_per_block)
Definition: VMCBatched.h:59
static void runVMCStep(int crowd_id, const StateForThread &sft, DriverTimers &timers, UPtrVector< ContextForSteps > &context_for_steps, UPtrVector< Crowd > &crowds)
Thread body for VMC step.
Definition: VMCBatched.cpp:243
ParticleAttrib< SingleParticlePos > ParticlePos
Definition: Configuration.h:92
SampleStack & samples_
Storage for samples (later used in optimizer)
Definition: VMCBatched.h:133
QTFull::RealType FullPrecRealType
Definition: Configuration.h:66
QMCRunType getRunType() override
Definition: VMCBatched.h:125
VMCDriverInput vmcdriver_input_
Definition: VMCBatched.h:124
static size_t compute_samples_per_rank(const size_t num_blocks, const size_t samples_per_block, const size_t local_walkers)
function to calculate samples per MPI rank
Definition: VMCBatched.cpp:287
auto getCDLW()
transitional interface on the way to better walker count adjustment handling.
const DriftModifierBase & drift_modifier
Definition: VMCBatched.h:51
Implements a VMC using particle-by-particle move.
Definition: VMCBatched.h:34
Input representation for Driver base class runtime parameters.
VMCBatched & operator=(const VMCBatched &)=delete
Copy operator (disabled).