Example #1
0
int
atf_process_child_stderr(atf_process_child_t *c)
{
    PRE(c->m_stderr != -1);
    return c->m_stderr;
}
Example #2
0
/// Checks whether the option has a default value for its argument.
///
/// \pre needs_arg() must be true.
///
/// \return True if the option has a default value, false otherwise.
bool
cmdline::base_option::has_default_value(void) const
{
    PRE(needs_arg());
    return _has_default_value;
}
Example #3
0
  bool RPAJastrow::put(xmlNodePtr cur){
    ReportEngine PRE("RPAJastrow","put");
    xmlNodePtr myNode=xmlCopyNode(cur,1);

    //capture attribute jastrow/@name
    MyName="RPA_Jee";
    string useL="yes";
    string useS="yes";
    rpafunc="RPA";
    
    OhmmsAttributeSet a;
    a.add(MyName,"name");
    a.add(useL,"longrange");
    a.add(useS,"shortrange");
    a.add(rpafunc,"function");
    a.put(cur);

    Rs=-1.0;
    Kc=-1.0;
    string ID_Rs="RPA_rs";
    ParameterSet params;
    params.add(Rs,"rs","double");
    params.add(Kc,"kc","double");
    params.put(cur);
    buildOrbital(MyName, useL, useS, rpafunc, Rs, Kc);

//     app_log() <<endl<<"   LongRangeForm is "<<rpafunc<<endl;
// 
//     DropLongRange = (useL == "no");
//     DropShortRange = (useS=="no");
// 
//     app_log() << "    Rs can be optimized using ID=" << ID_Rs << endl;
//     RealType tlen = std::pow(3.0/4.0/M_PI*targetPtcl.Lattice.Volume/ static_cast<RealType>(targetPtcl.getTotalNum()) ,1.0/3.0);
//     
//     if(Rs<0) {
//       if(targetPtcl.Lattice.SuperCellEnum) {
//         Rs=tlen;
//       } else {
//         cout<<"  Error finding rs. Is this an open system?!"<<endl;
//         Rs=100.0;
//       }
//     }
//     
//     //Add Rs to optimizable list
//     myVars.insert(ID_Rs,Rs,true);
//     
//     int indx = targetPtcl.SK->KLists.ksq.size()-1;
//     double Kc_max=std::pow(targetPtcl.SK->KLists.ksq[indx],0.5);
// 
//     if(Kc<0){ 
//       Kc = 2.0*  std::pow(2.25*M_PI,1.0/3.0)/tlen ;
//     }
//     
//     if(Kc>Kc_max){
//       Kc=Kc_max;
//       app_log() << "    Kc set too high. Resetting to the maximum value"<<endl;
//     }
// 
//     app_log() << "    RPAJastrowBuilder::addTwoBodyPart Rs = " << Rs <<  "  Kc= " << Kc << endl;
//     
//     if (rpafunc=="Yukawa" || rpafunc=="breakup"){
//       myHandler= new LRHandlerTemp<YukawaBreakup<RealType>,LPQHIBasis>(targetPtcl,Kc);
//     } else if (rpafunc=="RPA"){
//       myHandler= new LRRPAHandlerTemp<RPABreakup<RealType>,LPQHIBasis>(targetPtcl,Kc);
//     } else if (rpafunc=="dYukawa"){
//       myHandler= new LRHandlerTemp<DerivYukawaBreakup<RealType>,LPQHIBasis >(targetPtcl,Kc);
//     } else if (rpafunc=="dRPA"){
//       myHandler= new LRRPAHandlerTemp<DerivRPABreakup<RealType>,LPQHIBasis >(targetPtcl,Kc);
//     }
//     
//     
//     myHandler->Breakup(targetPtcl,Rs);
//     
//     app_log() << "  Maximum K shell " << myHandler->MaxKshell << endl;
//     app_log() << "  Number of k vectors " << myHandler->Fk.size() << endl;
// 
//     if(!DropLongRange) makeLongRange();
//     if(!DropShortRange) makeShortRange();

    return true;
  }
  bool eeI_JastrowBuilder::put(xmlNodePtr cur)
  {
    ReportEngine PRE(ClassName,"put(xmlNodePtr)");

    bool PrintTables=true;
    xmlNodePtr kids = cur->xmlChildrenNode;
    typedef BsplineFunctor3D FuncType;

    // Create a three-body Jastrow
    if (sourcePtcl) {
//       cerr << "sourcePtcl = " << sourcePtcl << endl;
      string ftype("Bspline");
      OhmmsAttributeSet tAttrib;
      tAttrib.add(ftype,"function");
      tAttrib.put (cur);

      SpeciesSet &iSet = sourcePtcl->getSpeciesSet();
      SpeciesSet &eSet = targetPtcl.getSpeciesSet();
      int numiSpecies = iSet.getTotalNum();

      if (ftype == "Bspline") {
      	typedef eeI_JastrowOrbital<BsplineFunctor3D> J3Type;
	J3Type &J3 = *(new J3Type(*sourcePtcl, targetPtcl, true));
	putkids (kids, J3);
      }
      else if (ftype == "polynomial") {
      	typedef eeI_JastrowOrbital<PolynomialFunctor3D> J3Type;
	J3Type &J3 = *(new J3Type(*sourcePtcl, targetPtcl, true));
	putkids (kids, J3);
      }
      else {
	app_error() << "Unknown function \"" << ftype << "\" in"
		    << " eeI_JastrowBuilder.  Aborting.\n";
	abort();
      }
      // 	// Find the number of the source species
      // 	bool success=false;
      // 	while (kids != NULL) {
      // 	  std::string kidsname = (char*)kids->name;	 
      // 	  if (kidsname == "correlation") {
      // 	    RealType ee_cusp=0.0;
      // 	    RealType eI_cusp=0.0;
      // 	    string iSpecies, eSpecies1("u"), eSpecies2("u");
      // 	    OhmmsAttributeSet rAttrib;
      // 	    rAttrib.add(iSpecies,"ispecies");
      // 	    rAttrib.add(eSpecies1,"especies1");
      // 	    rAttrib.add(eSpecies2,"especies2");
      // 	    rAttrib.add(ee_cusp,"ecusp");
      // 	    rAttrib.add(eI_cusp,"icusp");
      // 	    rAttrib.put(kids);
	    
      // 	    BsplineFunctor3D *functor = new BsplineFunctor3D(ee_cusp, eI_cusp);
	    
      // 	    functor->iSpecies = iSpecies;
      // 	    functor->eSpecies1 = eSpecies1;
      // 	    functor->eSpecies2 = eSpecies2;
      // 	    int iNum = iSet.findSpecies (iSpecies);
      // 	    int eNum1 = eSet.findSpecies (eSpecies1);
      // 	    int eNum2 = eSet.findSpecies (eSpecies2);
	    
      // 	    functor->put (kids);
      // 	    strstream aname;
      // 	    aname << iSpecies << "_" << eSpecies1 << "_" << eSpecies2;
      // 	    J3->addFunc(aname.str(), iNum, eNum1, eNum2, functor);
      // 	  }
      // 	  kids = kids->next;
      // 	}
      // 	targetPsi.addOrbital(J3,"eeI_bspline");
      // 	J3->setOptimizable(true);
      // }
    }
    else 
      app_error() << "You must specify the \"source\" particleset for a three-body Jastrow.\n";
    
    return true;
    
    //   // Find the number of the source species
    //   SpeciesSet &sSet = sourcePtcl->getSpeciesSet();
    //   int numSpecies = sSet.getTotalNum();
    //   bool success=false;
    //   while (kids != NULL) 
    //   {
    // 	std::string kidsname = (char*)kids->name;
    // 	if (kidsname == "correlation") 
    //     {
    //       RealType cusp=0.0;
    //       string elementType;
    //       OhmmsAttributeSet rAttrib;
    //       rAttrib.add(elementType,"elementType");
    //       rAttrib.add(cusp,"cusp");
    //       rAttrib.put(kids);                          

    // 	  BsplineFunctor<double> *functor = new BsplineFunctor<double>(cusp);
    // 	  functor->elementType = elementType;
    // 	  int ig = sSet.findSpecies (elementType);
    // 	  if (ig < numSpecies) 
    //       {//ignore
    //         functor->put (kids);
    // 	    if (functor->cutoff_radius < 1.0e-6) {
    // 	      app_log()  << "  BsplineFunction rcut is currently zero.\n"
    // 			 << "  Setting to Wigner-Seitz radius = " 
    // 			 << sourcePtcl->Lattice.WignerSeitzRadius << endl;
    // 	      functor->cutoff_radius = sourcePtcl->Lattice.WignerSeitzRadius;
    // 	      functor->reset();
    // 	    }
    //         J1->addFunc (ig,functor);
    // 	    success = true;
    //         dJ1->addFunc(ig,functor);
    //         if(ReportLevel) 
    //         {
    //           string fname="J1."+elementType+".dat";
    //           ofstream fout(fname.c_str());
    //           fout.setf(ios::scientific, ios::floatfield);
    //           fout << "# One-body Jastrow generated by BsplineJastrowBuilder" << endl;
    //           functor->print(fout);
    //         }
    //       }
    // 	}
    // 	kids = kids->next;
    //   }

    //   if(success)
    //   {
    //     //assign derivatives to J1
    //     //dJ1->initialize();
    //     //J1->setDiffOrbital(dJ1);
    //     J1->dPsi=dJ1;

    //     targetPsi.addOrbital(J1,"J1_bspline");
    //     J1->setOptimizable(true);
    //   }
    //   else
    //   {
    //     PRE.warning("eeI_JastrowBuilder failed to add an One-Body Jastrow.");
    //     delete J1;
    //     delete dJ1;
    //   }
    // } 
    // // Create a two-body Jastrow
    // else 
    // {
    //   typedef TwoBodyJastrowOrbital<BsplineFunctor<RealType> > J2Type;
    //   typedef DiffTwoBodyJastrowOrbital<BsplineFunctor<RealType> > dJ2Type;

    //   J2Type *J2 = new J2Type(targetPtcl,targetPsi.is_manager());
    //   dJ2Type *dJ2 = new dJ2Type(targetPtcl);

    //   SpeciesSet& species(targetPtcl.getSpeciesSet());
    //   RealType q=species(0,species.addAttribute("charge"));

    //   //std::map<std::string,RadFuncType*> functorMap;
    //   while (kids != NULL) 
    //   {
    // 	std::string kidsname((const char*)kids->name);
    // 	if (kidsname == "correlation") 
    //     {
    //       OhmmsAttributeSet rAttrib;
    //       RealType cusp=-1e10;
    //       string pairType("0");
    //       string spA(species.speciesName[0]);
    //       string spB(species.speciesName[0]);
    //       rAttrib.add(spA,"speciesA");
    //       rAttrib.add(spB,"speciesB");
    //       rAttrib.add(pairType,"pairType");
    //       rAttrib.add(cusp,"cusp");
    //       rAttrib.put(kids);
    //       if(pairType[0]=='0')
    //       {
    //         pairType=spA+spB;
    //       }
    //       else
    //       {
    //         PRE.warning("pairType is deprecated. Use speciesA/speciesB");
    //         //overwrite the species
    //         spA=pairType[0]; spB=pairType[1];
    //       }

    //       int ia = species.findSpecies(spA);
    //       int ib = species.findSpecies(spB);
    //       if(ia==species.size() || ib == species.size())
    //       {
    //         PRE.error("Failed. Species are incorrect.",true);
    //       }

    //       if(cusp<-1e6)
    //       { 
    //         if(ia==ib) 
    //           cusp=-0.25*q*q;
    //         else 
    //           cusp=-0.5*q*q;
    //       }

    //       app_log() << "  eeI_JastrowBuilder adds a functor with cusp = " << cusp << endl;

    // 	  RadFuncType *functor = new RadFuncType(cusp);
    // 	  functor->put (kids);
    // 	  functor->elementType=pairType;
    // 	  if (functor->cutoff_radius < 1.0e-6) {
    // 	    app_log()  << "  BsplineFunction rcut is currently zero.\n"
    // 		       << "  Setting to Wigner-Seitz radius = " 
    // 	    	       << targetPtcl.Lattice.WignerSeitzRadius << endl;
    // 	     functor->cutoff_radius = targetPtcl.Lattice.WignerSeitzRadius;
    // 	     functor->reset();
    // 	  }

    //       J2->addFunc(pairType,ia,ib,functor);
    //       dJ2->addFunc(pairType,ia,ib,functor);

    //       if(ReportLevel) 
    //       {
    //         string fname="J2."+pairType+".dat";
    //         ofstream fout(fname.c_str());
    //         fout.setf(ios::scientific, ios::floatfield);
    //         fout << "# Two-body Jastrow generated by eeI_JastrowBuilder" << endl;
    //         functor->print(fout);
    //       }
    // 	}
    // 	kids = kids->next;
    //   }
    //   //dJ2->initialize();
    //   //J2->setDiffOrbital(dJ2);
    //   J2->dPsi=dJ2;
    //   targetPsi.addOrbital(J2,"J2_bspline");
    //   J2->setOptimizable(true);
    // }
    // return true;
  }
