QMCPACK
WalkerControl Class Reference

Class for controlling the walkers for DMC simulations. More...

+ Inheritance diagram for WalkerControl:
+ Collaboration diagram for WalkerControl:

Public Types

using Walker_t = MCWalkerConfiguration::Walker_t
 typedef of Walker_t More...
 
using MCPWalker = MCPopulation::MCPWalker
 distinct type for "new" walker, currently same as Walker_t More...
 
using FullPrecRealType = QMCTraits::FullPrecRealType
 typedef of FullPrecRealType More...
 
using IndexType = QMCTraits::IndexType
 typedef of IndexType More...
 
- Public Types inherited from MPIObjectBase
using mpi_comm_type = Communicate::mpi_comm_type
 

Public Member Functions

 WalkerControl (Communicate *c, RandomBase< FullPrecRealType > &rng, bool use_fixed_pop=false)
 default constructor More...
 
 ~WalkerControl ()
 empty destructor to clean up the derived classes More...
 
void start ()
 start a block More...
 
void writeDMCdat (int iter, const std::vector< FullPrecRealType > &curData)
 take averages and writes to a file More...
 
void setTrialEnergy (FullPrecRealType et)
 set the trial energy for writing to dmc.dat More...
 
void branch (int iter, MCPopulation &pop, bool do_not_branch)
 unified: perform branch and swap walkers as required More...
 
bool put (xmlNodePtr cur)
 
void setMinMax (int nw_in, int nmax_in)
 
int get_n_max () const
 
int get_n_min () const
 
MCDataType< FullPrecRealType > & get_ensemble_property ()
 
void set_ensemble_property (MCDataType< FullPrecRealType > &ensemble_property)
 
IndexType get_num_contexts () const
 
- Public Member Functions inherited from MPIObjectBase
 MPIObjectBase (Communicate *c)
 constructor with communicator More...
 
int rank () const
 return the rank of the communicator More...
 
int getGroupID () const
 return the group id of the communicator More...
 
CommunicategetCommunicator () const
 return myComm More...
 
CommunicategetCommRef () const
 return a TEMPORARY reference to Communicate More...
 
mpi_comm_type getMPI () const
 return MPI communicator if one wants to use MPI directly More...
 
bool is_manager () const
 return true if the rank == 0 More...
 
const std::string & getName () const
 return the name More...
 
void setName (const std::string &aname)
 

Private Types

enum  {
  ENERGY_INDEX = 0, ENERGY_SQ_INDEX, WALKERSIZE_INDEX, WEIGHT_INDEX,
  R2ACCEPTED_INDEX, R2PROPOSED_INDEX, FNSIZE_INDEX, SENTWALKERS_INDEX,
  LE_MAX
}
 An enum to access curData for reduction. More...
 

Private Member Functions

void computeCurData (const UPtrVector< MCPWalker > &walkers, std::vector< FullPrecRealType > &curData)
 compute curData More...
 

Static Private Member Functions

static void killDeadWalkersOnRank (MCPopulation &pop)
 kill dead walkers in the population More...
 
static std::vector< IndexTypesyncFutureWalkersPerRank (Communicate *comm, IndexType n_walkers)
 
static void determineNewWalkerPopulation (const std::vector< int > &num_per_rank, std::vector< int > &fair_offset, std::vector< int > &minus, std::vector< int > &plus)
 creates the distribution plan More...
 

Private Attributes

RandomBase< FullPrecRealType > & rng_
 random number generator More...
 
bool use_fixed_pop_
 if true, use fixed population More...
 
IndexType n_min_
 minimum number of walkers More...
 
IndexType n_max_
 maximum number of walkers More...
 
IndexType max_copy_
 maximum copy per walker More...
 
FullPrecRealType trial_energy_
 trial energy energy More...
 
std::vector< int > num_per_rank_
 number of walkers on each MPI rank after branching before load balancing More...
 
std::vector< int > fair_offset_
 offset of the particle index for a fair distribution More...
 
std::filesystem::path dmcFname
 filename for dmc.dat More...
 
std::unique_ptr< std::ofstream > dmcStream
 file to save energy histogram More...
 
const IndexType rank_num_
 context id More...
 
const IndexType num_ranks_
 number of contexts More...
 
IndexType SwapMode
 0 is default More...
 
std::vector< FullPrecRealTypecurData
 any temporary data includes many ridiculous conversions of integral types to and from fp More...
 
bool use_nonblocking_
 Use non-blocking isend/irecv. More...
 
bool debug_disable_branching_
 disable branching for debugging More...
 
MCDataType< FullPrecRealTypeensemble_property_
 ensemble properties More...
 
