From 0ffbea6baf26d80cb801a8f7fc584982de14152a Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Thu, 12 Sep 2024 22:37:35 -0500 Subject: [PATCH 1/2] Remove unused wgt_tot2 --- src/QMCDrivers/WFOpt/QMCCostFunctionBatched.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/QMCDrivers/WFOpt/QMCCostFunctionBatched.cpp b/src/QMCDrivers/WFOpt/QMCCostFunctionBatched.cpp index e0a9f1a786..27ad981d6e 100644 --- a/src/QMCDrivers/WFOpt/QMCCostFunctionBatched.cpp +++ b/src/QMCDrivers/WFOpt/QMCCostFunctionBatched.cpp @@ -661,7 +661,6 @@ QMCCostFunctionBatched::EffectiveWeight QMCCostFunctionBatched::correlatedSampli //Return_rt wgt_node = 0.0, wgt_node2 = 0.0; Return_rt wgt_tot = 0.0; - Return_rt wgt_tot2 = 0.0; // Ensure number of samples did not change after getConfiguration assert(rank_local_num_samples_ == samples_.getNumSamples()); @@ -820,17 +819,12 @@ QMCCostFunctionBatched::EffectiveWeight QMCCostFunctionBatched::correlatedSampli compute_all_from_scratch, vmc_or_dmc, needGrad); // Sum weights over crowds for (int i = 0; i < opt_eval.size(); i++) - { wgt_tot += opt_eval[i]->get_wgt(); - wgt_tot2 += opt_eval[i]->get_wgt2(); - } //this is MPI barrier OHMMS::Controller->barrier(); //collect the total weight for normalization and apply maximum weight myComm->allreduce(wgt_tot); - myComm->allreduce(wgt_tot2); - // app_log()<<"Before Purge"<allreduce(wgt_tot); - // app_log()<<"During Purge"< Date: Thu, 12 Sep 2024 22:48:36 -0500 Subject: [PATCH 2/2] More compact code. --- .../WFOpt/QMCCostFunctionBatched.cpp | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/QMCDrivers/WFOpt/QMCCostFunctionBatched.cpp b/src/QMCDrivers/WFOpt/QMCCostFunctionBatched.cpp index 27ad981d6e..68545f137e 100644 --- a/src/QMCDrivers/WFOpt/QMCCostFunctionBatched.cpp +++ b/src/QMCDrivers/WFOpt/QMCCostFunctionBatched.cpp @@ -287,9 +287,7 @@ void QMCCostFunctionBatched::checkConfigurations(EngineHandle& handle) for (int inb = 0; inb < num_batches; inb++) { - int current_batch_size = walkers_per_crowd[crowd_id]; - if (inb == num_batches - 1) - current_batch_size = final_batch_size; + const int current_batch_size = inb == num_batches - 1 ? final_batch_size : walkers_per_crowd[crowd_id]; const int base_sample_index = inb * walkers_per_crowd[crowd_id] + samples_per_crowd_offsets[crowd_id]; @@ -487,9 +485,7 @@ void QMCCostFunctionBatched::checkConfigurationsSR(EngineHandle& handle) for (int inb = 0; inb < num_batches; inb++) { - int current_batch_size = walkers_per_crowd[crowd_id]; - if (inb == num_batches - 1) - current_batch_size = final_batch_size; + const int current_batch_size = inb == num_batches - 1 ? final_batch_size : walkers_per_crowd[crowd_id]; const int base_sample_index = inb * walkers_per_crowd[crowd_id] + samples_per_crowd_offsets[crowd_id]; @@ -660,7 +656,7 @@ QMCCostFunctionBatched::EffectiveWeight QMCCostFunctionBatched::correlatedSampli } //Return_rt wgt_node = 0.0, wgt_node2 = 0.0; - Return_rt wgt_tot = 0.0; + Return_rt wgt_tot = 0.0; // Ensure number of samples did not change after getConfiguration assert(rank_local_num_samples_ == samples_.getNumSamples()); @@ -697,11 +693,7 @@ QMCCostFunctionBatched::EffectiveWeight QMCCostFunctionBatched::correlatedSampli for (int inb = 0; inb < num_batches; inb++) { - int current_batch_size = walkers_per_crowd[crowd_id]; - if (inb == num_batches - 1) - { - current_batch_size = final_batch_size; - } + const int current_batch_size = inb == num_batches - 1 ? final_batch_size : walkers_per_crowd[crowd_id]; const int base_sample_index = inb * walkers_per_crowd[crowd_id] + samples_per_crowd_offsets[crowd_id]; @@ -1032,8 +1024,7 @@ QMCCostFunctionBatched::Return_rt QMCCostFunctionBatched::fillHamVec(std::vector return 1.0; } -void QMCCostFunctionBatched::calcOvlParmVec(const std::vector& parm, - std::vector& ovlParmVec) +void QMCCostFunctionBatched::calcOvlParmVec(const std::vector& parm, std::vector& ovlParmVec) { ScopedTimer tmp_timer(fill_timer_); @@ -1060,7 +1051,7 @@ void QMCCostFunctionBatched::calcOvlParmVec(const std::vector& parm, Return_rt weight = saved[REWEIGHT] * wgtinv; const Return_t* Dsaved = DerivRecords_[iw]; for (int pm = 0; pm < getNumParams(); pm++) - prod[iw] += (Dsaved[pm] - D_avg[pm]) * parm[pm]; + prod[iw] += (Dsaved[pm] - D_avg[pm]) * parm[pm]; }