Example #5
0
  void RNDMCOMP::resetUpdateEngines() 
  {

    ReportEngine PRE("RNDMCOMP","resetUpdateEngines");
 
    Timer init_timer;

    makeClones(W,Psi,H);

    if(Movers.empty()) 
    {
      //load walkers
      W.loadEnsemble();
      for(int ip=1;ip<NumThreads;++ip) wClones[ip]->loadEnsemble(W);

      if (useAlternate=="yes")
        branchEngine->initWalkerController(W,false,false);
        //branchEngine->initWalkerController(W,Tau,false,false);
      else
        branchEngine->initWalkerController(W,false,true);
        //branchEngine->initWalkerController(W,Tau,false,true);
      branchEngine->setRN(true);

      //if(QMCDriverMode[QMC_UPDATE_MODE]) W.clearAuxDataSet();
      Movers.resize(NumThreads,0);
      branchClones.resize(NumThreads,0);
      Rng.resize(NumThreads,0);
      estimatorClones.resize(NumThreads,0);
      FairDivideLow(W.getActiveWalkers(),NumThreads,wPerNode);
      bool klw=(KillWalker=="yes");

      {//log file
        ostringstream o;
        o << "  Initial partition of walkers on a node: ";
        std::copy(wPerNode.begin(),wPerNode.end(),ostream_iterator<int>(o," "));
        o << "\n";
        o << "Killing Walkers at nodes " << (useAlternate!="yes") <<endl;

        o << "Running the released node driver."<<endl;

        app_log() << o.str();
      }

#pragma omp parallel for
      for(int ip=0; ip<NumThreads; ++ip)
      {
        estimatorClones[ip]= new EstimatorManager(*Estimators);
        estimatorClones[ip]->setCollectionMode(false);

        Rng[ip]=new RandomGenerator_t(*RandomNumberControl::Children[ip]);
        hClones[ip]->setRandomGenerator(Rng[ip]);

        branchClones[ip] = new BranchEngineType(*branchEngine);
//         Movers[ip] = new RNDMCUpdatePbyPWithRejectionFast(*wClones[ip],*psiClones[ip],*hClones[ip],*Rng[ip]); 
        
        if (useAlternate=="yes")
          Movers[ip] = new RNDMCUpdatePbyPAlternate(*wClones[ip],*psiClones[ip],*hClones[ip],*Rng[ip]);  
        else
          Movers[ip] = new RNDMCUpdatePbyPCeperley(*wClones[ip],*psiClones[ip],*hClones[ip],*Rng[ip]); 
        Movers[ip]->put(qmcNode);
        Movers[ip]->resetRun(branchClones[ip],estimatorClones[ip]);   
        MCWalkerConfiguration::iterator wit(W.begin()+wPerNode[ip]), wit_end(W.begin()+wPerNode[ip+1]);
          Movers[ip]->initWalkersForPbyP(wit, wit_end);
        }
      } 
//     branchEngine->checkParameters(W);
    if(BranchInterval<0) BranchInterval=1;
    {
      ostringstream o;
      if (useAlternate=="yes") o << "  Using Alternate Mover"<<endl;
      else o << "  Using Ceperley Mover"<<endl;
      o << "  BranchInterval = " << BranchInterval << "\n";
      o << "  Steps per block = " << nSteps << "\n";
      o << "  Number of blocks = " << nBlocks << "\n";
      app_log() << endl << o.str() << endl;
    }
        
    app_log() << " RNDMC Engine Initialization = " << init_timer.elapsed() << " secs " << endl;
  }
Example #6
0
/// Constructor that sets up the signal handlers.
signals::interrupts_handler::interrupts_handler(void)
{
    PRE(!interrupts_handler_active);
    setup_handlers();
    interrupts_handler_active = true;
}
Example #7
0
impl::file_handle::file_handle(handle_type h) :
    m_handle(h)
{
    PRE(m_handle != invalid_value());
}
  bool PadeJastrowBuilder::put(xmlNodePtr cur) 
  {

    ReportEngine PRE(ClassName,"put()");

    string sourceOpt=targetPtcl.getName();
    string jname="PadeJastrow";
    string spin="no";
    string id_b="jee_b";
    RealType pade_b=1.0;
    OhmmsAttributeSet pattrib;
    pattrib.add(jname,"name");
    pattrib.add(spin,"spin");
    pattrib.add(sourceOpt,"source");
    pattrib.put(cur);

    cur=cur->children;
    while(cur != NULL)
    {
      {//just to hide this
        string pname="0";
        OhmmsAttributeSet aa;
        aa.add(pname,"name");
        aa.add(id_b,"id");
        aa.put(cur);
        if(pname[0]=='B') putContent(pade_b,cur);
      }

      xmlNodePtr cur1=cur->children;
      while(cur1!= NULL)
      {
        string pname="0";
        OhmmsAttributeSet aa;
        aa.add(pname,"name");
        aa.add(id_b,"id");
        aa.put(cur1);
        if(pname[0]=='B') putContent(pade_b,cur1);
        cur1=cur1->next;
      }
      cur=cur->next;
    }

    app_log() << "PadeJastrowBuilder " << id_b << " = " << pade_b << endl;

    typedef PadeFunctor<RealType> FuncType;

    typedef TwoBodyJastrowOrbital<FuncType> JeeType;
    JeeType *J2 = new JeeType(targetPtcl);

    SpeciesSet& species(targetPtcl.getSpeciesSet());
    RealType q=species(0,species.addAttribute("charge"));

    if(spin == "no") 
    {
      RealType cusp=-0.5*q*q;
      FuncType *func=new FuncType(cusp,pade_b);
      func->setIDs("jee_cusp",id_b);//set the ID's

      J2->addFunc("pade_uu",0,0,func);

      //DerivFuncType *dfunc=new DerivFuncType(cusp,B);
      //dJ2->addFunc("pade_uu",0,0,dfunc);
      //dFuncList.push_back(dfunc);
      app_log() << "    Adding Spin-independent Pade Two-Body Jastrow Cusp " << cusp<< "\n";
    } 
    else 
    {
      //build uu functor
      RealType cusp_uu=-0.25*q*q;
      FuncType *funcUU=new FuncType(cusp_uu,pade_b);
      funcUU->setIDs("pade_uu",id_b);//set the ID's

      //build ud functor
      RealType cusp_ud=-0.5*q*q;
      FuncType *funcUD=new FuncType(cusp_ud,pade_b);
      funcUD->setIDs("pade_ud",id_b);//set the ID's

      J2->addFunc("pade_uu",0,0,funcUU);

      //DerivFuncType *dfuncUU=new DerivFuncType(cusp_uu,B);
      //DerivFuncType *dfuncUD=new DerivFuncType(cusp_ud,B);
      //dJ2->addFunc("pade_uu",0,0,dfuncUU);
      //dJ2->addFunc("pade_ud",0,1,dfuncUD);
      app_log() << "    Adding Spin-dependent Pade Two-Body Jastrow " << "\n";
      app_log() << "      parallel spin     " << cusp_uu << "\n";
      app_log() << "      antiparallel spin " << cusp_ud << "\n";
    }

    targetPsi.addOrbital(J2,"J2_pade");

    if(sourceOpt != targetPtcl.getName())
    {
      map<string,ParticleSet*>::iterator pa_it(ptclPool.find(sourceOpt));
      if(pa_it == ptclPool.end()) 
      {
        PRE.warning("PadeJastrowBuilder::put failed. "+sourceOpt+" does not exist.");
        return true;
      }
      ParticleSet& sourcePtcl= (*(*pa_it).second);

      app_log() << "  PadeBuilder::Adding Pade One-Body Jastrow with effective ionic charges." << endl;
      typedef OneBodyJastrowOrbital<FuncType> JneType;
      JneType* J1 = new JneType(sourcePtcl,targetPtcl);

      //typedef OneBodyJastrowOrbital<DerivFuncType> DerivJneType;
      //DerivJneType* dJ1=new DerivJneType(sourcePtcl,targetPtcl);

      SpeciesSet& Species(sourcePtcl.getSpeciesSet());
      int ng=Species.getTotalNum();
      int icharge = Species.addAttribute("charge");
      for(int ig=0; ig<ng; ++ig) 
      {
        RealType zeff=Species(icharge,ig);
        ostringstream j1id;
        j1id<<"pade_"<<Species.speciesName[ig];

        RealType sc=std::pow(2*zeff,0.25);
        FuncType *func=new FuncType(-zeff,pade_b,sc);
        func->setIDs(j1id.str(),id_b);

        J1->addFunc(ig,func);

        //DerivFuncType *dfunc=new DerivFuncType(-zeff,B,sc);
        //dJ1->addFunc(ig,dfunc);
        //dFuncList.push_back(dfunc);

        app_log() << "    " << Species.speciesName[ig] <<  " Zeff = " << zeff << " B= " << pade_b*sc << endl;
      }
      targetPsi.addOrbital(J1,"J1_pade");
    }
    return true;
  }