TimerList_t my_timers_
 timers More...
 
IndexType saved_num_walkers_sent_
 Number of walkers sent during the exchange. More...
 

Additional Inherited Members

- Protected Attributes inherited from MPIObjectBase
CommunicatemyComm
 pointer to Communicate More...
 
std::string ClassName
 class Name More...
 
std::string myName
 name of the object More...
 

Detailed Description

Class for controlling the walkers for DMC simulations.

w and w/o MPI. Fixed and dynamic population in one place.

Definition at line 40 of file WalkerControl.h.

Member Typedef Documentation

◆ FullPrecRealType

typedef of FullPrecRealType

Definition at line 48 of file WalkerControl.h.

◆ IndexType

typedef of IndexType

Definition at line 50 of file WalkerControl.h.

◆ MCPWalker

distinct type for "new" walker, currently same as Walker_t

Definition at line 46 of file WalkerControl.h.

◆ Walker_t

typedef of Walker_t

Definition at line 44 of file WalkerControl.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

An enum to access curData for reduction.

curData is larger than this //LE_MAX + n_node * T

Enumerator
ENERGY_INDEX 
ENERGY_SQ_INDEX 
WALKERSIZE_INDEX 
WEIGHT_INDEX 
R2ACCEPTED_INDEX 
R2PROPOSED_INDEX 
FNSIZE_INDEX 
SENTWALKERS_INDEX 
LE_MAX 

Definition at line 130 of file WalkerControl.h.

Constructor & Destructor Documentation

◆ WalkerControl()

WalkerControl ( Communicate c,
RandomBase< FullPrecRealType > &  rng,
bool  use_fixed_pop = false 
)

default constructor

Set the SwapMode to zero so that instantiation can be done

Definition at line 57 of file WalkerControl.cpp.

References WalkerControl::fair_offset_, WalkerControl::num_per_rank_, WalkerControl::num_ranks_, and qmcplusplus::rank.

58  : MPIObjectBase(c),
59  rng_(rng),
60  use_fixed_pop_(use_fixed_pop),
61  n_min_(1),
62  n_max_(10),
63  max_copy_(2),
64  rank_num_(c->rank()),
65  num_ranks_(c->size()),
66  SwapMode(0),
67  use_nonblocking_(true),
71 {
72  num_per_rank_.resize(num_ranks_);
73  fair_offset_.resize(num_ranks_ + 1);
74 }
RandomBase< FullPrecRealType > & rng_
random number generator
IndexType saved_num_walkers_sent_
Number of walkers sent during the exchange.
int rank() const
return the rank
Definition: Communicate.h:116
std::vector< int > fair_offset_
offset of the particle index for a fair distribution
const IndexType rank_num_
context id
bool debug_disable_branching_
disable branching for debugging
int size() const
return the number of tasks
Definition: Communicate.h:118
const IndexType num_ranks_
number of contexts
IndexType n_min_
minimum number of walkers
bool use_nonblocking_
Use non-blocking isend/irecv.
IndexType n_max_
maximum number of walkers
std::vector< int > num_per_rank_
number of walkers on each MPI rank after branching before load balancing
IndexType SwapMode
0 is default
TimerList_t my_timers_
timers
TimerNameList_t< WC_Timers > WalkerControlTimerNames
TimerManager< NewTimer > & getGlobalTimerManager()
MPIObjectBase(Communicate *c)
constructor with communicator
IndexType max_copy_
maximum copy per walker
bool use_fixed_pop_
if true, use fixed population

◆ ~WalkerControl()

~WalkerControl ( )
default

empty destructor to clean up the derived classes

Member Function Documentation

◆ branch()

void branch ( int  iter,
MCPopulation pop,
bool  do_not_branch 
)

unified: perform branch and swap walkers as required

any temporary data includes many ridiculous conversions of integral types to and from fp

Definition at line 137 of file WalkerControl.cpp.

References MCPopulation::checkIntegrity(), WalkerControl::computeCurData(), WalkerControl::curData, WalkerControl::debug_disable_branching_, WalkerControl::ensemble_property_, MCPopulation::get_num_global_walkers(), MCPopulation::get_num_local_walkers(), MCPopulation::get_walkers(), WalkerControl::killDeadWalkersOnRank(), WalkerControl::LE_MAX, omptarget::min(), WalkerControl::my_timers_, MPIObjectBase::myComm, WalkerControl::num_per_rank_, WalkerControl::num_ranks_, WalkerControl::rng_, MCPopulation::set_ensemble_property(), MCPopulation::set_num_global_walkers(), MCPopulation::spawnWalker(), MCPopulation::syncWalkersPerRank(), WalkerControl::use_fixed_pop_, qmcplusplus::walker, WalkerElementsRef::walker, qmcplusplus::hdf::walkers, qmcplusplus::WC_branch, qmcplusplus::WC_copyWalkers, qmcplusplus::WC_loadbalance, qmcplusplus::WC_prebalance, and WalkerControl::writeDMCdat().

