コード例 #1
0
ファイル: FWSingleOMP.cpp プロジェクト: digideskio/qmcpack
  bool FWSingleOMP::run() 
  {
    hdf_WGT_data.setFileName(xmlrootName);
    hdf_OBS_data.setFileName(xmlrootName);

    if (doWeights==1)
    {
      fillIDMatrix();        
      hdf_WGT_data.makeFile();
      hdf_WGT_data.openFile();
      hdf_WGT_data.addFW(0);
      for (int i=0;i<Weights.size();i++) hdf_WGT_data.addStep(i,Weights[i]);
      hdf_WGT_data.closeFW();
      hdf_WGT_data.closeFile();
      for(int ill=1;ill<weightLength;ill++)
      {
        transferParentsOneGeneration();
        FWOneStep();
        //       WeightHistory.push_back(Weights);
        hdf_WGT_data.openFile();
        hdf_WGT_data.addFW(ill);
        for (int i=0;i<Weights.size();i++) hdf_WGT_data.addStep(i,Weights[i]);
        hdf_WGT_data.closeFW();
        hdf_WGT_data.closeFile();
      }
    }
    else
    {
      fillIDMatrix();
      //           find weight length from the weight file
      hid_t f_file = H5Fopen(hdf_WGT_data.getFileName().c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
      hsize_t numGrps = 0;
      H5Gget_num_objs(f_file, &numGrps);
      weightLength = static_cast<int> (numGrps)-1;
      if (H5Fclose(f_file)>-1) f_file=-1;
      if (verbose>0) app_log()<<" weightLength "<<weightLength<<endl;
    }
    if (verbose>0) app_log()<<" Done Computing Weights"<<endl;


    if (doObservables==1)
    {
      int nprops = H.sizeOfObservables();//local energy, local potnetial and all hamiltonian elements
      int FirstHamiltonian = H.startIndex();
      //     vector<vector<vector<RealType> > > savedValues;

      int nelectrons = W[0]->R.size();
      int nfloats=OHMMS_DIM*nelectrons;


      //     W.clearEnsemble();
      makeClones(W,Psi,H);

      vector<ForwardWalkingData* > FWvector;
      for(int ip=0; ip<NumThreads; ip++) FWvector.push_back(new ForwardWalkingData(nelectrons));


      if (myComm->rank()==0) hdf_OBS_data.makeFile();
      hdf_float_data.openFile(fname.str());

      for(int step=0;step<numSteps;step++)
      {
        hdf_float_data.setStep(step);


        vector<RealType> stepObservables(walkersPerBlock[step]*(nprops+2), 0);
        for(int wstep=0; wstep<walkersPerBlock[step];)
        {
          vector<float> ThreadsCoordinate(NumThreads*nfloats);
          int nwalkthread = hdf_float_data.getFloat(wstep*nfloats, (wstep+NumThreads)*nfloats, ThreadsCoordinate) / nfloats;
          //         for(int j=0;j<ThreadsCoordinate.size();j++)cout<<ThreadsCoordinate[j]<<" ";
          //         cout<<endl;
#pragma omp parallel for
          for(int ip=0; ip<nwalkthread; ip++) 
          {
            vector<float> SINGLEcoordinate(0);
            vector<float>::iterator TCB1(ThreadsCoordinate.begin()+ip*nfloats), TCB2(ThreadsCoordinate.begin()+(1+ip)*nfloats);

            SINGLEcoordinate.insert(SINGLEcoordinate.begin(),TCB1,TCB2);
            FWvector[ip]->fromFloat(SINGLEcoordinate);
            wClones[ip]->R=FWvector[ip]->Pos;
            wClones[ip]->update();
            RealType logpsi(psiClones[ip]->evaluateLog(*wClones[ip]));
            RealType eloc=hClones[ip]->evaluate( *wClones[ip] );
            hClones[ip]->auxHevaluate(*wClones[ip]);
            int indx=(wstep+ip)*(nprops+2);
            stepObservables[indx]= eloc;
            stepObservables[indx+1]= hClones[ip]->getLocalPotential();
            for(int i=0;i<nprops;i++) stepObservables[indx+i+2] = hClones[ip]->getObservable(i) ;
          }
          wstep+=nwalkthread;
          for(int ip=0; ip<NumThreads; ip++)  wClones[ip]->resetCollectables();
        }
        hdf_OBS_data.openFile();
        hdf_OBS_data.addStep(step, stepObservables);
        hdf_OBS_data.closeFile();
        //       savedValues.push_back(stepObservables);
        hdf_float_data.endStep();
        if (verbose >1) cout<<"Done with step: "<<step<<endl;
      }
    }


    if(doDat>=1)
    {
      vector<int> Dimensions(4);
      hdf_WGT_data.openFile();
      hdf_OBS_data.openFile();
      Estimators->start(weightLength,1);
      int nprops;
      if (doObservables==1) nprops = H.sizeOfObservables()+2;
      else
      {
        int Noo = hdf_OBS_data.numObsStep(0);
        int Nwl = hdf_WGT_data.numWgtStep(0);
        nprops = Noo/Nwl;
      }
      for(int ill=0;ill<weightLength;ill++)
      {    
        Dimensions[0]=ill;
        Dimensions[1]= nprops ;
        Dimensions[2]=numSteps;
        Dimensions[3]=startStep;
        Estimators->startBlock(1);
        Estimators->accumulate(hdf_OBS_data,hdf_WGT_data,Dimensions);
        Estimators->stopBlock(getNumberOfSamples(ill));
      }
      hdf_OBS_data.closeFile();
      hdf_WGT_data.closeFile();
      Estimators->stop();
    }
    return true;
  }
コード例 #2
0
ファイル: FWSingle.cpp プロジェクト: jyamu/qmc
bool FWSingle::run()
{
  Estimators->start(weightLength,1);
  fillIDMatrix();
  //we do this once because we only want to link parents to parents if we need to
  //     if (verbose>1) app_log()<<" getting weights for generation "<<gensTransferred<<endl;
  vector<vector<vector<int> > > WeightHistory;
  WeightHistory.push_back(Weights);
  for(int ill=1; ill<weightLength; ill++)
  {
    transferParentsOneGeneration();
    FWOneStep();
    WeightHistory.push_back(Weights);
  }
  if (verbose>0)
    app_log()<<" Done Computing Weights"<<endl;
  int nprops = H.sizeOfObservables();//local energy, local potnetial and all hamiltonian elements
  int FirstHamiltonian = H.startIndex();
  vector<vector<vector<RealType> > > savedValues;
  int nelectrons = W[0]->R.size();
  int nfloats=OHMMS_DIM*nelectrons;
  ForwardWalkingData fwer;
  fwer.resize(nelectrons);
  //      MCWalkerConfiguration* savedW = new MCWalkerConfiguration(W);
  for(int step=0; step<numSteps; step++)
  {
    vector<float> ALLcoordinates;
    readInFloat(step,ALLcoordinates);
    vector<float> SINGLEcoordinate(nfloats);
    vector<float>::iterator fgg(ALLcoordinates.begin()), fgg2(ALLcoordinates.begin()+nfloats);
    W.resetCollectables();
    vector<vector<RealType> > stepObservables;
    for(int wstep=0; wstep<walkersPerBlock[step]; wstep++)
    {
      std::copy( fgg,fgg2,SINGLEcoordinate.begin());
      fwer.fromFloat(SINGLEcoordinate);
      W.R=fwer.Pos;
      fgg+=nfloats;
      fgg2+=nfloats;
      W.update();
      RealType logpsi(Psi.evaluateLog(W));
      RealType eloc=H.evaluate( W );
      //             (*W[0]).resetProperty(logpsi,1,eloc);
      H.auxHevaluate(W);
      H.saveProperty(W.getPropertyBase());
      vector<RealType> walkerObservables(nprops+2,0);
      walkerObservables[0]= eloc;
      walkerObservables[1]= H.getLocalPotential();
      const RealType* restrict ePtr = W.getPropertyBase();
      for(int i=0; i<nprops; i++)
        walkerObservables[i+2] = ePtr[FirstHamiltonian+i] ;
      stepObservables.push_back(walkerObservables);
    }
    savedValues.push_back(stepObservables);
  }
  for(int ill=0; ill<weightLength; ill++)
  {
    Estimators->startBlock(1);
    Estimators->accumulate(savedValues,WeightHistory[ill],getNumberOfSamples(ill));
    Estimators->stopBlock(getNumberOfSamples(ill));
  }
  Estimators->stop();
  return true;
}