Example #9
0
  int SlaterDetBuilder::putDeterminant(xmlNodePtr cur, int firstIndex) {

    ReportEngine PRE(ClassName,"putDeterminant(xmlNodePtr,int)");

    string basisName("invalid");
    string detname("0"), refname("0");
    OhmmsAttributeSet aAttrib;
    aAttrib.add(basisName,basisset_tag);
    aAttrib.add(detname,"id");
    aAttrib.add(refname,"ref");
    aAttrib.put(cur);

    //index of the last SlaterDeterminant
    int dIndex=DetSet.size();
    if(refname[0] == '0') { //create one and use detname
      if(detname[0] =='0') { //no id is given, assign one
        char newname[8];
        sprintf(newname,"det%d",dIndex);
        detname=newname;
        //add attributed id and ref
        xmlNewProp(cur,(const xmlChar*)"id",(const xmlChar*)newname);
        xmlNewProp(cur,(const xmlChar*)"ref",(const xmlChar*)newname);
      }
      else
      {
        //add reference name
        xmlNewProp(cur,(const xmlChar*)"ref",(const xmlChar*)detname.c_str());
      }
    }

    map<string,SPOSetBasePtr>::iterator lit(SPOSet.find(detname));
    Det_t* adet=0;
    SPOSetBasePtr psi;
    if(lit == SPOSet.end()) {
#if defined(ENABLE_SMARTPOINTER)
      psi.reset(myBasisSetFactory->createSPOSet(cur)); 
#else
      psi = myBasisSetFactory->createSPOSet(cur); 
#endif
      psi->put(cur);
      psi->checkObject();
      SPOSet[detname]=psi;
    } else {
      psi = (*lit).second;
    }

    if(psi->getOrbitalSetSize()) {
      map<string,Det_t*>::iterator dit(DetSet.find(detname));
      if(dit == DetSet.end()) {
        adet = new Det_t(psi,firstIndex);
        adet->set(firstIndex,psi->getOrbitalSetSize());
        DetSet[detname]=adet;
      } else {
        adet = (*dit).second;
      }
      firstIndex += psi->getOrbitalSetSize();
    }

    //only if a determinant is not 0
    if(adet) SlaterDetSet.back()->add(adet);

    return firstIndex;
  }
