Skip to content

Commit

Permalink
Merge pull request #1104 from ye-luo/cleanup-myComm
Browse files Browse the repository at this point in the history
Require MPI communicator to be passed to MPIObjectBase
  • Loading branch information
prckent authored Oct 10, 2018
2 parents d987228 + 32e0f84 commit 4f6ccf2
Show file tree
Hide file tree
Showing 71 changed files with 173 additions and 229 deletions.
32 changes: 2 additions & 30 deletions src/Message/MPIObjectBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,9 @@
namespace qmcplusplus
{

MPIObjectBase::MPIObjectBase(Communicate* c): ReportLevel(1),
myComm(0), ClassName("MPIObjectBase")
MPIObjectBase::MPIObjectBase(Communicate* c)
: myComm(c), ClassName("MPIObjectBase")
{
initCommunicator(c);
if(myComm->rank())
ReportLevel=0;
}

//MPIObjectBase::MPIObjectBase(const MPIObjectBase& a): myComm(0)
//{}

MPIObjectBase::~MPIObjectBase()
{}

void MPIObjectBase::initCommunicator(Communicate* c)
{
if(myComm && myComm == c)
return;
myComm = c ? c:OHMMS::Controller;
}

void MPIObjectBase::setReportLevel(int level)
{
//demote the level if not the head node
ReportLevel=(myComm->rank())?0:level;
//if(ReportLevel)
//{//inherit the global info streams
// LogBuffer.set(*OhmmsInfo::Log,ClassName);
// WarnBuffer.set(*OhmmsInfo::Warn);
// ErrorBuffer.set(*OhmmsInfo::Error);
//}
}

}
21 changes: 2 additions & 19 deletions src/Message/MPIObjectBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,8 @@ class MPIObjectBase
typedef Communicate::mpi_comm_type mpi_comm_type;
typedef Communicate::intra_comm_type intra_comm_type;

///default constructor
MPIObjectBase(Communicate* c=0);

///virtual destructor
virtual ~MPIObjectBase();

/** initialize myComm
* @param c communicator
*/
void initCommunicator(Communicate* c);
///constructor with communicator
MPIObjectBase(Communicate* c);

///return the rank of the communicator
inline int rank() const
Expand Down Expand Up @@ -76,10 +68,6 @@ class MPIObjectBase
return !myComm->rank();
}

/** default is 1 minal
*/
void setReportLevel(int level=1);

///return the name
inline const std::string& getName() const
{
Expand All @@ -92,8 +80,6 @@ class MPIObjectBase
}

protected:
///level of report
int ReportLevel;
/** pointer to Communicate
* @todo use smart pointer
*/
Expand All @@ -104,9 +90,6 @@ class MPIObjectBase
/** name of the object */
std::string myName;

