QMCPACK
QMCDriverNewTestWrapper.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 created by: Peter Doak, , doakpw@ornl.gov, Oak Ridge National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef QMCPLUSPLUS_QMCDRIVERNEWTESTWRAPPER_H
13 #define QMCPLUSPLUS_QMCDRIVERNEWTESTWRAPPER_H
16 #include "Particle/SampleStack.h"
19 #include "ProjectData.h"
20 
21 namespace qmcplusplus
22 {
23 /** Unit testing an impure virtual base class
24  * requires a absolute minimal subtype
25  */
26 namespace testing
27 {
29 {
30 public:
31  using Base = QMCDriverNew;
35  MCPopulation&& population,
38  std::move(input),
39  std::nullopt,
40  wc,
41  std::move(population),
42  "QMCDriverTestWrapper::",
43  comm,
44  "QMCDriverNewTestWrapper")
45  {}
46 
48 
49  QMCRunType getRunType() override { return QMCRunType::DUMMY; }
50 
51  void process(xmlNodePtr node) override
52  {
53  // We want to test the reserve ability as well
57 
59  }
60 
62  {
64  if (myComm->size() == 4)
65  {
66  awc = adjustGlobalWalkerCount(*myComm, 0, 64, 0, 1.0, 0);
67  if (myComm->rank() == 1)
68  {
69  CHECK(awc.global_walkers == 64);
70  CHECK(awc.walkers_per_crowd.size() == 8);
71  CHECK(awc.walkers_per_rank[0] == 16);
72  CHECK(awc.walkers_per_rank[3] == 16);
73  CHECK(awc.walkers_per_crowd[4] == 2);
74  CHECK(awc.walkers_per_crowd[7] == 2);
75  }
76 
77  awc = adjustGlobalWalkerCount(*myComm, 4, 0, 0, 1.0, 0);
78  if (myComm->rank() == 1)
79  {
80  CHECK(awc.global_walkers == 16);
81  CHECK(awc.walkers_per_crowd.size() == 8);
82  CHECK(awc.walkers_per_rank[0] == 4);
83  CHECK(awc.walkers_per_rank[3] == 4);
84  CHECK(awc.walkers_per_crowd[3] == 1);
85  CHECK(awc.walkers_per_crowd[7] == 0);
86  }
87 
88  awc = adjustGlobalWalkerCount(*myComm, 0, 63, 0, 1.0, 4);
89  if (myComm->rank() == 1)
90  {
91  CHECK(awc.global_walkers == 63);
92  CHECK(awc.walkers_per_crowd.size() == 4);
93  CHECK(awc.walkers_per_rank[0] == 16);
94  CHECK(awc.walkers_per_rank[3] == 15);
95  CHECK(awc.walkers_per_crowd[0] == 4);
96  CHECK(awc.walkers_per_crowd[3] == 4);
97  }
98  awc = adjustGlobalWalkerCount(*myComm, 0, 63, 0, 1.0, 4);
99  if (myComm->rank() == 3)
100  {
101  CHECK(awc.global_walkers == 63);
102  CHECK(awc.walkers_per_crowd.size() == 4);
103  CHECK(awc.walkers_per_rank[0] == 16);
104  CHECK(awc.walkers_per_rank[3] == 15);
105  CHECK(awc.walkers_per_crowd[0] == 4);
106  CHECK(awc.walkers_per_crowd[3] == 3);
107  }
108 
109  awc = adjustGlobalWalkerCount(*myComm, 0, 0, 32, 1.0, 4);
110  if (myComm->rank() == 3)
111  {
112  CHECK(awc.global_walkers == 128);
113  CHECK(awc.walkers_per_crowd.size() == 4);
114  CHECK(awc.walkers_per_rank[0] == 32);
115  CHECK(awc.walkers_per_rank[3] == 32);
116  CHECK(awc.walkers_per_crowd[0] == 8);
117  CHECK(awc.walkers_per_crowd[3] == 8);
118  }
119  }
120  if (myComm->size() == 1)
121  {
122  awc = adjustGlobalWalkerCount(*myComm, 0, 7, 0, 1.0, 8);
123  CHECK(awc.global_walkers == 7);
124  CHECK(awc.walkers_per_crowd.size() == 8);
125  CHECK(awc.walkers_per_rank.size() == 1);
126  CHECK(awc.walkers_per_rank[0] == 7);
127  CHECK(awc.walkers_per_crowd[0] == 1);
128  CHECK(awc.walkers_per_crowd[7] == 0);
129  }
130 
131  if (myComm->size() == 2)
132  {
133  awc = adjustGlobalWalkerCount(*myComm, 0, 28, 0, 1.0, 0);
134  if (myComm->rank() == 0)
135  {
136  CHECK(awc.global_walkers == 28);
138  CHECK(awc.walkers_per_rank.size() == 2);
139  CHECK(awc.walkers_per_rank[0] == 14);
140  // \todo for std::thread these will be ones
141  CHECK(awc.walkers_per_crowd[0] == 2);
142  CHECK(awc.walkers_per_crowd[7] == 1);
143  }
144  awc = adjustGlobalWalkerCount(*myComm, 0, 27, 0, 1.0, 4);
145  if (myComm->rank() == 1)
146  {
147  CHECK(awc.global_walkers == 27);
148  CHECK(awc.walkers_per_crowd.size() == 4);
149  CHECK(awc.walkers_per_rank.size() == 2);
150  CHECK(awc.walkers_per_rank[0] == 14);
151  CHECK(awc.walkers_per_rank[1] == 13);
152  CHECK(awc.walkers_per_crowd[0] == 4);
153  CHECK(awc.walkers_per_crowd[3] == 3);
154  }
155  // Ask for 27 total walkers on 2 ranks of 11 walkers (inconsistent input)
156  // results in fatal exception on all ranks.
157  CHECK_THROWS_AS(adjustGlobalWalkerCount(*myComm, 0, 27, 11, 1.0, 4), UniformCommunicateError);
158  }
159 
160  if (myComm->size() == 16)
161  {
162  // Ask for 14 total walkers on 16 ranks (inconsistent input)
163  // results in fatal exception on all ranks.
164  CHECK_THROWS_AS(adjustGlobalWalkerCount(*myComm, 0, 14, 0, 0, 0), UniformCommunicateError);
165  }
166  }
167 
168  bool run() override { return false; }
169 
170  int get_num_crowds() { return crowds_.size(); }
171 
172  template<class CONCURRENCY>
174  {
175  void operator()(int num_crowds);
176  };
177 
180  {
181  CHECK(QMCDriverNew::determineStepsPerBlock(6, 36, 2, 3) == 2);
182  CHECK(QMCDriverNew::determineStepsPerBlock(6, 36, 1, 6) == 1);
183  CHECK(QMCDriverNew::determineStepsPerBlock(6, 33, 3, 2) == 3);
184  CHECK(QMCDriverNew::determineStepsPerBlock(6, 33, 0, 2) == 3);
185  CHECK(QMCDriverNew::determineStepsPerBlock(6, 25, 0, 2) == 3);
186  CHECK(QMCDriverNew::determineStepsPerBlock(6, 24, 0, 2) == 2);
189 
190  CHECK_THROWS_WITH(QMCDriverNew::determineStepsPerBlock(6, 13, 1, 2),
191  Catch::Contains("more than the total number of walkers"));
192  }
193 };
194 
195 template<class CONCURRENCY>
197 {}
198 
199 template<>
201 {
202  if (Concurrency::maxCapacity<>() != 8)
203  throw std::runtime_error("OMP_NUM_THREADS must be 8 for this test.");
204  if (num_crowds > 8)
205  CHECK_THROWS_AS(checkNumCrowdsLTNumThreads(num_crowds), UniformCommunicateError);
206  else
207  checkNumCrowdsLTNumThreads(num_crowds);
208  return;
209 }
210 
211 
212 } // namespace testing
213 } // namespace qmcplusplus
214 #endif
Stores particle configurations for later use in DMC and wavefunction optimization.
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.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
int rank() const
return the rank
Definition: Communicate.h:116
if(!okay) throw std xmlNodePtr node
This is a data structure strictly for QMCDriver and its derived classes.
Definition: QMCDriverNew.h:116
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.
ProjectData test_project("test", ProjectData::DriverVersion::BATCH)
int size() const
return the number of tasks
Definition: Communicate.h:118
Wrapping information on parallelism.
Definition: Communicate.h:68
IndexType get_num_crowds() const
static size_t determineStepsPerBlock(IndexType global_walkers, IndexType requested_samples, IndexType requested_steps, IndexType blocks)
pure function calculating the actual number of steps per block
IndexType get_total_walkers() const
IndexType get_walkers_per_rank() const
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
This a subclass for runtime errors that will occur on all ranks.
void process(xmlNodePtr node) override
QMCDriverNew driver second (3rd, 4th...) stage of constructing a valid driver.
static QMCDriverNew::AdjustedWalkerCounts adjustGlobalWalkerCount(Communicate &comm, const IndexType current_configs, const IndexType requested_total_walkers, const IndexType requested_walkers_per_rank, const RealType reserve_walkers, int num_crowds)
}@
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
UPtrVector< Crowd > crowds_
}@
Definition: QMCDriverNew.h:389
QMCDriverInput qmcdriver_input_
Definition: QMCDriverNew.h:372
void measureImbalance(const std::string &tag) const
inject additional barrier and measure load imbalance.
unsigned int maxCapacity()
void initializeQMC(const AdjustedWalkerCounts &awc)
Do common section starting tasks for VMC and DMC.
Input representation for Driver base class runtime parameters.
QMCDriverNewTestWrapper(const ProjectData &test_project, QMCDriverInput &&input, WalkerConfigurations &wc, MCPopulation &&population, Communicate *comm)