138 {
140  do_not_branch = true;
141  /* dynamic population
142  1. compute multiplicity. If iter 0, multiplicity = 1
143  2. compute curData, collect multiplicity on every rank
144 
145  fix population
146  1. compute curData, collect weight on every rank
147  2. compute multiplicity by comb method
148 
149  3. figure out final distribution, apply walker count ceiling
150  4. collect good, bad walkers
151  5. communicate walkers
152  6. unpack received walkers, apply walker count floor
153  */
154 
155  ScopedTimer branch_timer(my_timers_[WC_branch]);
156  auto& walkers = pop.get_walkers();
157 
158  {
159  ScopedTimer prebalance_timer(my_timers_[WC_prebalance]);
160  ///any temporary data includes many ridiculous conversions of integral types to and from fp
161  std::vector<FullPrecRealType> curData(LE_MAX + num_ranks_, 0.0);
162 
163  if (use_fixed_pop_)
164  {
166  // convert node local num of walkers after combing
167  // curData[LE_MAX + rank_num_] = wsum to num_total_copies
168  // calculate walker->Multiplicity;
169  }
170  else
171  {
172  // no branching at the first iteration to avoid large population change.
173  if (do_not_branch)
174  for (auto& walker : walkers)
175  walker->Multiplicity = 1.0;
176  else
177  for (auto& walker : walkers)
178  walker->Multiplicity = static_cast<int>(walker->Weight + rng_());
180  for (int i = 0, j = LE_MAX; i < num_ranks_; i++, j++)
181  num_per_rank_[i] = static_cast<int>(curData[j]);
182  }
183  // at this point, curData[LE_MAX + rank_num_] and walker->Multiplicity are ready.
184 
185  writeDMCdat(iter, curData);
186  pop.set_ensemble_property(ensemble_property_);
187  }
188 
189  auto untouched_walkers = walkers.size();
190 #if defined(HAVE_MPI)
191  {
192  ScopedTimer loadbalance_timer(my_timers_[WC_loadbalance]);
193  // kill walkers, actually put them in deadlist for be recycled for receiving walkers
195  // ranks receiving walkers from other ranks have the lowest walker count now.
196  untouched_walkers = std::min(untouched_walkers, walkers.size());
197 
198  // load balancing over MPI
199  swapWalkersSimple(pop);
200  }
201 #endif
202 
203  // kill dead walker to be recycled by the following copy
205  // ranks sending walkers from other ranks have the lowest walker count now.
206  untouched_walkers = std::min(untouched_walkers, walkers.size());
207 
208  { // copy good walkers
209  ScopedTimer copywalkers_timer(my_timers_[WC_copyWalkers]);
210  const size_t good_walkers = walkers.size();
211  for (size_t iw = 0; iw < good_walkers; iw++)
212  {
213  size_t num_copies = static_cast<int>(walkers[iw]->Multiplicity);
214  while (num_copies > 1)
215  {
216  auto walker_elements = pop.spawnWalker();
217  // save this walkers ID
218  // \todo revisit Walker assignment operator after legacy drivers removed.
219  // but in the modern scheme walker IDs are permanent after creation, what walker they
220  // were copied from is in ParentID.
221  long save_id = walker_elements.walker.getWalkerID();
222  walker_elements.walker = *walkers[iw];
223  walker_elements.walker.setParentID(walker_elements.walker.getWalkerID());
224  walker_elements.walker.setWalkerID(save_id);
225  num_copies--;
226  }
227  }
228  }
229 
230  const int current_num_global_walkers = std::accumulate(num_per_rank_.begin(), num_per_rank_.end(), 0);
231  pop.set_num_global_walkers(current_num_global_walkers);
232 #ifndef NDEBUG
233  pop.checkIntegrity();
234  pop.syncWalkersPerRank(myComm);
235  if (current_num_global_walkers != pop.get_num_global_walkers())
236  throw std::runtime_error("Potential bug! Population num_global_walkers mismatched!");
237 #endif
238 
239  if (!do_not_branch)
240  for (UPtr<MCPWalker>& walker : pop.get_walkers())
241  {
242  walker->Weight = 1.0;
243  walker->Multiplicity = 1.0;
244  }
245 
246  for (int iw = 0; iw < untouched_walkers; iw++)
247  pop.get_walkers()[iw]->wasTouched = false;
248 
249  for (int iw = untouched_walkers; iw < pop.get_num_local_walkers(); iw++)
250  pop.get_walkers()[iw]->wasTouched = true;
251 }
RandomBase< FullPrecRealType > & rng_
random number generator
ScopeGuard< NewTimer > ScopedTimer
Definition: NewTimer.h:257
void writeDMCdat(int iter, const std::vector< FullPrecRealType > &curData)
take averages and writes to a file
const char walkers[]
Definition: HDFVersion.h:36
bool debug_disable_branching_
disable branching for debugging
const IndexType num_ranks_
number of contexts
T min(T a, T b)
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
static void killDeadWalkersOnRank(MCPopulation &pop)
kill dead walkers in the population
std::vector< int > num_per_rank_
number of walkers on each MPI rank after branching before load balancing
TimerList_t my_timers_
timers
MCDataType< FullPrecRealType > ensemble_property_
ensemble properties
void computeCurData(const UPtrVector< MCPWalker > &walkers, std::vector< FullPrecRealType > &curData)
compute curData
bool use_fixed_pop_
if true, use fixed population
std::vector< FullPrecRealType > curData
any temporary data includes many ridiculous conversions of integral types to and from fp ...

