From 1bf86570afc19e0c9a6a333185120c9a952eba33 Mon Sep 17 00:00:00 2001 From: Carlo Camilloni <carlo.camilloni@gmail.com> Date: Tue, 5 Jul 2016 15:29:10 +0200 Subject: [PATCH] MetaD: removed some communication from MPI_WALKERS --- src/bias/MetaD.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/bias/MetaD.cpp b/src/bias/MetaD.cpp index 61efda7b7..8dd77a366 100644 --- a/src/bias/MetaD.cpp +++ b/src/bias/MetaD.cpp @@ -350,6 +350,7 @@ private: int mw_id_; int mw_rstride_; bool walkers_mpi; + unsigned mpi_nw_; bool acceleration; double acc; vector<IFile*> ifiles; @@ -465,7 +466,7 @@ dp_(NULL), adaptive_(FlexibleBin::none), flexbin(NULL), // Multiple walkers initialization mw_n_(1), mw_dir_("./"), mw_id_(0), mw_rstride_(1), -walkers_mpi(false), +walkers_mpi(false), mpi_nw_(0), acceleration(false), acc(0.0), // Interval initialization uppI_(-1), lowI_(-1), doInt_(false), @@ -713,7 +714,16 @@ last_step_warn_grid(0) log.printf(" reading stride %d\n",mw_rstride_); log.printf(" directory with hills files %s\n",mw_dir_.c_str()); } else { - if(walkers_mpi) log.printf(" Multiple walkers active using MPI communnication\n"); + if(walkers_mpi) { + log.printf(" Multiple walkers active using MPI communnication\n"); + if(comm.Get_rank()==0){ + // Only root of group can communicate with other walkers + mpi_nw_=multi_sim_comm.Get_size(); + } + // Communicate to the other members of the same group + // info abount number of walkers and walker index + comm.Bcast(mpi_nw_,0); + } } if( rewf_grid_.size()>0 ){ @@ -1313,22 +1323,11 @@ void MetaD::update(){ // In case we use walkers_mpi, it is now necessary to communicate with other replicas. if(walkers_mpi){ - int nw=0; - int mw=0; - if(comm.Get_rank()==0){ - // Only root of group can communicate with other walkers - nw=multi_sim_comm.Get_size(); - mw=multi_sim_comm.Get_rank(); - } - // Communicate to the other members of the same group - // info abount number of walkers and walker index - comm.Bcast(nw,0); - comm.Bcast(mw,0); // Allocate arrays to store all walkers hills - std::vector<double> all_cv(nw*cv.size(),0.0); - std::vector<double> all_sigma(nw*thissigma.size(),0.0); - std::vector<double> all_height(nw,0.0); - std::vector<int> all_multivariate(nw,0); + std::vector<double> all_cv(mpi_nw_*cv.size(),0.0); + std::vector<double> all_sigma(mpi_nw_*thissigma.size(),0.0); + std::vector<double> all_height(mpi_nw_,0.0); + std::vector<int> all_multivariate(mpi_nw_,0); if(comm.Get_rank()==0){ // Communicate (only root) multi_sim_comm.Allgather(cv,all_cv); @@ -1341,7 +1340,7 @@ void MetaD::update(){ comm.Bcast(all_sigma,0); comm.Bcast(all_height,0); comm.Bcast(all_multivariate,0); - for(int i=0;i<nw;i++){ + for(unsigned i=0;i<mpi_nw_;i++){ // actually add hills one by one std::vector<double> cv_now(cv.size()); std::vector<double> sigma_now(thissigma.size()); -- GitLab