34 :
MPIObjectBase(c), n_min_(1), n_max_(10), MaxCopy(2), target_sigma_(10), NumWalkersCreated(0), SwapMode(0)
65 hname.concat(
".dmc.dat");
68 dmcStream = std::make_unique<std::ofstream>(hname.c_str());
69 dmcStream->setf(std::ios::scientific, std::ios::floatfield);
71 (*dmcStream) <<
"# Index " << std::setw(20) <<
"LocalEnergy" << std::setw(20) <<
"Variance" << std::setw(20)
72 <<
"Weight" << std::setw(20) <<
"NumOfWalkers" << std::setw(20)
74 (*dmcStream) << std::setw(20) <<
"TrialEnergy" << std::setw(20) <<
"DiffEff";
76 (*dmcStream) << std::setw(20) <<
"LivingFraction";
77 (*dmcStream) << std::endl;
88 if (
walker->getWalkerID() == 0)
123 (*dmcStream) << std::setw(20) <<
trialEnergy << std::setw(20)
145 FullPrecRealType esum = 0.0, e2sum = 0.0, wsum = 0.0, ecum = 0.0, besum = 0.0, bwgtsum = 0.0;
147 int nrn(0), ncr(0), nfn(0), nc(0);
155 r2_accepted +=
walker->Properties(WP::R2ACCEPTED);
156 r2_proposed +=
walker->Properties(WP::R2PROPOSED);
163 e2sum += wgt *
e *
e;
209 walker->Multiplicity = 1.0;
213 W.setWalkerOffsets({0, nw_tot});
225 std::vector<std::unique_ptr<Walker_t>> good_rn;
226 std::vector<int> ncopy_rn;
228 FullPrecRealType esum = 0.0, e2sum = 0.0, wsum = 0.0, ecum = 0.0, besum = 0.0, bwgtsum = 0.0;
236 r2_accepted +=
walker->Properties(WP::R2ACCEPTED);
237 r2_proposed +=
walker->Properties(WP::R2PROPOSED);
241 e2sum += wgt *
e *
e;
282 app_warning() <<
"Exceeding Max Walkers per MPI rank : " <<
n_max_ <<
". Ceiling is applied" << std::endl;
293 for (
int iw = 0; iw <
ncopy_w.size(); iw++)
296 ncopy_w[iw] -= n_remove_walker;
297 n_remove -= n_remove_walker;
304 app_warning() <<
"Removing copies of good walkers is not enough. " 305 <<
"Removing good walkers." << std::endl;
312 }
while (n_remove > 0 && !
good_w.empty());
316 APP_ABORT(
"WalkerControlBase::applyNmaxNmin not able to remove sufficient walkers on a node!");
318 APP_ABORT(
"WalkerControlBase::applyNmaxNmin walker removal mismatch!");
326 APP_ABORT(
"WalkerControlBase::applyNmaxNmin not able to remove sufficient walkers overall!");
332 app_warning() <<
"The number of walkers is running lower than Min Walkers per MPI rank : " <<
n_min_ 333 <<
". Floor is applied" << std::endl;
344 int n_avg_insert_per_walker = (n_insert +
ncopy_w.size() - 1) /
ncopy_w.size();
345 for (
int iw = 0; iw <
ncopy_w.size(); iw++)
347 int n_insert_walker =
std::min(n_avg_insert_per_walker, n_insert);
348 ncopy_w[iw] += n_insert_walker;
349 n_insert -= n_insert_walker;
355 APP_ABORT(
"WalkerControlBase::applyNmaxNmin walker insertion mismatch!");
363 app_warning() <<
"WalkerControlBase::applyNmaxNmin not able to add sufficient walkers overall!" << std::endl;
371 app_error() <<
"Some MPI ranks have no walkers after load balancing. This should not happen." 372 <<
"Improve the trial wavefunction or adjust the simulation parameters." << std::endl;
373 APP_ABORT(
"WalkerControlBase::sortWalkers");
376 return current_population;
387 const int size_good_w =
good_w.size();
388 std::vector<int> copy_list;
389 for (
int i = 0; i < size_good_w; i++)
391 for (
int j = 0; j <
ncopy_w[i]; j++)
395 good_w.push_back(
nullptr);
402 copy_list.push_back(i);
406 #pragma omp parallel for 407 for (
int i = size_good_w; i <
good_w.size(); i++)
409 auto& wRef =
good_w[copy_list[i - size_good_w]];
410 auto& awalker =
good_w[i];
411 if (awalker ==
nullptr)
412 awalker = std::make_unique<Walker_t>(*wRef);
417 awalker->setParentID(wRef->getParentID());
433 int nw_target = 0, nw_max = 0;
434 std::string nonblocking =
"yes";
438 params.
add(nw_target,
"targetwalkers");
439 params.
add(nw_max,
"max_walkers");
440 params.
add(nonblocking,
"use_nonblocking");
442 bool success = params.
put(cur);
445 if (nonblocking ==
"yes")
449 else if (nonblocking ==
"no")
455 APP_ABORT(
"WalkerControlBase::put unknown use_nonblocking option " + nonblocking);
460 app_log() <<
" WalkerControlBase parameters " << std::endl;
464 app_log() <<
" Max Walkers per MPI rank " <<
n_max_ << std::endl;
465 app_log() <<
" Min Walkers per MPI rank " <<
n_min_ << std::endl;
483 n_min_ = npernode / 5 + 1;
WalkerControlBase(Communicate *c)
default constructor
virtual void reset()
reset to accumulate data
std::vector< std::unique_ptr< Walker_t > > bad_w
FullPrecRealType target_sigma_
target sigma to limit fluctuations of the trial energy
IndexType NumWalkers
current number of walkers per processor
int copyWalkers(MCWalkerConfiguration &W)
legacy: copy good walkers to W
A set of walkers that are to be advanced by Metropolis Monte Carlo.
std::ostream & app_warning()
std::vector< int > NumPerRank
number of particle per rank
Base class for any object which needs to know about a MPI communicator.
helper functions for EinsplineSetBuilder
int rank() const
return the rank
std::filesystem::path dmcFname
filename for dmc.dat
size_t getActiveWalkers() const
return the number of active walkers
std::ostream & app_error()
std::vector< int > ncopy_w
temporary storage for copy counters
FullPrecRealType trialEnergy
trial energy energy
std::vector< FullPrecRealType > accumData
any accumulated data over a block
IndexType MyContext
context id
int size() const
return the number of tasks
bool put(std::istream &is) override
read from std::istream
bool use_nonblocking
Use non-blocking isend/irecv.
Wrapping information on parallelism.
std::vector< int > FairOffSet
offset of the particle index for a fair distribution
void start()
start a block
int doNotBranch(int iter, MCWalkerConfiguration &W)
legacy: return global population update properties without branching
IndexType method_
id for the method
const std::string & getName() const
class to handle a set of parameters
WalkerProperties::Indexes WP
std::vector< int > OffSet
offset of the particle index
Communicate * myComm
pointer to Communicate
IndexType n_min_
minimum number of walkers
void measureProperties(int iter)
take averages and writes to a file
std::vector< FullPrecRealType > curData
any temporary data includes many ridiculous conversions of integral types to and from fp ...
void setWalkerID(MCWalkerConfiguration &walkers)
start controller and initialize the IDs of walkers
IndexType NumWalkersCreated
Number of walkers created by this rank.
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
std::unique_ptr< std::ofstream > dmcStream
file to save energy histogram
IndexType num_contexts_
number of contexts
Declaration of a TrialWaveFunction.
std::vector< std::unique_ptr< Walker_t > > good_w
temporary storage for good and bad 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 insert(iterator it, INPUT_ITER first, INPUT_ITER last)
insert elements
virtual int branch(int iter, MCWalkerConfiguration &W, FullPrecRealType trigger)
legacy: perform branch and swap walkers as required
void setMinMax(int nw_in, int nmax_in)
IndexType n_max_
maximum number of walkers
Indexes
an enum denoting index of physical properties
IndexType MaxCopy
maximum copy per walker
QMCTraits::FullPrecRealType FullPrecRealType
typedef of FullPrecRealType
virtual ~WalkerControlBase()
empty destructor to clean up the derived classes
int sortWalkers(MCWalkerConfiguration &W)
legacy: sort Walkers between good and bad and prepare branching
MCDataType< FullPrecRealType > EnsembleProperty
MCDataType< FullPrecRealType > ensemble_property_
ensemble properties
void clear()
clean up the walker list
int applyNmaxNmin(int current_population)
legacy: apply per rank limit Nmax and Nmin
iterator begin()
return the first iterator