◆ computeCurData()

void computeCurData ( const UPtrVector< MCPWalker > &  walkers,
std::vector< FullPrecRealType > &  curData 
)
private

compute curData

Definition at line 253 of file WalkerControl.cpp.

References Communicate::allreduce(), WalkerControl::curData, qmcplusplus::Units::charge::e, WalkerControl::ENERGY_INDEX, WalkerControl::ENERGY_SQ_INDEX, WalkerControl::FNSIZE_INDEX, WalkerControl::LE_MAX, WalkerControl::my_timers_, MPIObjectBase::myComm, WalkerControl::R2ACCEPTED_INDEX, WalkerControl::R2PROPOSED_INDEX, WalkerControl::rank_num_, WalkerControl::saved_num_walkers_sent_, WalkerControl::SENTWALKERS_INDEX, WalkerControl::use_fixed_pop_, qmcplusplus::walker, qmcplusplus::hdf::walkers, WalkerControl::WALKERSIZE_INDEX, qmcplusplus::WC_allreduce, and WalkerControl::WEIGHT_INDEX.

Referenced by WalkerControl::branch().

254 {
255  FullPrecRealType esum = 0.0, e2sum = 0.0, wsum = 0.0;
256  FullPrecRealType r2_accepted = 0.0, r2_proposed = 0.0;
257  int num_good_walkers(0), num_total_copies(0);
258  for (const auto& walker : walkers)
259  {
260  const int num_copies = static_cast<int>(walker->Multiplicity);
261  num_good_walkers += num_copies > 0 ? 1 : 0;
262  num_total_copies += num_copies;
263  // Ye : not sure about these r2
264  r2_accepted += walker->Properties(WP::R2ACCEPTED);
265  r2_proposed += walker->Properties(WP::R2PROPOSED);
266  FullPrecRealType e = walker->Properties(WP::LOCALENERGY);
267  FullPrecRealType wgt = walker->Weight;
268  esum += wgt * e;
269  e2sum += wgt * e * e;
270  wsum += wgt;
271  }
272  //temp is an array to perform reduction operations
273  std::fill(curData.begin(), curData.end(), 0.0);
274  curData[ENERGY_INDEX] = esum;
275  curData[ENERGY_SQ_INDEX] = e2sum;
276  curData[WALKERSIZE_INDEX] = walkers.size(); // num of all the current walkers (good+bad)
277  curData[WEIGHT_INDEX] = wsum;
278  curData[R2ACCEPTED_INDEX] = r2_accepted;
279  curData[R2PROPOSED_INDEX] = r2_proposed;
280  curData[FNSIZE_INDEX] = num_good_walkers; // num of good walkers before branching
282  if (use_fixed_pop_)
283  curData[LE_MAX + rank_num_] = wsum; // node sum of walker weights
284  else
285  curData[LE_MAX + rank_num_] = num_total_copies; // node num of walkers after local branching
286 
287  {
288  ScopedTimer allreduce_timer(my_timers_[WC_allreduce]);
290  }
291 }
IndexType saved_num_walkers_sent_
Number of walkers sent during the exchange.
ScopeGuard< NewTimer > ScopedTimer
Definition: NewTimer.h:257
const char walkers[]
Definition: HDFVersion.h:36
const IndexType rank_num_
context id
void allreduce(T &)
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
TimerList_t my_timers_
timers
QMCTraits::FullPrecRealType FullPrecRealType
typedef of FullPrecRealType
Definition: WalkerControl.h:48
bool use_fixed_pop_
if true, use fixed population
std::vector< FullPrecRealType > curData
any temporary data includes many ridiculous conversions of integral types to and from fp ...

