LocalEnergyEstimator::LocalEnergyEstimator(QMCHamiltonian& h):Href(h) { 
   int hterms(h.size());
   SizeOfHamiltonians = hterms;
   FirstHamiltonian = h.startIndex();
   elocal.resize(SizeOfHamiltonians+LE_MAX);
   elocal_name.resize(SizeOfHamiltonians+LE_MAX);
   elocal_name[ENERGY_INDEX] = "LocalEnergy";
   elocal_name[ENERGY_SQ_INDEX] = "Variance";
   elocal_name[POTENTIAL_INDEX] = "LocalPotential";
   int ii(LE_MAX);
   for(int i=0; i < SizeOfHamiltonians; i++) elocal_name[ii++] = h.getName(i);
 }
Beispiel #2
0
  void HamiltonianPool::clone(const MCWalkerConfiguration& qp, const TrialWaveFunction& psi, const QMCHamiltonian& h,
      vector<MCWalkerConfiguration*>& plist, 
      vector<TrialWaveFunction*>& olist, 
      vector<QMCHamiltonian*>& hlist) 
  {
    int np=omp_get_max_threads();
    {
      ReportEngine PRE("HamiltonianPool","clone");
      app_log() << "Number of threads = " << np << endl;
    }

    //temporarily turnoff stream buffer for the clones
    OhmmsInfo::Log->turnoff();
    OhmmsInfo::Warn->turnoff();

    //clone ParticleSet and TrialWaveFunction
    WaveFunctionFactory* psiFac=psiPool->getWaveFunctionFactory(psi.getName());
    psiFac->setCloneSize(np);

    //capture cloned WaveFunctionFactory*
    vector<WaveFunctionFactory*> otemp;
    otemp.resize(np,0);

    //allocate the data on each thread
//#pragma omp parallel 
//    {
//      int ip=omp_get_thread_num();
//#pragma omp critical 
//      {
//        if(ip) {
//          char pname[16],oname[16];
//          sprintf(pname,"%s.c%i",qp.getName().c_str(),ip);
//          plist[ip]=new MCWalkerConfiguration(qp);
//          plist[ip]->setName(pname);
//
//          sprintf(oname,"%s.c%i",psi.getName().c_str(),ip);
//          otemp[ip]= psiFac->clone(plist[ip],ip,oname);
//        }
//      }
//    }
//    
//    //add the Clones to the pools
//    for(int ip=1; ip<np; ip++) 
//    {
//      ptclPool->addParticleSet(plist[ip]);
//      psiPool->addFactory(otemp[ip]);
//      olist[ip]=otemp[ip]->targetPsi;
//      if(ip%2==1) olist[ip]->reverse();
//    }
//
    
    //add the Clones to the pools
    for(int ip=1; ip<np; ++ip) 
    {
      plist[ip]=new MCWalkerConfiguration(qp);

      char oname[16];
      sprintf(oname,"%s.c%i",psi.getName().c_str(),ip);
      // Don't recreate with a factory anymore
      //otemp[ip]= psiFac->clone(plist[ip],ip,oname);
      //ptclPool->addParticleSet(plist[ip]);
      //psiPool->addFactory(otemp[ip]);
      //olist[ip]=otemp[ip]->targetPsi;

      // Just clone the TrialWaveFunction.
      ptclPool->addParticleSet(plist[ip]);
      olist[ip]=psiFac->targetPsi->makeClone(*plist[ip]);
      olist[ip]->setName(oname);

      //need to add a WaveFunctionFactory so that Hamiltonian can use them
      otemp[ip]=new WaveFunctionFactory(*psiFac);//make a shallow copy
      otemp[ip]->setPsi(olist[ip]);
      psiPool->addFactory(otemp[ip]);
    }

    //find the HamiltonianFactory* to be cloned
    HamiltonianFactory* hFac=0;
    PoolType::iterator hit(myPool.find(h.getName()));
    if(hit == myPool.end()) {
      hFac=(*(myPool.begin())).second;
    } else {
      hFac=(*hit).second;
    }
    hFac->setCloneSize(np);

    vector<HamiltonianFactory*> htemp;
    htemp.resize(np,0);

//#pragma omp parallel 
//    {
//      int ip=omp_get_thread_num();
//#pragma omp critical 
//      {
//        if(ip) {
//          char hname[16];
//          sprintf(hname,"%s.c%i",h.getName().c_str(),ip);
//          htemp[ip]= hFac->clone(plist[ip],olist[ip],ip,hname);
//        }
//      }
//    }
//
//    for(int ip=1; ip<np; ip++) 
//    {
//      myPool[htemp[ip]->getName()]=htemp[ip];
//      hlist[ip]=htemp[ip]->targetH;
//    }

    for(int ip=1; ip<np; ip++) 
    {
      char hname[16];
      sprintf(hname,"%s.c%i",h.getName().c_str(),ip);
      htemp[ip]= hFac->clone(plist[ip],olist[ip],ip,hname);
      myPool[htemp[ip]->getName()]=htemp[ip];
      hlist[ip]=htemp[ip]->targetH;
    }

    //restore stream buffer to the original state
    OhmmsInfo::Log->reset();
    OhmmsInfo::Warn->reset();

  }