QMCPACK
WalkerConfigurations.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: Jordan E. Vincent, University of Illinois at Urbana-Champaign
8 // Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11 // Cynthia Gu, zg1@ornl.gov, Oak Ridge National Laboratory
12 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
13 // Ye Luo, yeluo@anl.gov, Argonne National Laboratory
14 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
15 //
16 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
17 //////////////////////////////////////////////////////////////////////////////////////
18 
19 
20 /** @file WalkerConfigurations.h
21  * @brief Declaration of a WalkerConfigurations
22  */
23 #ifndef QMCPLUSPLUS_WALKERCONFIGURATIONS_H
24 #define QMCPLUSPLUS_WALKERCONFIGURATIONS_H
25 #include "Configuration.h"
26 #include "Particle/Walker.h"
28 
29 namespace qmcplusplus
30 {
31 /** Monte Carlo Data of an ensemble
32  *
33  * The quantities are shared by all the nodes in a group
34  * - NumSamples number of samples
35  * - Weight total weight of a sample
36  * - Energy average energy of a sample
37  * - Variance variance
38  * - LivingFraction fraction of walkers alive each step.
39  */
40 template<typename T>
41 struct MCDataType
42 {
45  T Weight;
46  T Energy;
52 };
53 
54 /** A set of light weight walkers that are carried between driver sections and restart
55  */
57 {
58 public:
59  /// walker type
62  ///container type of Walkers
63  using walker_list__t = std::vector<std::unique_ptr<Walker_t>>;
64  /// FIX: a type alias of iterator for an object should not be for just one of many objects it holds.
65  using iterator = walker_list__t::iterator;
66  ///const_iterator of Walker container
67  using const_iterator = walker_list__t::const_iterator;
68 
70 
77 
78  /** create numWalkers Walkers
79  *
80  * Append Walkers to walker_list_.
81  */
82  void createWalkers(int numWalkers, size_t numPtcls);
83  /** create walkers
84  * @param first walker iterator
85  * @param last walker iterator
86  */
87  void createWalkers(iterator first, iterator last);
88  /** copy walkers
89  * @param first input walker iterator
90  * @param last input walker iterator
91  * @param start first target iterator
92  *
93  * No memory allocation is allowed.
94  */
95  void copyWalkers(iterator first, iterator last, iterator start);
96 
97  /** destroy Walkers from itstart to itend
98  *@param first starting iterator of the walkers
99  *@param last ending iterator of the walkers
100  */
102 
103  /** destroy Walkers
104  *@param nw number of walkers to be destroyed
105  */
106  void destroyWalkers(int nw);
107 
108  ///clean up the walker list and make a new list
109  void resize(int numWalkers, size_t numPtcls);
110 
111  ///return the number of active walkers
112  inline size_t getActiveWalkers() const { return walker_list_.size(); }
113  ///return the total number of active walkers among a MPI group
114  inline size_t getGlobalNumWalkers() const { return walker_offsets_.empty() ? 0 : walker_offsets_.back(); }
115  ///return the total number of active walkers among a MPI group
116 
117  inline void setWalkerOffsets(const std::vector<int>& o) { walker_offsets_ = o; }
118  inline const std::vector<int>& getWalkerOffsets() const { return walker_offsets_; }
119 
120  /// return the first iterator
121  inline iterator begin() { return walker_list_.begin(); }
122  /// return the last iterator, [begin(), end())
123  inline iterator end() { return walker_list_.end(); }
124 
125  /// return the first const_iterator
126  inline const_iterator begin() const { return walker_list_.begin(); }
127 
128  /// return the last const_iterator [begin(), end())
129  inline const_iterator end() const { return walker_list_.end(); }
130  /**@}*/
131 
132  /** clear the walker_list_ without destroying them
133  *
134  * Provide std::vector::clear interface
135  */
136  inline void clear() { walker_list_.clear(); }
137 
138  /** insert elements
139  * @param it locator where the inserting begins
140  * @param first starting iterator
141  * @param last ending iterator
142  *
143  * Provide std::vector::insert interface
144  */
145  template<class INPUT_ITER>
146  inline void insert(iterator it, INPUT_ITER first, INPUT_ITER last)
147  {
148  walker_list_.insert(it, first, last);
149  }
150 
151  /** add Walker_t* at the end
152  * @param awalker pointer to a walker
153  *
154  * Provide std::vector::push_back interface
155  */
156  inline void push_back(std::unique_ptr<Walker_t> awalker) { walker_list_.push_back(std::move(awalker)); }
157 
158  /** delete the last Walker_t*
159  *
160  * Provide std::vector::pop_back interface
161  */
162  inline void pop_back() { walker_list_.pop_back(); }
163 
164  inline Walker_t* operator[](int i) { return walker_list_[i].get(); }
165 
166  inline const Walker_t* operator[](int i) const { return walker_list_[i].get(); }
167 
168  /** reset the Walkers
169  */
170  void reset();
171 
172  ///save the particle positions of all the walkers into target
174 
175 protected:
176  ///a collection of walkers
178 
179 private:
180  /** starting index of the walkers in a processor group
181  *
182  * walker_offsets_[0]=0 and walker_offsets_[walker_offsets_.size()-1]=total number of walkers in a group
183  * walker_offsets_[processorid+1]-walker_offsets_[processorid] is equal to the number of walkers on a processor,
184  * i.e., W.getActiveWalkers().
185  * walker_offsets_ is added to handle parallel I/O with hdf5
186  */
187  std::vector<int> walker_offsets_;
188 };
189 } // namespace qmcplusplus
190 #endif
const Walker_t * operator[](int i) const
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
size_t getActiveWalkers() const
return the number of active walkers
A set of light weight walkers that are carried between driver sections and restart.
void pop_back()
delete the last Walker_t*
void setWalkerOffsets(const std::vector< int > &o)
return the total number of active walkers among a MPI group
walker_list__t::iterator iterator
FIX: a type alias of iterator for an object should not be for just one of many objects it holds...
void push_back(std::unique_ptr< Walker_t > awalker)
add Walker_t* at the end
size_t getGlobalNumWalkers() const
return the total number of active walkers among a MPI group
const_iterator begin() const
return the first const_iterator
iterator destroyWalkers(iterator first, iterator last)
destroy Walkers from itstart to itend
void clear()
clear the walker_list_ without destroying them
const_iterator end() const
return the last const_iterator [begin(), end())
WalkerConfigurations & operator=(const WalkerConfigurations &)=delete
void copyWalkers(iterator first, iterator last, iterator start)
copy walkers
void createWalkers(int numWalkers, size_t numPtcls)
create numWalkers Walkers
walker_list__t::const_iterator const_iterator
const_iterator of Walker container
std::vector< std::unique_ptr< Walker_t > > walker_list__t
container type of Walkers
QMCTraits::FullPrecRealType FullPrecRealType
const std::vector< int > & getWalkerOffsets() const
Monte Carlo Data of an ensemble.
void insert(iterator it, INPUT_ITER first, INPUT_ITER last)
insert elements
void resize(int numWalkers, size_t numPtcls)
clean up the walker list and make a new list
typename t_traits::RealType RealType
typedef for real data type
Definition: Walker.h:58
QTFull::RealType FullPrecRealType
Definition: Configuration.h:66
MCDataType< FullPrecRealType > EnsembleProperty
void putConfigurations(Walker_t::RealType *target, QMCTraits::FullPrecRealType *weights) const
save the particle positions of all the walkers into target
iterator end()
return the last iterator, [begin(), end())
walker_list__t walker_list_
a collection of walkers
std::vector< int > walker_offsets_
starting index of the walkers in a processor group
A container class to represent a walker.
Definition: Walker.h:49
iterator begin()
return the first iterator