void EinsplineSetBuilder::ReadBands_ESHDF(int spin, EinsplineSetExtended<complex<double > >* orbitalSet)
{
  update_token(__FILE__,__LINE__,"ReadBands_ESHDF:complex");
  ReportEngine PRE("EinsplineSetBuilder","ReadBands_ESHDF(EinsplineSetExtended<complex<double > >*");
  Timer c_prep, c_unpack,c_fft, c_phase, c_spline, c_newphase, c_h5, c_init;
  double t_prep=0.0, t_unpack=0.0, t_fft=0.0, t_phase=0.0, t_spline=0.0, t_newphase=0.0, t_h5=0.0, t_init=0.0;
  c_prep.restart();
  bool root = myComm->rank()==0;
  vector<BandInfo>& SortBands(*FullBands[spin]);
  // bcast other stuff
  myComm->bcast (NumDistinctOrbitals);
  myComm->bcast (NumValenceOrbs);
  myComm->bcast (NumCoreOrbs);
  int N = NumDistinctOrbitals;
  orbitalSet->kPoints.resize(N);
  orbitalSet->MakeTwoCopies.resize(N);
  orbitalSet->StorageValueVector.resize(N);
  orbitalSet->BlendValueVector.resize(N);
  orbitalSet->StorageLaplVector.resize(N);
  orbitalSet->BlendLaplVector.resize(N);
  orbitalSet->StorageGradVector.resize(N);
  orbitalSet->BlendGradVector.resize(N);
  orbitalSet->StorageHessVector.resize(N);
  orbitalSet->StorageGradHessVector.resize(N);
  orbitalSet->phase.resize(N);
  orbitalSet->eikr.resize(N);
  orbitalSet->NumValenceOrbs = NumValenceOrbs;
  orbitalSet->NumCoreOrbs    = NumCoreOrbs;
  // Read in k-points
  int numOrbs = orbitalSet->getOrbitalSetSize();
  int num = 0;
  if (root)
  {
    for (int iorb=0; iorb<N; iorb++)
    {
      int ti = SortBands[iorb].TwistIndex;
      PosType twist  = TwistAngles[ti];
      orbitalSet->kPoints[iorb] = orbitalSet->PrimLattice.k_cart(twist);
      orbitalSet->MakeTwoCopies[iorb] =
        (num < (numOrbs-1)) && SortBands[iorb].MakeTwoCopies;
      num += orbitalSet->MakeTwoCopies[iorb] ? 2 : 1;
    }
  }
  myComm->bcast(orbitalSet->kPoints);
  myComm->bcast(orbitalSet->MakeTwoCopies);
  // First, check to see if we have already read this in
  H5OrbSet set(H5FileName, spin, N);
  ///check mesh or ready for FFT grid
  bool havePsig=ReadGvectors_ESHDF();
  app_log() << "MeshSize = (" << MeshSize[0] << ", " << MeshSize[1] << ", " << MeshSize[2] << ")\n";
  int nx, ny, nz, bi, ti;
  nx=MeshSize[0];
  ny=MeshSize[1];
  nz=MeshSize[2];
  Ugrid x_grid, y_grid, z_grid;
  BCtype_z xBC, yBC, zBC;
  xBC.lCode = PERIODIC;
  xBC.rCode = PERIODIC;
  yBC.lCode = PERIODIC;
  yBC.rCode = PERIODIC;
  zBC.lCode = PERIODIC;
  zBC.rCode = PERIODIC;
  x_grid.start = 0.0;
  x_grid.end = 1.0;
  x_grid.num = nx;
  y_grid.start = 0.0;
  y_grid.end = 1.0;
  y_grid.num = ny;
  z_grid.start = 0.0;
  z_grid.end = 1.0;
  z_grid.num = nz;
  // Create the multiUBspline object
  orbitalSet->MultiSpline =
    create_multi_UBspline_3d_z (x_grid, y_grid, z_grid, xBC, yBC, zBC, NumValenceOrbs);
  //////////////////////////////////////
  // Create the MuffinTin APW splines //
  //////////////////////////////////////
  orbitalSet->MuffinTins.resize(NumMuffinTins);
  for (int tin=0; tin<NumMuffinTins; tin++)
  {
    orbitalSet->MuffinTins[tin].Atom = tin;
    orbitalSet->MuffinTins[tin].set_center (MT_centers[tin]);
    orbitalSet->MuffinTins[tin].set_lattice(Lattice);
    orbitalSet->MuffinTins[tin].init_APW
    (MT_APW_rgrids[tin], MT_APW_lmax[tin],
     NumValenceOrbs);
  }
  for (int iat=0; iat<AtomicOrbitals.size(); iat++)
  {
    AtomicOrbitals[iat].set_num_bands(NumValenceOrbs);
    AtomicOrbitals[iat].allocate();
  }
  int isComplex=1;
  if (root)
  {
    HDFAttribIO<int> h_isComplex(isComplex);
    h_isComplex.read(H5FileID, "/electrons/psi_r_is_complex");
  }
  myComm->bcast(isComplex);
  if (!isComplex)
  {
    APP_ABORT("Expected complex orbitals in ES-HDF file, but found real ones.");
  }
  EinsplineSetBuilder::RotateBands_ESHDF(spin, orbitalSet);
  bool isCore = bcastSortBands(spin,N,root);
  if(isCore)
  {
    APP_ABORT("Core states not supported by ES-HDF yet.");
  }
  t_prep += c_prep.elapsed();
  /** For valence orbitals,
   * - extended orbitals either in G or in R
   * - localized orbitals
   */
  //this can potentially break
  Array<ComplexType,3> splineData(nx,ny,nz);
  if(havePsig)//perform FFT using FFTW
  {
    c_init.restart();
    Array<ComplexType,3> FFTbox;
    FFTbox.resize(MeshSize[0], MeshSize[1], MeshSize[2]);
    fftw_plan FFTplan = fftw_plan_dft_3d
                        (MeshSize[0], MeshSize[1], MeshSize[2],
                         reinterpret_cast<fftw_complex*>(FFTbox.data()),
                         reinterpret_cast<fftw_complex*>(FFTbox.data()),
                         +1, FFTW_ESTIMATE);
    Vector<complex<double> > cG(MaxNumGvecs);
    //this will be parallelized with OpenMP
    for(int iorb=0,ival=0; iorb<N; ++iorb, ++ival)
    {
      //Vector<complex<double> > cG;
      int ncg=0;
      int ti=SortBands[iorb].TwistIndex;
      c_h5.restart();
      if(root)
      {
        ostringstream path;
        path << "/electrons/kpoint_" << SortBands[iorb].TwistIndex
             << "/spin_" << spin << "/state_" << SortBands[iorb].BandIndex << "/psi_g";
        HDFAttribIO<Vector<complex<double> > >  h_cG(cG);
        h_cG.read (H5FileID, path.str().c_str());
        ncg=cG.size();
      }
      myComm->bcast(ncg);
      if(ncg != Gvecs[0].size())
      {
        APP_ABORT("Failed : ncg != Gvecs[0].size()");
      }
      if(!root)
        cG.resize(ncg);
      myComm->bcast(cG);
      t_h5 += c_h5.elapsed();
      c_unpack.restart();
      unpack4fftw(cG,Gvecs[0],MeshSize,FFTbox);
      t_unpack+= c_unpack.elapsed();
      c_fft.restart();
      fftw_execute (FFTplan);
      t_fft+= c_fft.elapsed();
      c_phase.restart();
      fix_phase_rotate_c2c(FFTbox,splineData,TwistAngles[ti]);
      t_phase+= c_phase.elapsed();
      c_spline.restart();
      set_multi_UBspline_3d_z(orbitalSet->MultiSpline, ival, splineData.data());
      t_spline+= c_spline.elapsed();
    }
    fftw_destroy_plan(FFTplan);
    t_init+=c_init.elapsed();
  }
  else
  {
    //this will be parallelized with OpenMP
    for(int iorb=0,ival=0; iorb<N; ++iorb, ++ival)
    {
      //check dimension
      if(root)
      {
        ostringstream path;
        path << "/electrons/kpoint_" << SortBands[iorb].TwistIndex
             << "/spin_" << spin << "/state_" << SortBands[iorb].BandIndex << "/psi_r";
        HDFAttribIO<Array<complex<double>,3> >  h_splineData(splineData);
        h_splineData.read(H5FileID, path.str().c_str());
      }
      myComm->bcast(splineData);
      set_multi_UBspline_3d_z(orbitalSet->MultiSpline, ival, splineData.data());
    }
    //return true;
  }
  app_log() << "    READBANDS::PREP   = " << t_prep << endl;
  app_log() << "    READBANDS::H5     = " << t_h5 << endl;
  app_log() << "    READBANDS::UNPACK = " << t_unpack << endl;
  app_log() << "    READBANDS::FFT    = " << t_fft << endl;
  app_log() << "    READBANDS::PHASE  = " << t_phase << endl;
  app_log() << "    READBANDS::SPLINE = " << t_spline << endl;
  app_log() << "    READBANDS::SUM    = " << t_init << endl;
  //now localized orbitals
  for(int iorb=0,ival=0; iorb<N; ++iorb, ++ival)
  {
    PosType twist=TwistAngles[SortBands[iorb].TwistIndex];
    // Read atomic orbital information
    for (int iat=0; iat<AtomicOrbitals.size(); iat++)
    {
      app_log() << "Reading orbital " << iat << " for band " << ival << endl;
      AtomicOrbital<complex<double> > &orb = AtomicOrbitals[iat];
      Array<complex<double>,2> radial_spline(orb.SplinePoints,orb.Numlm),
            poly_coefs(orb.PolyOrder+1,orb.Numlm);
      if (root)
      {
        int ti   = SortBands[iorb].TwistIndex;
        int bi   = SortBands[iorb].BandIndex;
        ostringstream path;
        path << "/electrons/kpoint_" << ti << "/spin_" << spin << "/state_" << bi << "/";
        AtomicOrbital<complex<double> > &orb = AtomicOrbitals[iat];
        ostringstream spline_path, poly_path;
        spline_path << path.str() << "radial_spline_" << iat;
        poly_path   << path.str() << "poly_coefs_"    << iat;
        HDFAttribIO<Array<complex<double>,2> > h_radial_spline(radial_spline);
        HDFAttribIO<Array<complex<double>,2> > h_poly_coefs(poly_coefs);
        h_radial_spline.read(H5FileID, spline_path.str().c_str());
        h_poly_coefs.read   (H5FileID, poly_path.str().c_str());
        // cerr << "radial_spline.size = (" << radial_spline.size(0)
        // 	 << ", " << radial_spline.size(1) << ")\n";
        // cerr << "poly_coefs.size = (" << poly_coefs.size(0)
        // 	 << ", " << poly_coefs.size(1) << ")\n";
      }
      myComm->bcast(radial_spline);
      myComm->bcast(poly_coefs);
      AtomicOrbitals[iat].set_band (ival, radial_spline, poly_coefs, twist);
    }
    // Now read muffin tin data
    for (int tin=0; tin<NumMuffinTins; tin++)
    {
      // app_log() << "Reading data for muffin tin " << tin << endl;
      PosType twist, k;
      int lmax = MT_APW_lmax[tin];
      int numYlm = (lmax+1)*(lmax+1);
      Array<complex<double>,2>
      u_lm_r(numYlm, MT_APW_num_radial_points[tin]);
      Array<complex<double>,1> du_lm_dr (numYlm);
      if (root)
      {
        int ti   = SortBands[iorb].TwistIndex;
        int bi   = SortBands[iorb].BandIndex;
        twist = TwistAngles[ti];
        k = orbitalSet->PrimLattice.k_cart(twist);
        string uName  = MuffinTinPath (ti, bi,tin) + "u_lm_r";
        string duName = MuffinTinPath (ti, bi,tin) + "du_lm_dr";
        HDFAttribIO<Array<complex<double>,2> > h_u_lm_r(u_lm_r);
        HDFAttribIO<Array<complex<double>,1> > h_du_lm_dr(du_lm_dr);
        h_u_lm_r.read(H5FileID, uName.c_str());
        h_du_lm_dr.read(H5FileID, duName.c_str());
      }
      myComm->bcast(u_lm_r);
      myComm->bcast(du_lm_dr);
      myComm->bcast(k);
      double Z = (double)IonTypes(tin);
      OrbitalSet->MuffinTins[tin].set_APW (ival, k, u_lm_r, du_lm_dr, Z);
    }
  }
  orbitalSet->AtomicOrbitals = AtomicOrbitals;
  for (int i=0; i<orbitalSet->AtomicOrbitals.size(); i++)
    orbitalSet->AtomicOrbitals[i].registerTimers();
  //ExtendedMap_z[set] = orbitalSet->MultiSpline;
}
void EinsplineSetBuilder::ReadBands_ESHDF(int spin, EinsplineSetExtended<double>* orbitalSet)
{
  update_token(__FILE__,__LINE__,"ReadBands_ESHDF:double");
  ReportEngine PRE("EinsplineSetBuilder","ReadBands_ESHDF(EinsplineSetExtended<double>*");
  vector<AtomicOrbital<double> > realOrbs(AtomicOrbitals.size());
  for (int iat=0; iat<realOrbs.size(); iat++)
  {
    AtomicOrbital<complex<double> > &corb (AtomicOrbitals[iat]);
    realOrbs[iat].set_pos  (corb.Pos);
    realOrbs[iat].set_lmax (corb.lMax);
    realOrbs[iat].set_cutoff (corb.CutoffRadius);
    realOrbs[iat].set_spline (corb.SplineRadius, corb.SplinePoints);
    realOrbs[iat].set_polynomial (corb.PolyRadius, corb.PolyOrder);
    realOrbs[iat].Lattice = corb.Lattice;
  }
  bool root = myComm->rank()==0;
  // bcast other stuff
  myComm->bcast (NumDistinctOrbitals);
  myComm->bcast (NumValenceOrbs);
  myComm->bcast (NumCoreOrbs);
  int N = NumDistinctOrbitals;
  orbitalSet->kPoints.resize(N);
  orbitalSet->MakeTwoCopies.resize(N);
  orbitalSet->StorageValueVector.resize(N);
  orbitalSet->BlendValueVector.resize(N);
  orbitalSet->StorageLaplVector.resize(N);
  orbitalSet->BlendLaplVector.resize(N);
  orbitalSet->StorageGradVector.resize(N);
  orbitalSet->BlendGradVector.resize(N);
  orbitalSet->StorageHessVector.resize(N);
  orbitalSet->StorageGradHessVector.resize(N);
  orbitalSet->phase.resize(N);
  orbitalSet->eikr.resize(N);
  orbitalSet->NumValenceOrbs = NumValenceOrbs;
  orbitalSet->NumCoreOrbs    = NumCoreOrbs;
  orbitalSet->FirstOrderSplines.resize(IonPos.size());
  // Read in k-points
  int numOrbs = orbitalSet->getOrbitalSetSize();
  int num = 0;
  vector<BandInfo>& SortBands(*FullBands[spin]);
  if (root)
  {
    for (int iorb=0; iorb<N; iorb++)
    {
      int ti = SortBands[iorb].TwistIndex;
      PosType twist  = TwistAngles[ti];
      orbitalSet->kPoints[iorb] = orbitalSet->PrimLattice.k_cart(twist);
      orbitalSet->MakeTwoCopies[iorb] =
        (num < (numOrbs-1)) && SortBands[iorb].MakeTwoCopies;
      num += orbitalSet->MakeTwoCopies[iorb] ? 2 : 1;
    }
    PosType twist0 = TwistAngles[SortBands[0].TwistIndex];
    for (int i=0; i<OHMMS_DIM; i++)
      if (std::fabs(std::fabs(twist0[i]) - 0.5) < 1.0e-8)
        orbitalSet->HalfG[i] = 1;
      else
        orbitalSet->HalfG[i] = 0;
    EinsplineSetBuilder::RotateBands_ESHDF(spin, orbitalSet);
  }
  myComm->bcast(orbitalSet->kPoints);
  myComm->bcast(orbitalSet->MakeTwoCopies);
  myComm->bcast(orbitalSet->HalfG);
  // First, check to see if we have already read this in
  H5OrbSet set(H5FileName, spin, N);
  bool havePsir=!ReadGvectors_ESHDF();
  app_log() << "MeshSize = (" << MeshSize[0] << ", "
            << MeshSize[1] << ", " << MeshSize[2] << ")\n";
  //int nx, ny, nz, bi, ti;
  int nx, ny, nz;
  nx=MeshSize[0];
  ny=MeshSize[1];
  nz=MeshSize[2];
  Ugrid x_grid, y_grid, z_grid;
  BCtype_d xBC, yBC, zBC;
  if (orbitalSet->HalfG[0])
  {
    xBC.lCode = ANTIPERIODIC;
    xBC.rCode = ANTIPERIODIC;
  }
  else
  {
    xBC.lCode = PERIODIC;
    xBC.rCode = PERIODIC;
  }
  if (orbitalSet->HalfG[1])
  {
    yBC.lCode = ANTIPERIODIC;
    yBC.rCode = ANTIPERIODIC;
  }
  else
  {
    yBC.lCode = PERIODIC;
    yBC.rCode = PERIODIC;
  }
  if (orbitalSet->HalfG[2])
  {
    zBC.lCode = ANTIPERIODIC;
    zBC.rCode = ANTIPERIODIC;
  }
  else
  {
    zBC.lCode = PERIODIC;
    zBC.rCode = PERIODIC;
  }
  x_grid.start = 0.0;
  x_grid.end = 1.0;
  x_grid.num = nx;
  y_grid.start = 0.0;
  y_grid.end = 1.0;
  y_grid.num = ny;
  z_grid.start = 0.0;
  z_grid.end = 1.0;
  z_grid.num = nz;
  // Create the multiUBspline object
  orbitalSet->MultiSpline =
    create_multi_UBspline_3d_d (x_grid, y_grid, z_grid, xBC, yBC, zBC, NumValenceOrbs);
  if (HaveOrbDerivs)
  {
    orbitalSet->FirstOrderSplines.resize(IonPos.size());
    for (int ion=0; ion<IonPos.size(); ion++)
      for (int dir=0; dir<OHMMS_DIM; dir++)
        orbitalSet->FirstOrderSplines[ion][dir] =
          create_multi_UBspline_3d_d (x_grid, y_grid, z_grid, xBC, yBC, zBC, NumValenceOrbs);
  }
  //////////////////////////////////////
  // Create the MuffinTin APW splines //
  //////////////////////////////////////
  orbitalSet->MuffinTins.resize(NumMuffinTins);
  for (int tin=0; tin<NumMuffinTins; tin++)
  {
    orbitalSet->MuffinTins[tin].Atom = tin;
    orbitalSet->MuffinTins[tin].set_center (MT_centers[tin]);
    orbitalSet->MuffinTins[tin].set_lattice(Lattice);
    orbitalSet->MuffinTins[tin].init_APW
    (MT_APW_rgrids[tin], MT_APW_lmax[tin],
     NumValenceOrbs);
  }
  for (int iat=0; iat<realOrbs.size(); iat++)
  {
    realOrbs[iat].set_num_bands(NumValenceOrbs);
    realOrbs[iat].allocate();
  }
  int isComplex;
  if (root)
  {
    HDFAttribIO<int> h_isComplex(isComplex);
    h_isComplex.read(H5FileID, "/electrons/psi_r_is_complex");
  }
  myComm->bcast(isComplex);
  bool isCore = bcastSortBands(spin,N,root);
  if(isCore)
  {
    APP_ABORT("Core states not supported by ES-HDF yet.");
  }
  //this is common
  Array<double,3> splineData(nx,ny,nz);
  if(havePsir)
  {
    if(isComplex)
    {
      app_log() << "   Reading complex psi_r and convert to real" << endl;
      Array<complex<double>,3> rawData;
      for(int iorb=0,ival=0; iorb<N; ++iorb, ++ival)
      {
        int ti=SortBands[iorb].TwistIndex;
        if(root)
        {
          ostringstream path;
          path << "/electrons/kpoint_" << SortBands[iorb].TwistIndex
               << "/spin_" << spin << "/state_" << SortBands[iorb].BandIndex << "/psi_r";
          HDFAttribIO<Array<complex<double>,3> >  h_splineData(rawData);
          h_splineData.read(H5FileID, path.str().c_str());
        }
        myComm->bcast(rawData);
        //multiply twist factor and project on the real
        fix_phase_c2r(rawData,splineData,TwistAngles[ti]);
        set_multi_UBspline_3d_d (orbitalSet->MultiSpline, ival, splineData.data());
      }
    }
    else
    {
      app_log() << "   Reading real psi_r" << endl;
      for(int iorb=0,ival=0; iorb<N; ++iorb, ++ival)
      {
        if(root)
        {
          ostringstream path;
          path << "/electrons/kpoint_" << SortBands[iorb].TwistIndex
               << "/spin_" << spin << "/state_" << SortBands[iorb].BandIndex << "/psi_r";
          HDFAttribIO<Array<double,3> >  h_splineData(splineData);
          h_splineData.read(H5FileID, path.str().c_str());
        }
        myComm->bcast(splineData);
        set_multi_UBspline_3d_d (orbitalSet->MultiSpline, ival, splineData.data());
      }
    }
  }
  else
  {
    Array<ComplexType,3> FFTbox;
    FFTbox.resize(MeshSize[0], MeshSize[1], MeshSize[2]);
    fftw_plan FFTplan = fftw_plan_dft_3d
                        (MeshSize[0], MeshSize[1], MeshSize[2],
                         reinterpret_cast<fftw_complex*>(FFTbox.data()),
                         reinterpret_cast<fftw_complex*>(FFTbox.data()),
                         +1, FFTW_ESTIMATE);
    for(int iorb=0,ival=0; iorb<N; ++iorb, ++ival)
    {
      Vector<complex<double> > cG;
      int ncg=0;
      int ti=SortBands[iorb].TwistIndex;
      if(root)
      {
        ostringstream path;
        path << "/electrons/kpoint_" << SortBands[iorb].TwistIndex
             << "/spin_" << spin << "/state_" << SortBands[iorb].BandIndex << "/psi_g";
        HDFAttribIO<Vector<complex<double> > >  h_cG(cG);
        h_cG.read (H5FileID, path.str().c_str());
        ncg=cG.size();
      }
      myComm->bcast(ncg);
      if(ncg != Gvecs[0].size())
      {
        APP_ABORT("Failed : ncg != Gvecs[0].size()");
      }
      if(!root)
        cG.resize(ncg);
      myComm->bcast(cG);
      unpack4fftw(cG,Gvecs[0],MeshSize,FFTbox);
      fftw_execute (FFTplan);
      fix_phase_rotate_c2r(FFTbox,splineData,TwistAngles[ti]);
      set_multi_UBspline_3d_d (orbitalSet->MultiSpline, ival, splineData.data());
    }
    fftw_destroy_plan(FFTplan);
  }
  for(int iorb=0,ival=0; iorb<N; ++iorb, ++ival)
  {
    // Read atomic orbital information
    for (int iat=0; iat<realOrbs.size(); iat++)
    {
      app_log() << "Reading orbital " << iat << " for band " << ival << endl;
      AtomicOrbital<double> &orb = realOrbs[iat];
      //AtomicOrbital<complex<double> > &orb = realOrbs[iat];
      Array<complex<double>,2> radial_spline(orb.SplinePoints,orb.Numlm),
            poly_coefs(orb.PolyOrder+1,orb.Numlm);
      int ti   = SortBands[iorb].TwistIndex;
      if (root)
      {
        int bi   = SortBands[iorb].BandIndex;
        ostringstream path;
        path << "/electrons/kpoint_" << ti << "/spin_" << spin << "/state_" << bi << "/";
        ostringstream spline_path, poly_path;
        spline_path << path.str() << "radial_spline_" << iat;
        poly_path   << path.str() << "poly_coefs_"    << iat;
        HDFAttribIO<Array<complex<double>,2> > h_radial_spline(radial_spline);
        HDFAttribIO<Array<complex<double>,2> > h_poly_coefs(poly_coefs);
        h_radial_spline.read(H5FileID, spline_path.str().c_str());
        h_poly_coefs.read   (H5FileID, poly_path.str().c_str());
      }
      myComm->bcast(radial_spline);
      myComm->bcast(poly_coefs);
      realOrbs[iat].set_band (ival, radial_spline, poly_coefs, TwistAngles[ti]);
    }
  }
  for(int iorb=0,ival=0; iorb<N; ++iorb, ++ival)
  {
    // Now read muffin tin data
    for (int tin=0; tin<NumMuffinTins; tin++)
    {
      // app_log() << "Reading data for muffin tin " << tin << endl;
      PosType twist, k;
      int lmax = MT_APW_lmax[tin];
      int numYlm = (lmax+1)*(lmax+1);
      Array<complex<double>,2>
      u_lm_r(numYlm, MT_APW_num_radial_points[tin]);
      Array<complex<double>,1> du_lm_dr (numYlm);
      int ti   = SortBands[iorb].TwistIndex;
      if (root)
      {
        int bi   = SortBands[iorb].BandIndex;
        twist = TwistAngles[ti];
        k = orbitalSet->PrimLattice.k_cart(twist);
        string uName  = MuffinTinPath (ti, bi,tin) + "u_lm_r";
        string duName = MuffinTinPath (ti, bi,tin) + "du_lm_dr";
        HDFAttribIO<Array<complex<double>,2> > h_u_lm_r(u_lm_r);
        HDFAttribIO<Array<complex<double>,1> > h_du_lm_dr(du_lm_dr);
        h_u_lm_r.read(H5FileID, uName.c_str());
        h_du_lm_dr.read(H5FileID, duName.c_str());
      }
      myComm->bcast(u_lm_r);
      myComm->bcast(du_lm_dr);
      myComm->bcast(k);
      double Z = (double)IonTypes(tin);
      OrbitalSet->MuffinTins[tin].set_APW (ival, k, u_lm_r, du_lm_dr, Z);
    }
  }
  //FIX HaveOrbDerivs after debugging
//	// Now read orbital derivatives if we have them
//	if (HaveOrbDerivs) {
//	  for (int ion=0; ion<IonPos.size(); ion++)
//	    for (int dim=0; dim<OHMMS_DIM; dim++) {
//	      if (root) {
//		int ti   = SortBands[iorb].TwistIndex;
//		int bi   = SortBands[iorb].BandIndex;
//
//		app_log() << "Reading orbital derivative for ion " << ion
//			  << " dim " << dim << " spin " << spin << " band "
//			  << bi << " kpoint " << ti << endl;
//		ostringstream path;
//		path << "/electrons/kpoint_" << ti << "/spin_" << spin << "/state_" << bi << "/"
//		     << "dpsi_" << ion << "_" << dim << "_r";
//		string psirName = path.str();
//		if (isComplex) {
//		  HDFAttribIO<Array<complex<double>,3> > h_rawData(rawData);
//		  h_rawData.read(H5FileID, psirName.c_str());
//		  if ((rawData.size(0) != nx) ||
//		      (rawData.size(1) != ny) ||
//		      (rawData.size(2) != nz)) {
//		    fprintf (stderr, "Error in EinsplineSetBuilder::ReadBands.\n");
//		    fprintf (stderr, "Extended orbitals should all have the same dimensions\n");
//		    abort();
//		  }
//#pragma omp parallel for
//		  for (int ix=0; ix<nx; ix++) {
//		  PosType ru;
//		    ru[0] = (RealType)ix / (RealType)nx;
//		    for (int iy=0; iy<ny; iy++) {
//		      ru[1] = (RealType)iy / (RealType)ny;
//		      for (int iz=0; iz<nz; iz++) {
//			ru[2] = (RealType)iz / (RealType)nz;
//			double phi = -2.0*M_PI*dot (ru, TwistAngles[ti]);
//			double s, c;
//			sincos(phi, &s, &c);
//			complex<double> phase(c,s);
//			complex<double> z = phase*rawData(ix,iy,iz);
//			splineData(ix,iy,iz) = z.real();
//		      }
//		    }
//		  }
//		}
//		else {
//		  HDFAttribIO<Array<double,3> >  h_splineData(splineData);
//		  h_splineData.read(H5FileID, psirName.c_str());
//		  if ((splineData.size(0) != nx) ||
//		      (splineData.size(1) != ny) ||
//		      (splineData.size(2) != nz)) {
//		    fprintf (stderr, "Error in EinsplineSetBuilder::ReadBands.\n");
//		    fprintf (stderr, "Extended orbitals should all have the same dimensions\n");
//		    abort();
//		  }
//		}
//	      }
//	      myComm->bcast(splineData);
//	      set_multi_UBspline_3d_d
//		(orbitalSet->FirstOrderSplines[ion][dim], ival, splineData.data());
//	    }
//	}
//
//
//
  orbitalSet->AtomicOrbitals = realOrbs;
  for (int i=0; i<orbitalSet->AtomicOrbitals.size(); i++)
    orbitalSet->AtomicOrbitals[i].registerTimers();
  //ExtendedMap_d[set] = orbitalSet->MultiSpline;
}
Example #12
0
/// Returns the number of bytes stored in the column.
///
/// \pre This is only valid for columns of type blob and text.
///
/// \param index The column to retrieve the size of.
///
/// \return The number of bytes in the column.  Remember that strings are stored
/// in their UTF-8 representation; this call returns the number of *bytes*, not
/// characters.
int
sqlite::statement::column_bytes(const int index)
{
    PRE(column_type(index) == type_blob || column_type(index) == type_text);
    return ::sqlite3_column_bytes(_pimpl->stmt, index);
}
Example #13
0
/// Returns a particular column in the result as a 64-bit integer.
///
/// \param index The column to retrieve.
///
/// \return The integer value.
int64_t
sqlite::statement::column_int64(const int index)
{
    PRE(column_type(index) == type_integer);
    return ::sqlite3_column_int64(_pimpl->stmt, index);
}
Example #14
0
/// Returns a particular column in the result as a double.
///
/// \param index The column to retrieve.
///
/// \return The double value.
double
sqlite::statement::column_double(const int index)
{
    PRE(column_type(index) == type_float);
    return ::sqlite3_column_double(_pimpl->stmt, index);
}
Example #15
0
void
cfi_call_instrumentation_snapahot(void *dcontext, instrlist_t *ilist, instr_t *where, void *callee)
{
    uint dstack_offs = 0, pad = 0;

    unsigned int eflags_offs;

    CFI_ASSERT(dcontext != NULL, "cfi_call_instrumentation_snapahot: dcontext cannot be NULL");

    instr_t *next_snapshot = INSTR_CREATE_label(dcontext);
    PRE(ilist, where, INSTR_CREATE_pushf(dcontext));
    dstack_offs += XSP_SZ;
    eflags_offs = dstack_offs;

    PRE(ilist, where, INSTR_CREATE_push(dcontext, opnd_create_reg(DR_REG_RDI)));
    dstack_offs += XSP_SZ;

    PRE(ilist, where, INSTR_CREATE_mov_imm(dcontext, opnd_create_reg(DR_REG_RDI), OPND_CREATE_INT64(&flag_memory_snapshot)));
    PRE(ilist, where, INSTR_CREATE_mov_ld(dcontext, opnd_create_reg(DR_REG_RDI), opnd_create_base_disp(DR_REG_RDI, DR_REG_NULL, 0, 0, OPSZ_PTR)));
    PRE(ilist, where, INSTR_CREATE_cmp(dcontext, opnd_create_reg(DR_REG_RDI), OPND_CREATE_INT8(0x0)));
    PRE(ilist, where, INSTR_CREATE_jcc(dcontext, OP_je, opnd_create_instr(next_snapshot)));

    PRE(ilist, where, INSTR_CREATE_push(dcontext,
                          opnd_create_base_disp(DR_REG_RSP, DR_REG_NULL, 0,
                          dstack_offs - eflags_offs, OPSZ_STACK)));

    PRE(ilist, where, INSTR_CREATE_and(dcontext,
                         opnd_create_base_disp(DR_REG_RSP, DR_REG_NULL, 0, 0,
                                               OPSZ_STACK),
                         OPND_CREATE_INT32(~(EFLAGS_NON_SYSTEM | EFLAGS_IF))));

    PRE(ilist, where, INSTR_CREATE_popf(dcontext));

    instrlist_set_our_mangling(ilist, true);
    cfi_insert_meta_native_call_vargs(dcontext, ilist, where, true/*clean*/, callee);
    instrlist_set_our_mangling(ilist, false);

    cfi_insert_native_call(dcontext, ilist, where, callee /*, opnd_create_reg(DR_REG_RAX)*/);

    PRE(ilist, where, next_snapshot);
    PRE(ilist, where, INSTR_CREATE_pop(dcontext, opnd_create_reg(DR_REG_RDI)));
    PRE(ilist, where, INSTR_CREATE_popf(dcontext));



   /* dstack_offs = cfi_prepare_for_native_call(dcontext, ilist, where);

     instrlist_set_our_mangling(ilist, true);
     cfi_insert_meta_native_call_vargs(dcontext, ilist, where, true*//*clean*//*, callee);
     instrlist_set_our_mangling(ilist, false);

     cfi_cleanup_after_native_call(dcontext, ilist, where);*/
}
Example #16
0
/// Overrides the current set of users for testing purposes.
///
/// \param users The new users set.  Cannot be empty.
void
passwd_ns::set_mock_users_for_testing(const std::vector< user >& users)
{
    PRE(!users.empty());
    mock_users = users;
}
Example #17
0
bool WaveFunctionFactory::build(xmlNodePtr cur, bool buildtree) {

    ReportEngine PRE(ClassName,"build");

    if(cur == NULL) return false;

    bool attach2Node=false;
    if(buildtree) {
        if(myNode == NULL) {
            myNode = xmlCopyNode(cur,1);
        } else {
            attach2Node=true;
        }
    }

    if(targetPsi==0) //allocate targetPsi and set the name
    {
        targetPsi  = new TrialWaveFunction(myComm);
        targetPsi->setName(myName);
    }

    cur = cur->children;
    bool success=true;
    while(cur != NULL)
    {
        string cname((const char*)(cur->name));
        if (cname == OrbitalBuilderBase::detset_tag)
        {
            success = addFermionTerm(cur);
        }
        else if (cname ==  OrbitalBuilderBase::jastrow_tag)
        {
            OrbitalBuilderBase *jbuilder = new JastrowBuilder(*targetPtcl,*targetPsi,ptclPool);
            jbuilder->setReportLevel(ReportLevel);
            success = jbuilder->put(cur);
            addNode(jbuilder,cur);
        }
#if OHMMS_DIM==3
        else if(cname == "agp")
        {
#if defined(QMC_COMPLEX)
            sendError("AGPDeterminant cannot be used with QMC_COMPLEX=1");
            return false;
#else
            AGPDeterminantBuilder* agpbuilder = new AGPDeterminantBuilder(*targetPtcl,*targetPsi,ptclPool);
            success = agpbuilder->put(cur);
            addNode(agpbuilder,cur);
#endif
        }
#endif
        if(attach2Node) xmlAddChild(myNode,xmlCopyNode(cur,1));
        cur = cur->next;
    }

    //{
    //  ReportEngine PREA("TrialWaveFunction","print");
    //  targetPsi->VarList.print(app_log());
    //}

    return success;
}
Example #18
0
void
watchpoint_indirect_call_event(dcontext_t *drcontext, instrlist_t *ilist, instr_t *instr,
                     instr_t *next_instr, bool mangle_calls, uint flags)
{
    opnd_t instr_opnd;
    reg_id_t base_reg;
    unsigned long used_registers = 0;
    app_pc pc;
    struct memory_operand_modifier ops = {0};

    instr_t *begin_instrumenting = INSTR_CREATE_label(drcontext);
    instr_t *done_instrumenting = INSTR_CREATE_label(drcontext);
    instr_t *nop = INSTR_CREATE_nop(drcontext);
    instr_t *emulated;


    memset(&ops, 0, sizeof(struct memory_operand_modifier));

    if(instr_reads_memory(instr)) {
        instr_opnd = instr_get_src(instr, 0);
        if (opnd_is_rel_addr(instr_opnd) || opnd_is_abs_addr(instr_opnd)) {

        }else if (opnd_is_base_disp(instr_opnd)) {

            for_each_src_operand(instr, &ops, (opnd_callback_t *) memory_src_operand_finder);
           // base_reg = opnd_get_reg(instr_opnd);

            switch(ops.found_operand.value.base_disp.base_reg) {
                case DR_REG_RSP: case DR_REG_ESP: case DR_REG_SP:
                case DR_REG_RBP: case DR_REG_EBP: case DR_REG_BP:
                    return;
                default:
                  break;
            }

            collect_regs(&used_registers, instr, instr_num_srcs, instr_get_src );
            collect_regs(&used_registers, instr, instr_num_dsts, instr_get_dst );

            reg_id_t reg_watched_addr = get_next_free_reg(&used_registers);
            opnd_t opnd_watched_addr = opnd_create_reg(reg_watched_addr);

            reg_id_t reg_unwatched_addr = get_next_free_reg(&used_registers);
            opnd_t opnd_unwatched_addr = opnd_create_reg(reg_unwatched_addr);

            PRE(ilist, instr, begin_instrumenting);
            PRE(ilist, instr, INSTR_CREATE_push(drcontext, opnd_watched_addr));
            PRE(ilist, instr, INSTR_CREATE_push(drcontext, opnd_unwatched_addr));
            PRE(ilist, instr, INSTR_CREATE_pushf(drcontext));
            PRE(ilist, instr, INSTR_CREATE_lea(drcontext, opnd_watched_addr, opnd_create_base_disp(opnd_get_base(ops.found_operand),
                                                        opnd_get_index(ops.found_operand), opnd_get_scale(ops.found_operand),
                                                        opnd_get_disp(ops.found_operand), OPSZ_lea)));

            PRE(ilist, instr, INSTR_CREATE_mov_imm(drcontext, opnd_unwatched_addr,
                                            OPND_CREATE_INT64(WATCHPOINT_INDEX_MASK)));
            PRE(ilist, instr, INSTR_CREATE_or(drcontext, opnd_unwatched_addr, opnd_watched_addr));

            emulated = instr_clone(drcontext, instr);
            emulated->translation = 0;

            ops.replacement_operand = opnd_create_base_disp(
                    reg_unwatched_addr, DR_REG_NULL,1, 0 , ops.found_operand.size);

            for_each_operand(emulated, &ops, (opnd_callback_t *) memory_operand_replacer);

            PRE(ilist, instr, INSTR_CREATE_popf(drcontext));
            PRE(ilist, instr, emulated);
            PRE(ilist, instr, INSTR_CREATE_pop(drcontext, opnd_unwatched_addr));
            PRE(ilist, instr, INSTR_CREATE_pop(drcontext, opnd_watched_addr));

            PRE(ilist, instr, INSTR_CREATE_jmp_short(drcontext,
                    opnd_create_instr(done_instrumenting)));

            pc = instr->translation;
            instr->translation = 0; // hack!
            instr_being_modified(instr, false);
            instr_set_ok_to_mangle(instr, false);

            if(NULL != pc){
                nop->translation = pc + instr->length;
            }
            POST(ilist, instr, nop);
            POST(ilist, instr, done_instrumenting);

        }
    }
}
Example #19
0
/// Constructor that sets up signal masking.
signals::interrupts_inhibiter::interrupts_inhibiter(void)
{
    PRE(!interrupts_inhibiter_active);
    mask_signals();
    interrupts_inhibiter_active = true;
}
Example #20
0
void RNDMCOMP::resetUpdateEngines()
{
  ReportEngine PRE("RNDMCOMP","resetUpdateEngines");
  Timer init_timer;
  makeClones(W,Psi,H);
  makeClones(W,Guide);
  if(Movers.empty())
  {
    W.loadEnsemble(wClones);
    branchEngine->initWalkerController(W,false,true);
    branchEngine->setRN(true);
    //if(QMCDriverMode[QMC_UPDATE_MODE]) W.clearAuxDataSet();
    Movers.resize(NumThreads,0);
    branchClones.resize(NumThreads,0);
    Rng.resize(NumThreads,0);
    estimatorClones.resize(NumThreads,0);
    FairDivideLow(W.getActiveWalkers(),NumThreads,wPerNode);
    bool klw=(KillWalker=="yes");
    {
      //log file
      ostringstream o;
      o << "  Initial partition of walkers on a node: ";
      std::copy(wPerNode.begin(),wPerNode.end(),ostream_iterator<int>(o," "));
      o << "\n";
      o << "Killing Walkers at nodes " << (useAlternate!="yes") <<endl;
      o << "Running the released node driver."<<endl;
      app_log() << o.str();
    }
    #pragma omp parallel for
    for(int ip=0; ip<NumThreads; ++ip)
    {
      estimatorClones[ip]= new EstimatorManager(*Estimators);
      estimatorClones[ip]->setCollectionMode(false);
      Rng[ip]=new RandomGenerator_t(*RandomNumberControl::Children[ip]);
      hClones[ip]->setRandomGenerator(Rng[ip]);
      branchClones[ip] = new BranchEngineType(*branchEngine);
//         Movers[ip] = new RNDMCUpdatePbyPWithRejectionFast(*wClones[ip],*psiClones[ip],*hClones[ip],*Rng[ip]);
      Movers[ip] = new RNDMCUpdatePbyPFast(*wClones[ip],*wgClones[ip],*psiClones[ip],*guideClones[ip],*hClones[ip],*Rng[ip]);
      Movers[ip]->put(qmcNode);
      Movers[ip]->resetRun(branchClones[ip],estimatorClones[ip]);
      MCWalkerConfiguration::iterator wit(W.begin()+wPerNode[ip]), wit_end(W.begin()+wPerNode[ip+1]);
      Movers[ip]->initWalkersForPbyP(wit, wit_end);
    }
  }
//     branchEngine->checkParameters(W);
  if(BranchInterval<0)
    BranchInterval=1;
  {
    ostringstream o;
//       if (useAlternate=="yes") o << "  Using Alternate Mover"<<endl;
//       else o << "  Using Ceperley Mover"<<endl;
    o << "  BranchInterval = " << BranchInterval << "\n";
    o << "  Steps per block = " << nSteps << "\n";
    o << "  Number of blocks = " << nBlocks << "\n";
    app_log() << endl << o.str() << endl;
  }
//     RealType avg_w(0);
//     RealType n_w(0);
//     RealType logepsilon(0);
// #pragma omp parallel
//       {
//         int ip=omp_get_thread_num();
//
//         for (int step=0; step<nWarmupSteps; ++step)
//         {
//           avg_w=0;
//           n_w=0;
//           for (int prestep=0; prestep<myRNWarmupSteps; ++prestep)
//           {
//             Movers[ip]->advanceWalkers(W.begin()+wPerNode[ip],W.begin()+wPerNode[ip+1],true);
//             #pragma omp single
//             {
//               MCWalkerConfiguration::iterator wit(W.begin()), wit_end(W.end());
//               while (wit!=wit_end)
//               {
//                 avg_w += (*wit)->Weight;
//                 n_w +=1;
//                 wit++;
//               }
//             }
//             #pragma omp barrier
//            }
//            #pragma omp single
//            {
//              avg_w *= 1.0/n_w;
//              RealType w_m = avg_w/(1.0-avg_w);
//              w_m = std::log(0.5+0.5*w_m);
//              if (std::abs(w_m)>0.01)
//                logepsilon += w_m;
//            }
//            #pragma omp barrier
//            Movers[ip]->setLogEpsilon(logepsilon);
//         }
//
//       }
  app_log() << " RNDMC Engine Initialization = " << init_timer.elapsed() << " secs " << endl;
}
Example #21
0
void
atf_error_format(const atf_error_t err, char *buf, size_t buflen)
{
    PRE(err != NULL);
    err->m_format(err, buf, buflen);
}
Example #22
0
/// Unsets a string variable from the templates.
///
/// Client code has no reason to use this.  This is only required to implement
/// proper scoping of loop iterators.
///
/// \pre The variable must exist.
///
/// \param name The name of the variable to remove from the templates.
void
text::templates_def::remove_variable(const std::string& name)
{
    PRE(_variables.find(name) != _variables.end());
    _variables.erase(_variables.find(name));
}
Example #23
0
void DMCOMPOPT::resetUpdateEngines()
{
  ReportEngine PRE("DMCOMPOPT","resetUpdateEngines");
  resetComponents(qmcNode);
  bool fixW = (Reconfiguration == "yes");
  Timer init_timer;
//     HACK HACK HACK
// This is so ugly it's probably a crime. It must be fixed.
  if(firsttime)
  {
//       for(int ip=1; ip<NumThreads; ++ip)
//       {
//         delete wClones[ip];
//         delete psiClones[ip];
//         delete hClones[ip];
//       }
//       wClones.resize(0);
    wClones.clear();
    psiClones.clear();
    hClones.clear();
    firsttime=false;
  }
  for (int ip=0; ip<NumThreads; ++ip)
  {
    opt_variables_type dummy;
    psiClones[ip]->checkInVariables(dummy);
    dummy.resetIndex();
    psiClones[ip]->checkOutVariables(dummy);
    dummyOptVars.push_back(dummy);
  }
  NumOptimizables=dummyOptVars[0].size();
  resizeForOpt(NumOptimizables);
  makeClones(W,Psi,H);
  if(Movers.empty())
  {
//       //load walkers
    Eindx = W.addPropertyHistory(wlen);
    W.loadEnsemble(wClones);
    for(int ip=1; ip<NumThreads; ++ip)
      wClones[ip]->addPropertyHistory(wlen);
//       m_param.put(qmcNode);
//       put(qmcNode);
//       //app_log()<<"DMCOMPOPT::resetComponents"<<endl;
//       Estimators->reset();
//       branchEngine->resetRun(qmcNode);
//       branchEngine->checkParameters(W);
    branchEngine->initWalkerController(W,fixW,false);
    //if(QMCDriverMode[QMC_UPDATE_MODE]) W.clearAuxDataSet();
    Movers.resize(NumThreads,0);
    branchClones.resize(NumThreads,0);
    Rng.resize(NumThreads,0);
    estimatorClones.resize(NumThreads,0);
    FairDivideLow(W.getActiveWalkers(),NumThreads,wPerNode);
    {
      //log file
      ostringstream o;
      o << "  Initial partition of walkers on a node: ";
      std::copy(wPerNode.begin(),wPerNode.end(),ostream_iterator<int>(o," "));
      o << "\n";
      if(QMCDriverMode[QMC_UPDATE_MODE])
        o << "  Updates by particle-by-particle moves";
      else
        o << "  Updates by walker moves";
      if(UseFastGrad == "yes")
        o << " using fast gradient version ";
      else
        o << " using full-ratio version ";
      if(KillNodeCrossing)
        o << "\n  Walkers are killed when a node crossing is detected";
      else
        o << "\n  DMC moves are rejected when a node crossing is detected";
      app_log() << o.str() << endl;
    }
    #pragma omp parallel for
    for(int ip=0; ip<NumThreads; ++ip)
    {
      estimatorClones[ip]= new EstimatorManager(*Estimators);
      estimatorClones[ip]->setCollectionMode(false);
      Rng[ip]=new RandomGenerator_t(*RandomNumberControl::Children[ip]);
      hClones[ip]->setRandomGenerator(Rng[ip]);
      branchClones[ip] = new BranchEngineType(*branchEngine);
      if(QMCDriverMode[QMC_UPDATE_MODE])
      {
        if(UseFastGrad == "yes")
          Movers[ip] = new DMCUpdatePbyPWithRejectionFast(*wClones[ip],*psiClones[ip],*hClones[ip],*Rng[ip]);
        else
          Movers[ip] = new DMCUpdatePbyPWithRejection(*wClones[ip],*psiClones[ip],*hClones[ip],*Rng[ip]);
//           Movers[ip]->put(qmcNode);
//           Movers[ip]->resetRun(branchClones[ip],estimatorClones[ip]);
//           Movers[ip]->initWalkersForPbyP(W.begin()+wPerNode[ip],W.begin()+wPerNode[ip+1]);
      }
      else
      {
        if(KillNodeCrossing)
          Movers[ip] = new DMCUpdateAllWithKill(*wClones[ip],*psiClones[ip],*hClones[ip],*Rng[ip]);
        else
          Movers[ip] = new DMCUpdateAllWithRejection(*wClones[ip],*psiClones[ip],*hClones[ip],*Rng[ip]);
//           Movers[ip]->put(qmcNode);
//           Movers[ip]->resetRun(branchClones[ip],estimatorClones[ip]);
//           Movers[ip]->initWalkers(W.begin()+wPerNode[ip],W.begin()+wPerNode[ip+1]);
      }
    }
//       #pragma omp parallel for
//       for (int ip=0; ip<NumThreads; ++ip)
//       {
//         MCWalkerConfiguration::iterator wit(W.begin()+wPerNode[ip]), wit_end(W.begin()+wPerNode[ip+1]);
//         while (wit!=wit_end)
//         {
//           Walker_t& thisWalker(**wit);
//           Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);
//           wClones[ip]->loadWalker(thisWalker,true);
//           psiClones[ip]->copyFromBuffer(*wClones[ip],w_buffer);
//           psiClones[ip]->updateBuffer(*wClones[ip],w_buffer,true);
//           wit++;
//         }
//       }
  }
  #pragma omp parallel for
  for(int ip=0; ip<NumThreads; ++ip)
  {
    if(QMCDriverMode[QMC_UPDATE_MODE])
    {
      Movers[ip]->put(qmcNode);
      Movers[ip]->resetRun(branchClones[ip],estimatorClones[ip]);
      Movers[ip]->initWalkersForPbyP(W.begin()+wPerNode[ip],W.begin()+wPerNode[ip+1]);
    }
    else
    {
      Movers[ip]->put(qmcNode);
      Movers[ip]->resetRun(branchClones[ip],estimatorClones[ip]);
      Movers[ip]->initWalkers(W.begin()+wPerNode[ip],W.begin()+wPerNode[ip+1]);
    }
  }
  //       adding weight index
  MCWalkerConfiguration::iterator wit(W.begin()), wit_end(W.end());
  (**wit).addPropertyHistory(wlen);
  wit++;
  while(wit!=wit_end)
  {
    (**wit).addPropertyHistory(wlen);
    wit++;
  }
  std::vector<IndexType> samples_th(omp_get_max_threads(),0);
  myPeriod4WalkerDump=(Period4WalkerDump>0)?Period4WalkerDump:(nBlocks+1)*nSteps;
  samples_this_node = nTargetSamples/myComm->size();
  if (nTargetSamples%myComm->size() > myComm->rank())
    samples_this_node+=1;
  int samples_each_thread = samples_this_node/omp_get_max_threads();
  for (int ip=0; ip<omp_get_max_threads(); ++ip)
    samples_th[ip]=samples_each_thread;
  if(samples_this_node%omp_get_max_threads())
    for (int ip=0; ip < samples_this_node%omp_get_max_threads(); ++ip)
      samples_th[ip] +=1;
  int ndumps = std::max(samples_this_node/W.getActiveWalkers() + 1,2);
  myPeriod4WalkerDump = nBlocks*nSteps/ndumps;
  app_log() << "  Samples are dumped every " << myPeriod4WalkerDump << " steps " << endl;
  app_log() << "  Total Sample Size =" << nTargetSamples << endl;
  app_log() << "  Nodes Sample Size =" << samples_this_node << endl;
  for (int ip=0; ip<NumThreads; ++ip)
    app_log()  << "    Sample size for thread " <<ip<<" = " << samples_th[ip] << endl;
  #pragma omp critical
  for(int ip=0; ip<NumThreads; ++ip)
  {
    wClones[ip]->clearEnsemble();
    wClones[ip]->setNumSamples(samples_th[ip]);
  }
  t= Movers[0]->getTau();
  clearComponentMatrices();
  branchEngine->checkParameters(W);
  int mxage=mover_MaxAge;
  if(fixW)
  {
    if(BranchInterval<0)
      BranchInterval=nSteps;
    mxage=(mover_MaxAge<0)?0:mover_MaxAge;
    for(int ip=0; ip<Movers.size(); ++ip)
      Movers[ip]->MaxAge=mxage;
  }
  else
  {
    if(BranchInterval<0)
      BranchInterval=1;
    int miage=(QMCDriverMode[QMC_UPDATE_MODE])?1:5;
    mxage=(mover_MaxAge<0)?miage:mover_MaxAge;
    for(int ip=0; ip<Movers.size(); ++ip)
      Movers[ip]->MaxAge=mxage;
  }
  {
    ostringstream o;
    if(fixW)
      o << "  Fixed population using reconfiguration method\n";
    else
      o << "  Fluctuating population\n";
    o << "  Persisent walkers are killed after " << mxage << " MC sweeps\n";
    o << "  BranchInterval = " << BranchInterval << "\n";
    o << "  Steps per block = " << nSteps << "\n";
    o << "  Number of blocks = " << nBlocks << "\n";
    app_log() << o.str() << endl;
  }
  app_log() << "  DMC Engine Initialization = " << init_timer.elapsed() << " secs " << endl;
}
Example #24
0
/// Creates a new vector in the templates.
///
/// If the vector already exists, it is cleared.  Client code should really not
/// be redefining variables.
///
/// \pre The vector must not already exist as a variable.
///
/// \param name The name of the vector to set.
void
text::templates_def::add_vector(const std::string& name)
{
    PRE(_variables.find(name) == _variables.end());
    _vectors[name] = strings_vector();
}
Example #25
0
/// Returns the short name of the option.
///
/// \pre has_short_name() must be true.
///
/// \return The short name.
char
cmdline::base_option::short_name(void) const
{
    PRE(has_short_name());
    return _short_name;
}
Example #26
0
  void DMCOMP::resetUpdateEngines() 
  {

    ReportEngine PRE("DMCOMP","resetUpdateEngines");

    bool fixW = (Reconfiguration == "yes");
    
    Timer init_timer;

    makeClones(W,Psi,H);

    if(Movers.empty()) 
    {
      //load walkers
      W.loadEnsemble();
      for(int ip=1;ip<NumThreads;++ip) wClones[ip]->loadEnsemble(W);

      branchEngine->initWalkerController(W,fixW,false);

      //if(QMCDriverMode[QMC_UPDATE_MODE]) W.clearAuxDataSet();
      Movers.resize(NumThreads,0);
      branchClones.resize(NumThreads,0);
      Rng.resize(NumThreads,0);
      estimatorClones.resize(NumThreads,0);
      FairDivideLow(W.getActiveWalkers(),NumThreads,wPerNode);

      {//log file
        ostringstream o;
        o << "  Initial partition of walkers on a node: ";
        std::copy(wPerNode.begin(),wPerNode.end(),ostream_iterator<int>(o," "));
        o << "\n";

        if(QMCDriverMode[QMC_UPDATE_MODE]) 
          o << "  Updates by particle-by-particle moves";
        else 
          o << "  Updates by walker moves";

        if(UseFastGrad == "yes") 
          o << " using fast gradient version ";
        else 
          o << " using full-ratio version ";

        if(KillNodeCrossing)  
          o << "\n  Walkers are killed when a node crossing is detected";
        else
          o << "\n  DMC moves are rejected when a node crossing is detected";

        app_log() << o.str() << endl;
      }

#pragma omp parallel for
      for(int ip=0; ip<NumThreads; ++ip)
      {
        estimatorClones[ip]= new EstimatorManager(*Estimators);
        estimatorClones[ip]->setCollectionMode(false);

        Rng[ip]=new RandomGenerator_t(*RandomNumberControl::Children[ip]);
        hClones[ip]->setRandomGenerator(Rng[ip]);

        branchClones[ip] = new BranchEngineType(*branchEngine);
        if(QMCDriverMode[QMC_UPDATE_MODE])
        {
          if(UseFastGrad == "yes")
            Movers[ip] = new DMCUpdatePbyPWithRejectionFast(*wClones[ip],*psiClones[ip],*hClones[ip],*Rng[ip]); 
          else
            Movers[ip] = new DMCUpdatePbyPWithRejection(*wClones[ip],*psiClones[ip],*hClones[ip],*Rng[ip]); 
          Movers[ip]->put(qmcNode);
          Movers[ip]->resetRun(branchClones[ip],estimatorClones[ip]);
          Movers[ip]->initWalkersForPbyP(W.begin()+wPerNode[ip],W.begin()+wPerNode[ip+1]);
        }
        else
        {
          if(KillNodeCrossing) 
            Movers[ip] = new DMCUpdateAllWithKill(*wClones[ip],*psiClones[ip],*hClones[ip],*Rng[ip]);
          else 
            Movers[ip] = new DMCUpdateAllWithRejection(*wClones[ip],*psiClones[ip],*hClones[ip],*Rng[ip]);
          Movers[ip]->put(qmcNode);
          Movers[ip]->resetRun(branchClones[ip],estimatorClones[ip]);
          Movers[ip]->initWalkers(W.begin()+wPerNode[ip],W.begin()+wPerNode[ip+1]);
        }
      }
    }

    branchEngine->checkParameters(W);

    int mxage=mover_MaxAge;
    if(fixW) 
    {
      if(BranchInterval<0) BranchInterval=nSteps;
      mxage=(mover_MaxAge<0)?0:mover_MaxAge;
      for(int ip=0; ip<Movers.size(); ++ip) Movers[ip]->MaxAge=mxage;
    } 
    else 
    {
      if(BranchInterval<0) BranchInterval=1;
      int miage=(QMCDriverMode[QMC_UPDATE_MODE])?1:5;
      mxage=(mover_MaxAge<0)?miage:mover_MaxAge;
      for(int ip=0; ip<Movers.size(); ++ip) Movers[ip]->MaxAge=mxage;
    }

    {
      ostringstream o;
      if(fixW)
        o << "  Fixed population using reconfiguration method\n";
      else
        o << "  Fluctuating population\n";
      o << "  Persisent walkers are killed after " << mxage << " MC sweeps\n";
      o << "  BranchInterval = " << BranchInterval << "\n";
      o << "  Steps per block = " << nSteps << "\n";
      o << "  Number of blocks = " << nBlocks << "\n";
      app_log() << o.str() << endl;
    }
    app_log() << "  DMC Engine Initialization = " << init_timer.elapsed() << " secs " << endl;
  }