//private:
// //disable copy constructor for now
// MPIObjectBase(const MPIObjectBase& a);
};

}
Expand Down
17 changes: 8 additions & 9 deletions src/QMCApp/QMCDriverFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ bool QMCDriverFactory::setQMCDriver(int curSeries, xmlNodePtr cur)
//create a driver
createQMCDriver(cur);
//initialize QMCDriver::myComm
qmcDriver->initCommunicator(myComm);
//branchEngine has to be transferred to a new QMCDriver
if(branchEngine)
qmcDriver->setBranchEngine(branchEngine);
Expand Down Expand Up @@ -287,7 +286,7 @@ void QMCDriverFactory::createQMCDriver(xmlNodePtr cur)
{
//VMCFactory fac(curQmcModeBits[UPDATE_MODE],cur);
VMCFactory fac(curQmcModeBits.to_ulong(),cur);
qmcDriver = fac.create(*qmcSystem,*primaryPsi,*primaryH,*ptclPool,*hamPool,*psiPool);
qmcDriver = fac.create(*qmcSystem,*primaryPsi,*primaryH,*ptclPool,*hamPool,*psiPool,myComm);
//TESTING CLONE
//TrialWaveFunction* psiclone=primaryPsi->makeClone(*qmcSystem);
//qmcDriver = fac.create(*qmcSystem,*psiclone,*primaryH,*ptclPool,*hamPool);
Expand All @@ -296,16 +295,16 @@ void QMCDriverFactory::createQMCDriver(xmlNodePtr cur)
{
DMCFactory fac(curQmcModeBits[UPDATE_MODE],
curQmcModeBits[GPU_MODE], cur);
qmcDriver = fac.create(*qmcSystem,*primaryPsi,*primaryH,*hamPool,*psiPool);
qmcDriver = fac.create(*qmcSystem,*primaryPsi,*primaryH,*hamPool,*psiPool,myComm);
}
else if(curRunType == RMC_RUN)
{
RMCFactory fac(curQmcModeBits[UPDATE_MODE], cur);
qmcDriver = fac.create(*qmcSystem,*primaryPsi,*primaryH,*ptclPool,*hamPool,*psiPool);
qmcDriver = fac.create(*qmcSystem,*primaryPsi,*primaryH,*ptclPool,*hamPool,*psiPool,myComm);
}
else if(curRunType == OPTIMIZE_RUN)
{
QMCOptimize *opt = new QMCOptimize(*qmcSystem,*primaryPsi,*primaryH,*hamPool,*psiPool);
QMCOptimize *opt = new QMCOptimize(*qmcSystem,*primaryPsi,*primaryH,*hamPool,*psiPool,myComm);
//ZeroVarianceOptimize *opt = new ZeroVarianceOptimize(*qmcSystem,*primaryPsi,*primaryH );
opt->setWaveFunctionNode(psiPool->getWaveFunctionNode("psi0"));
qmcDriver=opt;
Expand All @@ -315,7 +314,7 @@ void QMCDriverFactory::createQMCDriver(xmlNodePtr cur)
#ifdef MIXED_PRECISION
APP_ABORT("QMCDriverFactory::createQMCDriver : method=\"linear\" is not safe with CPU mixed precision. Please use full precision build instead.");
#endif
QMCFixedSampleLinearOptimize *opt = new QMCFixedSampleLinearOptimize(*qmcSystem,*primaryPsi,*primaryH,*hamPool,*psiPool);
QMCFixedSampleLinearOptimize *opt = new QMCFixedSampleLinearOptimize(*qmcSystem,*primaryPsi,*primaryH,*hamPool,*psiPool,myComm);
//ZeroVarianceOptimize *opt = new ZeroVarianceOptimize(*qmcSystem,*primaryPsi,*primaryH );
opt->setWaveFunctionNode(psiPool->getWaveFunctionNode("psi0"));
qmcDriver=opt;
Expand All @@ -324,9 +323,9 @@ void QMCDriverFactory::createQMCDriver(xmlNodePtr cur)
{
#if defined(QMC_CUDA)
app_log() << "cslinear is not supported. Switch to linear method. " << std::endl;
QMCFixedSampleLinearOptimize *opt = new QMCFixedSampleLinearOptimize(*qmcSystem,*primaryPsi,*primaryH,*hamPool,*psiPool);
QMCFixedSampleLinearOptimize *opt = new QMCFixedSampleLinearOptimize(*qmcSystem,*primaryPsi,*primaryH,*hamPool,*psiPool,myComm);
#else
QMCCorrelatedSamplingLinearOptimize *opt = new QMCCorrelatedSamplingLinearOptimize(*qmcSystem,*primaryPsi,*primaryH,*hamPool,*psiPool);
QMCCorrelatedSamplingLinearOptimize *opt = new QMCCorrelatedSamplingLinearOptimize(*qmcSystem,*primaryPsi,*primaryH,*hamPool,*psiPool,myComm);
#endif
opt->setWaveFunctionNode(psiPool->getWaveFunctionNode("psi0"));
qmcDriver=opt;
Expand All @@ -335,7 +334,7 @@ void QMCDriverFactory::createQMCDriver(xmlNodePtr cur)
{
app_log() << "Testing wavefunctions." << std::endl;
qmcDriver = new WaveFunctionTester(*qmcSystem,*primaryPsi,*primaryH,
*ptclPool,*psiPool);
*ptclPool,*psiPool,myComm);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/QMCDrivers/CorrelatedSampling/CSVMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace qmcplusplus

/// Constructor.
CSVMC::CSVMC(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h,
WaveFunctionPool& ppool):
QMCDriver(w,psi,h,ppool), multiEstimator(0), Mover(0), UseDrift("yes")
WaveFunctionPool& ppool, Communicate* comm):
QMCDriver(w,psi,h,ppool,comm), multiEstimator(0), Mover(0), UseDrift("yes")
{
RootName = "csvmc";
QMCType ="CSVMC";
Expand Down
2 changes: 1 addition & 1 deletion src/QMCDrivers/CorrelatedSampling/CSVMC.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CSVMC: public QMCDriver, public CloneManager
public:
/// Constructor.
CSVMC(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h,
WaveFunctionPool& ppool);
WaveFunctionPool& ppool, Communicate* comm);

bool run();
bool put(xmlNodePtr cur);
Expand Down
8 changes: 4 additions & 4 deletions src/QMCDrivers/DMC/DMCFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
namespace qmcplusplus
{

QMCDriver* DMCFactory::create(MCWalkerConfiguration& w, TrialWaveFunction& psi
, QMCHamiltonian& h, HamiltonianPool& hpool,WaveFunctionPool& ppool)
QMCDriver* DMCFactory::create(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h,
HamiltonianPool& hpool,WaveFunctionPool& ppool, Communicate* comm)
{
#ifdef QMC_CUDA
if (GPU)
return new DMCcuda (w, psi, h,ppool);
return new DMCcuda (w, psi, h, ppool, comm);
#endif
app_log() << "Creating DMCMP for the qmc driver" << std::endl;
QMCDriver* qmc = new DMCOMP(w,psi,h,ppool);
QMCDriver* qmc = new DMCOMP(w, psi, h, ppool, comm);
qmc->setUpdateMode(PbyPUpdate);
return qmc;
}
Expand Down
10 changes: 6 additions & 4 deletions src/QMCDrivers/DMC/DMCFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@

namespace qmcplusplus
{
struct DMCFactory
class DMCFactory
{
private:
bool PbyPUpdate, GPU;
xmlNodePtr myNode;

public:
DMCFactory(bool pbyp, bool gpu, xmlNodePtr cur) :
PbyPUpdate(pbyp), myNode(cur), GPU(gpu)
{ }
PbyPUpdate(pbyp), myNode(cur), GPU(gpu) { }

QMCDriver* create(MCWalkerConfiguration& w,
TrialWaveFunction& psi,
QMCHamiltonian& h, HamiltonianPool& hpool,WaveFunctionPool& ppool);
QMCHamiltonian& h, HamiltonianPool& hpool,WaveFunctionPool& ppool, Communicate* comm);
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/QMCDrivers/DMC/DMCOMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ namespace qmcplusplus
{

/// Constructor.
DMCOMP::DMCOMP(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h, WaveFunctionPool& ppool)
: QMCDriver(w,psi,h,ppool)
DMCOMP::DMCOMP(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h, WaveFunctionPool& ppool, Communicate* comm)
: QMCDriver(w,psi,h,ppool,comm)
, KillNodeCrossing(0) ,Reconfiguration("no"), BenchMarkRun("no")
, BranchInterval(-1),mover_MaxAge(-1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/QMCDrivers/DMC/DMCOMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DMCOMP: public QMCDriver, public CloneManager

/// Constructor.
DMCOMP(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h,
WaveFunctionPool& ppool);
WaveFunctionPool& ppool, Communicate* comm);

bool run();
bool put(xmlNodePtr cur);
Expand Down
4 changes: 2 additions & 2 deletions src/QMCDrivers/DMC/DMC_CUDA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ namespace qmcplusplus

/// Constructor.
DMCcuda::DMCcuda(MCWalkerConfiguration& w, TrialWaveFunction& psi,
QMCHamiltonian& h,WaveFunctionPool& ppool):
QMCDriver(w,psi,h,ppool), myWarmupSteps(0), Mover(0),
QMCHamiltonian& h,WaveFunctionPool& ppool, Communicate* comm):
QMCDriver(w,psi,h,ppool,comm), myWarmupSteps(0), Mover(0),
NLop(w.getTotalNum()),
ResizeTimer("DMCcuda::resize"),
DriftDiffuseTimer("DMCcuda::Drift_Diffuse"),
Expand Down
2 changes: 1 addition & 1 deletion src/QMCDrivers/DMC/DMC_CUDA.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DMCcuda: public QMCDriver
public:
/// Constructor.
GPU_XRAY_TRACE DMCcuda(MCWalkerConfiguration& w, TrialWaveFunction& psi,
QMCHamiltonian& h,WaveFunctionPool& ppool);
QMCHamiltonian& h,WaveFunctionPool& ppool, Communicate* comm);
GPU_XRAY_TRACE bool run();
GPU_XRAY_TRACE bool put(xmlNodePtr cur);
GPU_XRAY_TRACE void resetUpdateEngine();
Expand Down
11 changes: 5 additions & 6 deletions src/QMCDrivers/QMCCorrelatedSamplingLinearOptimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace qmcplusplus


QMCCorrelatedSamplingLinearOptimize::QMCCorrelatedSamplingLinearOptimize(MCWalkerConfiguration& w,
TrialWaveFunction& psi, QMCHamiltonian& h, HamiltonianPool& hpool, WaveFunctionPool& ppool): QMCLinearOptimize(w,psi,h,hpool,ppool),
TrialWaveFunction& psi, QMCHamiltonian& h, HamiltonianPool& hpool, WaveFunctionPool& ppool, Communicate* comm): QMCLinearOptimize(w,psi,h,hpool,ppool,comm),
exp0(-16), nstabilizers(3), stabilizerScale(2.0), bigChange(3), w_beta(0.0), MinMethod("quartic"), GEVtype("mixed")
{
IsQMCDriver=false;
Expand Down Expand Up @@ -340,24 +340,23 @@ QMCCorrelatedSamplingLinearOptimize::put(xmlNodePtr q)
if (vmcEngine ==0)
{
#if defined (QMC_CUDA)
vmcCSEngine = new VMCcuda(W,Psi,H,psiPool);
vmcCSEngine = new VMCcuda(W,Psi,H,psiPool,myComm);
vmcCSEngine->setOpt(true);
vmcEngine = vmcCSEngine;
#else
vmcEngine = vmcCSEngine = new VMCLinearOptOMP(W,Psi,H,hamPool,psiPool);
vmcEngine = vmcCSEngine = new VMCLinearOptOMP(W,Psi,H,hamPool,psiPool,myComm);
#endif
vmcEngine->setUpdateMode(vmcMove[0] == 'p');
vmcEngine->initCommunicator(myComm);
}
vmcEngine->setStatus(RootName,h5FileRoot,AppendRun);
vmcEngine->process(qsave);
bool success=true;
if (optTarget == 0)
{
#if defined (QMC_CUDA)
optTarget = new QMCCostFunctionCUDA(W,Psi,H);
optTarget = new QMCCostFunctionCUDA(W,Psi,H,myComm);
#else
optTarget = new QMCCostFunctionOMP(W,Psi,H);
optTarget = new QMCCostFunctionOMP(W,Psi,H,myComm);
#endif
optTarget->setneedGrads(false);
optTarget->setStream(&app_log());
Expand Down
2 changes: 1 addition & 1 deletion src/QMCDrivers/QMCCorrelatedSamplingLinearOptimize.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class QMCCorrelatedSamplingLinearOptimize: public QMCLinearOptimize, private NRC

///Constructor.
QMCCorrelatedSamplingLinearOptimize(MCWalkerConfiguration& w, TrialWaveFunction& psi,
QMCHamiltonian& h, HamiltonianPool& hpool, WaveFunctionPool& ppool);
QMCHamiltonian& h, HamiltonianPool& hpool, WaveFunctionPool& ppool, Communicate* comm);

///Destructor
~QMCCorrelatedSamplingLinearOptimize();
Expand Down
4 changes: 2 additions & 2 deletions src/QMCDrivers/QMCCostFunctionBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
namespace qmcplusplus
{

QMCCostFunctionBase::QMCCostFunctionBase(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h):
MPIObjectBase(0),
QMCCostFunctionBase::QMCCostFunctionBase(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h, Communicate* comm):
MPIObjectBase(comm),
W(w),H(h),Psi(psi), Write2OneXml(true),
PowerE(2), NumCostCalls(0), NumSamples(0), MaxWeight(1e6),
w_en(0.9), w_var(0.1), w_abs(0.0), w_w(0.0), w_beta(0.0), GEVType("mixed"),
Expand Down
2 changes: 1 addition & 1 deletion src/QMCDrivers/QMCCostFunctionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class QMCCostFunctionBase: public CostFunctionBase<QMCTraits::RealType>, public


///Constructor.
QMCCostFunctionBase(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h);
QMCCostFunctionBase(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h, Communicate* comm);

///Destructor
virtual ~QMCCostFunctionBase();
Expand Down
4 changes: 2 additions & 2 deletions src/QMCDrivers/QMCCostFunctionCUDA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace qmcplusplus

QMCCostFunctionCUDA::QMCCostFunctionCUDA
( MCWalkerConfiguration& w, TrialWaveFunction& psi,
QMCHamiltonian& h):
QMCCostFunctionBase(w,psi,h)
QMCHamiltonian& h, Communicate* comm):
QMCCostFunctionBase(w,psi,h,comm)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/QMCDrivers/QMCCostFunctionCUDA.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class QMCCostFunctionCUDA: public QMCCostFunctionBase, public CloneManager

///Constructor.
QMCCostFunctionCUDA( MCWalkerConfiguration& w, TrialWaveFunction& psi,
QMCHamiltonian& h);
QMCHamiltonian& h, Communicate* comm);

///Destructor
~QMCCostFunctionCUDA();
Expand Down
4 changes: 2 additions & 2 deletions src/QMCDrivers/QMCCostFunctionOMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ namespace qmcplusplus
{

QMCCostFunctionOMP::QMCCostFunctionOMP(MCWalkerConfiguration& w,
TrialWaveFunction& psi, QMCHamiltonian& h):
QMCCostFunctionBase(w,psi,h)
TrialWaveFunction& psi, QMCHamiltonian& h, Communicate* comm):
QMCCostFunctionBase(w,psi,h,comm)
{
CSWeight=1.0;
app_log()<<" Using QMCCostFunctionOMP::QMCCostFunctionOMP"<< std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/QMCDrivers/QMCCostFunctionOMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class QMCCostFunctionOMP: public QMCCostFunctionBase, public CloneManager

///Constructor.
QMCCostFunctionOMP(MCWalkerConfiguration& w, TrialWaveFunction& psi,
QMCHamiltonian& h);
QMCHamiltonian& h, Communicate* comm);

///Destructor
~QMCCostFunctionOMP();
Expand Down
4 changes: 2 additions & 2 deletions src/QMCDrivers/QMCDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ typedef int TraceManager;
namespace qmcplusplus
{

QMCDriver::QMCDriver(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h, WaveFunctionPool& ppool)
: MPIObjectBase(0), branchEngine(0), W(w), Psi(psi), H(h), psiPool(ppool),
QMCDriver::QMCDriver(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h, WaveFunctionPool& ppool, Communicate* comm)
: MPIObjectBase(comm), branchEngine(0), W(w), Psi(psi), H(h), psiPool(ppool),
Estimators(0),Traces(0), qmcNode(NULL), wOut(0)
{
ResetRandom=false;
Expand Down
2 changes: 1 addition & 1 deletion src/QMCDrivers/QMCDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class QMCDriver: public QMCTraits, public MPIObjectBase
xmlNodePtr traces_xml;

/// Constructor.
QMCDriver(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h, WaveFunctionPool& ppool);
QMCDriver(MCWalkerConfiguration& w, TrialWaveFunction& psi, QMCHamiltonian& h, WaveFunctionPool& ppool, Communicate* comm);

virtual ~QMCDriver();

Expand Down
Loading

0 comments on commit 4f6ccf2

Please sign in to comment.