◆ determineNewWalkerPopulation()

void determineNewWalkerPopulation ( const std::vector< int > &  num_per_rank,
std::vector< int > &  fair_offset,
std::vector< int > &  minus,
std::vector< int > &  plus 
)
staticprivate

creates the distribution plan

populates the minus and plus vectors they contain 1 copy of a partition index for each adjustment in population to the context.

Parameters
[in]num_per_rankas if all walkers were copied out to multiplicity
[out]fair_offsetrunning population count at each partition boundary
[out]minuslist of partition indexes one occurrence for each walker removed
[out]pluslist of partition indexes one occurrence for each walker added

Definition at line 294 of file WalkerControl.cpp.

References qmcplusplus::app_error(), and FairDivideLow().

Referenced by UnifiedDriverWalkerControlMPITest::testNewDistribution().

298 {
299  const int num_contexts = num_per_rank.size();
300  const int current_population = std::accumulate(num_per_rank.begin(), num_per_rank.end(), 0);
301  FairDivideLow(current_population, num_contexts, fair_offset);
302  for (int ip = 0; ip < num_contexts; ip++)
303  {
304  int dn = num_per_rank[ip] - (fair_offset[ip + 1] - fair_offset[ip]);
305  if (dn > 0)
306  plus.insert(plus.end(), dn, ip);
307  else if (dn < 0)
308  minus.insert(minus.end(), -dn, ip);
309  }
310 #ifndef NDEBUG
311  if (plus.size() != minus.size())
312  {
313  app_error() << "Walker send/recv pattern doesn't match. "
314  << "The send size " << plus.size() << " is not equal to the recv size " << minus.size() << " ."
315  << std::endl;
316  throw std::runtime_error("Trying to swap in WalkerControl::swapWalkersSimple with mismatched queues");
317  }
318 #endif
319 }
std::ostream & app_error()
Definition: OutputManager.h:67
void FairDivideLow(int ntot, int npart, IV &adist)
partition ntot elements among npart
Definition: FairDivide.h:114

◆ get_ensemble_property()

MCDataType<FullPrecRealType>& get_ensemble_property ( )
inline

Definition at line 81 of file WalkerControl.h.

References WalkerControl::ensemble_property_.

81 { return ensemble_property_; }
MCDataType< FullPrecRealType > ensemble_property_
ensemble properties

◆ get_n_max()

int get_n_max ( ) const
inline

Definition at line 79 of file WalkerControl.h.

References WalkerControl::n_max_.

79 { return n_max_; }
IndexType n_max_
maximum number of walkers

◆ get_n_min()

int get_n_min ( ) const
inline

Definition at line 80 of file WalkerControl.h.

References WalkerControl::n_min_.

80 { return n_min_; }
IndexType n_min_
minimum number of walkers

◆ get_num_contexts()

IndexType get_num_contexts ( ) const
inline

Definition at line 86 of file WalkerControl.h.

References WalkerControl::num_ranks_.

86 { return num_ranks_; }
const IndexType num_ranks_
number of contexts

◆ killDeadWalkersOnRank()

void killDeadWalkersOnRank ( MCPopulation pop)
staticprivate

kill dead walkers in the population

Definition at line 525 of file WalkerControl.cpp.

References MCPopulation::checkIntegrity(), MCPopulation::get_walkers(), MCPopulation::killWalker(), qmcplusplus::walker, and qmcplusplus::hdf::walkers.

Referenced by WalkerControl::branch().

526 {
527  // kill walkers, actually put them in deadlist
528  RefVector<MCPWalker> bad_walkers;
529  auto& walkers = pop.get_walkers();
530  bad_walkers.reserve(walkers.size());
531  for (auto& walker : walkers)
532  if (static_cast<int>(walker->Multiplicity) == 0)
533  bad_walkers.push_back(*walker);
534  for (MCPWalker& bad_walker : bad_walkers)
535  pop.killWalker(bad_walker);
536 #ifndef NDEBUG
537  pop.checkIntegrity();
538 #endif
539 }
const char walkers[]
Definition: HDFVersion.h:36
MCPopulation::MCPWalker MCPWalker
distinct type for "new" walker, currently same as Walker_t
Definition: WalkerControl.h:46

◆ put()

bool put ( xmlNodePtr  cur)