Example #27
0
/// Converts a relative path in the current directory to an absolute path.
///
/// \pre The path is relative.
///
/// \return The absolute representation of the relative path.
fs::path
fs::path::to_absolute(void) const
{
    PRE(!is_absolute());
    return fs::current_path() / *this;
}
Example #28
0
unsigned int
cfi_prepare_for_native_call(void *drcontext, instrlist_t *ilist, instr_t *where)
{
	unsigned int eflags_offs, dstack_offs = 0;
    instr_t *in = (where == NULL) ? instrlist_last(ilist) : instr_get_prev(where);

    CFI_ASSERT(drcontext != NULL, "cfi_prepare_for_native_call: drcontext cannot be NULL");

    //PRE(ilist, where, INSTR_CREATE_push_imm(dcontext, OPND_CREATE_INT32(0)));
    //dstack_offs += XSP_SZ;

    PRE(ilist, where, INSTR_CREATE_pushf(drcontext));
    PRE(ilist, where, INSTR_CREATE_push(drcontext,
                          opnd_create_base_disp(REG_XSP, REG_NULL, 0, 0, OPSZ_STACK)));
    PRE(ilist, where, INSTR_CREATE_and(drcontext,
                         opnd_create_base_disp(REG_XSP, REG_NULL, 0, 0,
                                               OPSZ_STACK),
                         OPND_CREATE_INT32(~(EFLAGS_NON_SYSTEM | EFLAGS_IF))));

    PRE(ilist, where, INSTR_CREATE_popf(drcontext));

  /*  dstack_offs += XSP_SZ;
    eflags_offs = dstack_offs;

    PRE(ilist, where, INSTR_CREATE_lea(drcontext, opnd_create_reg(REG_XSP),
    		OPND_CREATE_MEM_lea(REG_XSP, REG_NULL, 0, - XMM_SLOTS_SIZE)));

    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_R15)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_R14)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_R13)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_R12)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_R11)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_R10)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_R9)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_R8)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_RAX)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_RCX)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_RDX)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_RBX)));*/
    /* we do NOT match pusha xsp value *//*
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_RSP)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_RBP)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_RSI)));
    PRE(ilist, where, INSTR_CREATE_push(drcontext, opnd_create_reg(REG_RDI)));
    dstack_offs += 16*XSP_SZ + XMM_SLOTS_SIZE;

    PRE(ilist, where, INSTR_CREATE_push(drcontext,
                          opnd_create_base_disp(REG_XSP, REG_NULL, 0,
                          dstack_offs - eflags_offs, OPSZ_STACK)));

    PRE(ilist, where, INSTR_CREATE_and(drcontext,
                         opnd_create_base_disp(REG_XSP, REG_NULL, 0, 0,
                                               OPSZ_STACK),
                         OPND_CREATE_INT32(~(EFLAGS_NON_SYSTEM | EFLAGS_IF))));

    PRE(ilist, where, INSTR_CREATE_popf(drcontext));*/

    /* now go through and mark inserted instrs as meta */
    if (in == NULL)
        in = instrlist_first(ilist);
    else
        in = instr_get_next(in);

    while (in != where) {
        instr_set_ok_to_mangle(in, false);
        in = instr_get_next(in);
    }

    return dstack_offs;
}
Example #29
0
int
impl::app::run(int argc, char* const* argv)
{
    PRE(argc > 0);
    PRE(argv != NULL);

    m_argc = argc;
    m_argv = argv;

    m_argv0 = m_argv[0];

    m_prog_name = std::strrchr(m_argv[0], '/');
    if (m_prog_name == NULL)
        m_prog_name = m_argv[0];
    else
        m_prog_name++;

    // Libtool workaround: if running from within the source tree (binaries
    // that are not installed yet), skip the "lt-" prefix added to files in
    // the ".libs" directory to show the real (not temporary) name.
    if (std::strncmp(m_prog_name, "lt-", 3) == 0)
        m_prog_name += 3;

    const std::string bug =
        std::string("This is probably a bug in ") + m_prog_name +
        " or one of the libraries it uses.  Please report this problem to "
        PACKAGE_BUGREPORT " and provide as many details as possible "
        "describing how you got to this condition.";

    int errcode;
    try {
        int oldargc = m_argc;

        process_options();

        if (m_hflag) {
            INV(m_use_ui);
            if (oldargc != 2)
                throw usage_error("-h must be given alone.");

            usage(std::cout);
            errcode = EXIT_SUCCESS;
        } else
            errcode = main();
    } catch (const usage_error& e) {
        if (m_use_ui) {
            std::cerr << ui::format_error(m_prog_name, e.what()) << "\n"
                      << ui::format_info(m_prog_name, std::string("Type `") +
                                         m_prog_name + " -h' for more details.")
                      << "\n";
        } else {
            std::cerr << m_prog_name << ": ERROR: " << e.what() << "\n";
            std::cerr << m_prog_name << ": See " << m_manpage << " for usage "
                "details.\n";
        }
        errcode = EXIT_FAILURE;
    } catch (const std::runtime_error& e) {
        if (m_use_ui) {
            std::cerr << ui::format_error(m_prog_name, std::string(e.what()))
                      << "\n";
        } else {
            std::cerr << m_prog_name << ": ERROR: " << e.what() << "\n";
        }
        errcode = EXIT_FAILURE;
    } catch (const std::exception& e) {
        if (m_use_ui) {
            std::cerr << ui::format_error(m_prog_name, std::string("Caught "
                "unexpected error: ") + e.what() + "\n" + bug) << "\n";
        } else {
            std::cerr << m_prog_name << ": ERROR: Caught unexpected error: "
                      << e.what() << "\n";
        }
        errcode = EXIT_FAILURE;
    } catch (...) {
        if (m_use_ui) {
            std::cerr << ui::format_error(m_prog_name, std::string("Caught "
                "unknown error\n") + bug) << "\n";
        } else {
            std::cerr << m_prog_name << ": ERROR: Caught unknown error\n";
        }
        errcode = EXIT_FAILURE;
    }
    return errcode;
}
Example #30
0
int
atf_process_child_stdout(atf_process_child_t *c)
{
    PRE(c->m_stdout != -1);
    return c->m_stdout;
}