Definition at line 550 of file WalkerControl.cpp.

References ParameterSet::add(), qmcplusplus::app_log(), Communicate::barrier_and_abort(), WalkerControl::debug_disable_branching_, WalkerControl::max_copy_, MPIObjectBase::myComm, WalkerControl::n_max_, WalkerControl::n_min_, ParameterSet::put(), WalkerControl::setMinMax(), and WalkerControl::use_nonblocking_.

551 {
552  int nw_target = 0, nw_max = 0;
553  ParameterSet params;
554  params.add(max_copy_, "maxCopy");
555  params.add(nw_target, "targetwalkers");
556  params.add(nw_max, "max_walkers");
557  params.add(use_nonblocking_, "use_nonblocking", {true});
558  params.add(debug_disable_branching_, "debug_disable_branching", {false});
559 
560  try
561  {
562  bool success = params.put(cur);
563  }
564  catch (const std::runtime_error& re)
565  {
566  myComm->barrier_and_abort("WalkerControl::put parsing error. " + std::string(re.what()));
567  }
568 
569  setMinMax(nw_target, nw_max);
570 
571  app_log() << " WalkerControl parameters " << std::endl;
572  //app_log() << " energyBound = " << targetEnergyBound << std::endl;
573  //app_log() << " sigmaBound = " << targetSigma << std::endl;
574  app_log() << " maxCopy = " << max_copy_ << std::endl;
575  app_log() << " Max Walkers per MPI rank " << n_max_ << std::endl;
576  app_log() << " Min Walkers per MPI rank " << n_min_ << std::endl;
577  app_log() << " Using " << (use_nonblocking_ ? "non-" : "") << "blocking send/recv" << std::endl;
579  app_log() << " Disable branching for debugging as the user input request." << std::endl;
580  return true;
581 }
std::ostream & app_log()
Definition: OutputManager.h:65
bool debug_disable_branching_
disable branching for debugging
void setMinMax(int nw_in, int nmax_in)
bool put(std::istream &is) override
read from std::istream
Definition: ParameterSet.h:42
IndexType n_min_
minimum number of walkers
bool use_nonblocking_
Use non-blocking isend/irecv.
class to handle a set of parameters
Definition: ParameterSet.h:27
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
IndexType n_max_
maximum number of walkers
void add(PDT &aparam, const std::string &aname_in, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new parameter corresponding to an xmlNode <parameter>
void barrier_and_abort(const std::string &msg) const
IndexType max_copy_
maximum copy per walker

◆ set_ensemble_property()

void set_ensemble_property ( MCDataType< FullPrecRealType > &  ensemble_property)
inline

Definition at line 82 of file WalkerControl.h.

References WalkerControl::ensemble_property_.

83  {
84  ensemble_property_ = ensemble_property;
85  }
MCDataType< FullPrecRealType > ensemble_property_
ensemble properties

◆ setMinMax()

void setMinMax ( int  nw_in,
int  nmax_in 
)

Definition at line 583 of file WalkerControl.cpp.

References WalkerControl::max_copy_, WalkerControl::n_max_, WalkerControl::n_min_, WalkerControl::num_ranks_, and WalkerControl::use_fixed_pop_.

Referenced by WalkerControl::put().

584 {
585  if (nw_in > 0)
586  {
587  int npernode = nw_in / num_ranks_;
588  if (use_fixed_pop_)
589  {
590  n_max_ = npernode;
591  n_min_ = npernode;
592  }
593  else
594  {
595  n_max_ = max_copy_ * npernode + 1;
596  n_min_ = npernode / 5 + 1;
597  if (nmax_in > 0)
598  n_max_ = nmax_in;
599  }
600  }
601 }
const IndexType num_ranks_
number of contexts
IndexType n_min_
minimum number of walkers
IndexType n_max_
maximum number of walkers
IndexType max_copy_
maximum copy per walker
bool use_fixed_pop_
if true, use fixed population

◆ setTrialEnergy()

void setTrialEnergy ( FullPrecRealType  et)
inline

set the trial energy for writing to dmc.dat

Definition at line 69 of file WalkerControl.h.

References WalkerControl::trial_energy_.

69 { trial_energy_ = et; }
FullPrecRealType trial_energy_
trial energy energy

◆ start()

void start ( )

start a block

Definition at line 78 of file WalkerControl.cpp.

References WalkerControl::dmcFname, WalkerControl::dmcStream, Communicate::getName(), MPIObjectBase::myComm, and WalkerControl::rank_num_.

79 {
80  if (rank_num_ == 0)
81  {
82  std::filesystem::path hname(myComm->getName());
83  hname.concat(".dmc.dat");
84  if (hname != dmcFname)
85  {
86  dmcStream = std::make_unique<std::ofstream>(hname);
87  dmcStream->setf(std::ios::scientific, std::ios::floatfield);
88  dmcStream->precision(10);
89  (*dmcStream) << "# Index " << std::setw(20) << "LocalEnergy" << std::setw(20) << "Variance" << std::setw(20)
90  << "Weight" << std::setw(20) << "NumOfWalkers" << std::setw(20)
91  << "AvgSentWalkers"; //add the number of walkers
92  (*dmcStream) << std::setw(20) << "TrialEnergy" << std::setw(20) << "DiffEff";
93  (*dmcStream) << std::setw(20) << "LivingFraction";
94  (*dmcStream) << std::endl;
95  dmcFname = std::move(hname);
96  }
97  }
98 }
std::filesystem::path dmcFname
filename for dmc.dat
const IndexType rank_num_
context id
const std::string & getName() const
Definition: Communicate.h:131
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
std::unique_ptr< std::ofstream > dmcStream
file to save energy histogram

◆ syncFutureWalkersPerRank()

std::vector< WalkerControl::IndexType > syncFutureWalkersPerRank ( Communicate comm,
IndexType  n_walkers 
)
staticprivate

Definition at line 541 of file WalkerControl.cpp.

References Communicate::allreduce(), qmcplusplus::comm, Communicate::rank(), and Communicate::size().

542 {
543  int ncontexts = comm->size();
544  std::vector<IndexType> future_walkers(ncontexts, 0);
545  future_walkers[comm->rank()] = n_walkers;
546  comm->allreduce(future_walkers);
547  return future_walkers;
548 }
int rank() const
return the rank
Definition: Communicate.h:116
int size() const
return the number of tasks
Definition: Communicate.h:118
void allreduce(T &)

◆ writeDMCdat()

void writeDMCdat ( int  iter,
const std::vector< FullPrecRealType > &  curData 
)

take averages and writes to a file

Definition at line 100 of file WalkerControl.cpp.

References MCDataType< T >::AlternateEnergy, WalkerControl::curData, WalkerControl::dmcStream, MCDataType< T >::Energy, WalkerControl::ENERGY_INDEX, WalkerControl::ENERGY_SQ_INDEX, WalkerControl::ensemble_property_, WalkerControl::FNSIZE_INDEX, MCDataType< T >::LivingFraction, WalkerControl::num_ranks_, MCDataType< T >::NumSamples, MCDataType< T >::R2Accepted, WalkerControl::R2ACCEPTED_INDEX, MCDataType< T >::R2Proposed, WalkerControl::R2PROPOSED_INDEX, WalkerControl::SENTWALKERS_INDEX, WalkerControl::trial_energy_, MCDataType< T >::Variance, WalkerControl::WALKERSIZE_INDEX, MCDataType< T >::Weight, and WalkerControl::WEIGHT_INDEX.

Referenced by WalkerControl::branch().

101 {
102  //taking average over the walkers
103  FullPrecRealType wgtInv(1.0 / curData[WEIGHT_INDEX]);
104  FullPrecRealType eavg = curData[ENERGY_INDEX] * wgtInv;
105  ensemble_property_.Energy = eavg;
107  ensemble_property_.Variance = (curData[ENERGY_SQ_INDEX] * wgtInv - eavg * eavg);
112  static_cast<FullPrecRealType>(curData[FNSIZE_INDEX]) / static_cast<FullPrecRealType>(curData[WALKERSIZE_INDEX]);
114  // \\todo If WalkerControl is not exclusively for dmc then this shouldn't be here.
115  // If it is it shouldn't be in QMDrivers but QMCDrivers/DMC
116  if (dmcStream)
117  {
118  //boost::archive::text_oarchive oa(*dmcStream);
119  //(*oa) & iter & eavg_cur & wgt_cur & Etrial & pop_old;
120  (*dmcStream) << std::setw(10) << iter << std::setw(20) << ensemble_property_.Energy << std::setw(20)
121  << ensemble_property_.Variance << std::setw(20) << ensemble_property_.Weight << std::setw(20)
122  << ensemble_property_.NumSamples << std::setw(20)
123  << curData[SENTWALKERS_INDEX] / static_cast<double>(num_ranks_);
124  (*dmcStream) << std::setw(20) << trial_energy_ << std::setw(20)
126  (*dmcStream) << std::setw(20) << ensemble_property_.LivingFraction;
127  // Work around for bug with deterministic scalar trace test on select compiler/architectures.
128  // While WalkerControl appears to have exclusive ownership of the dmcStream pointer,
129  // this is not actually true. Apparently it doesn't actually and can loose ownership then it is
130  // either leaked or not flushed before it is destroyed.
131  // \todo fix this, you don't want to flush every step since you really hope that could be very rapid.
132  (*dmcStream)
133  << std::endl; //'\n'; // this is definitely not a place to put an endl as that is also a signal for a flush.
134  }
135 }
FullPrecRealType trial_energy_
trial energy energy
const IndexType num_ranks_
number of contexts
MCDataType< FullPrecRealType > ensemble_property_
ensemble properties
QMCTraits::FullPrecRealType FullPrecRealType
typedef of FullPrecRealType
Definition: WalkerControl.h:48
std::unique_ptr< std::ofstream > dmcStream
file to save energy histogram
std::vector< FullPrecRealType > curData
any temporary data includes many ridiculous conversions of integral types to and from fp ...

Member Data Documentation

◆ curData

std::vector<FullPrecRealType> curData
private

any temporary data includes many ridiculous conversions of integral types to and from fp

Definition at line 170 of file WalkerControl.h.

Referenced by WalkerControl::branch(), WalkerControl::computeCurData(), and WalkerControl::writeDMCdat().

◆ debug_disable_branching_

bool debug_disable_branching_
private

disable branching for debugging

Definition at line 174 of file WalkerControl.h.

Referenced by WalkerControl::branch(), and WalkerControl::put().

◆ dmcFname

std::filesystem::path dmcFname
private

filename for dmc.dat

Definition at line 160 of file WalkerControl.h.

Referenced by WalkerControl::start().

◆ dmcStream

std::unique_ptr<std::ofstream> dmcStream
private

file to save energy histogram

Definition at line 162 of file WalkerControl.h.

Referenced by WalkerControl::start(), and WalkerControl::writeDMCdat().

◆ ensemble_property_

◆ fair_offset_

std::vector<int> fair_offset_
private

offset of the particle index for a fair distribution

Definition at line 158 of file WalkerControl.h.

Referenced by WalkerControl::WalkerControl().

◆ max_copy_

IndexType max_copy_
private

maximum copy per walker

Definition at line 152 of file WalkerControl.h.

Referenced by WalkerControl::put(), and WalkerControl::setMinMax().

◆ my_timers_

TimerList_t my_timers_
private

timers

Definition at line 178 of file WalkerControl.h.

Referenced by WalkerControl::branch(), and WalkerControl::computeCurData().

◆ n_max_

IndexType n_max_
private

maximum number of walkers

Definition at line 150 of file WalkerControl.h.

Referenced by WalkerControl::get_n_max(), WalkerControl::put(), and WalkerControl::setMinMax().

◆ n_min_

IndexType n_min_
private

minimum number of walkers

Definition at line 148 of file WalkerControl.h.

Referenced by WalkerControl::get_n_min(), WalkerControl::put(), and WalkerControl::setMinMax().

◆ num_per_rank_

std::vector<int> num_per_rank_
private

number of walkers on each MPI rank after branching before load balancing

Definition at line 156 of file WalkerControl.h.

Referenced by WalkerControl::branch(), and WalkerControl::WalkerControl().

◆ num_ranks_

◆ rank_num_

const IndexType rank_num_
private

context id

Definition at line 164 of file WalkerControl.h.

Referenced by WalkerControl::computeCurData(), and WalkerControl::start().

◆ rng_

RandomBase<FullPrecRealType>& rng_
private

random number generator

Definition at line 144 of file WalkerControl.h.

Referenced by WalkerControl::branch().

◆ saved_num_walkers_sent_

IndexType saved_num_walkers_sent_
private

Number of walkers sent during the exchange.

Definition at line 180 of file WalkerControl.h.

Referenced by WalkerControl::computeCurData().

◆ SwapMode

IndexType SwapMode
private

0 is default

Definition at line 168 of file WalkerControl.h.

◆ trial_energy_

FullPrecRealType trial_energy_
private

trial energy energy

Definition at line 154 of file WalkerControl.h.

Referenced by WalkerControl::setTrialEnergy(), and WalkerControl::writeDMCdat().

◆ use_fixed_pop_

bool use_fixed_pop_
private

if true, use fixed population

Definition at line 146 of file WalkerControl.h.

Referenced by WalkerControl::branch(), WalkerControl::computeCurData(), and WalkerControl::setMinMax().

◆ use_nonblocking_

bool use_nonblocking_
private

Use non-blocking isend/irecv.

Definition at line 172 of file WalkerControl.h.

Referenced by WalkerControl::put().


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