void DynamicLimit::init(float k, Type t, uint32 uLimit) { resetRun(); std::memset(&adjust, 0, sizeof(adjust)); adjust.limit = uLimit; adjust.rk = k; adjust.type = t; }
bool VMCSingleOMP::run() { resetRun(); //start the main estimator Estimators->start(nBlocks); #pragma omp parallel { int now=0; #pragma omp for for(int ip=0; ip<NumThreads; ++ip) Movers[ip]->startRun(nBlocks,false); for(int block=0;block<nBlocks; ++block) { #pragma omp for for(int ip=0; ip<NumThreads; ++ip) { IndexType updatePeriod=(QMCDriverMode[QMC_UPDATE_MODE])?Period4CheckProperties:(nBlocks+1)*nSteps; //assign the iterators and resuse them MCWalkerConfiguration::iterator wit(W.begin()+wPerNode[ip]), wit_end(W.begin()+wPerNode[ip+1]); Movers[ip]->startBlock(nSteps); int now_loc=now; for(int step=0; step<nSteps;++step) { Movers[ip]->advanceWalkers(wit,wit_end,false); Movers[ip]->accumulate(wit,wit_end); ++now_loc; if(now_loc%updatePeriod==0) Movers[ip]->updateWalkers(wit,wit_end); if(now_loc%myPeriod4WalkerDump==0) wClones[ip]->saveEnsemble(wit,wit_end); } Movers[ip]->stopBlock(); }//end-of-parallel for //increase now now+=nSteps; #pragma omp master { CurrentStep+=nSteps; Estimators->stopBlock(estimatorClones); recordBlock(block+1); }//end of mater }//block }//end of parallel Estimators->stop(estimatorClones); //copy back the random states for(int ip=0; ip<NumThreads; ++ip) *(RandomNumberControl::Children[ip])=*(Rng[ip]); //finalize a qmc section return finalize(nBlocks); }
// // Perform resetRun on all the reset commands in the list, using // initiator and initiator_type void resetRunOn(LIST *list, void *initiator, int initiator_type, const char *locale) { if(listSize(list) > 0) { LIST_ITERATOR *list_i = newListIterator(list); RESET_DATA *reset = NULL; ITERATE_LIST(reset, list_i) resetRun(reset, initiator, initiator_type, locale); deleteListIterator(list_i); } }
bool VMCSingle::run() { resetRun(); Mover->startRun(nBlocks,true); IndexType block = 0; IndexType nAcceptTot = 0; IndexType nRejectTot = 0; do { Mover->startBlock(nSteps); IndexType step = 0; do { ++step;++CurrentStep; Mover->advanceWalkers(W.begin(),W.end(),true); //step==nSteps); Estimators->accumulate(W); //save walkers for optimization if(QMCDriverMode[QMC_OPTIMIZE]&&CurrentStep%Period4WalkerDump==0) W.saveEnsemble(); } while(step<nSteps); Mover->stopBlock(); nAcceptTot += Mover->nAccept; nRejectTot += Mover->nReject; ++block; recordBlock(block); ////periodically re-evaluate everything for pbyp //if(QMCDriverMode[QMC_UPDATE_MODE] && CurrentStep%100 == 0) // Mover->updateWalkers(W.begin(),W.end()); } while(block<nBlocks); Mover->stopRun(); //finalize a qmc section return finalize(block); }
bool VMCcuda::run() { if (UseDrift == "yes") return runWithDrift(); resetRun(); IndexType block = 0; IndexType nAcceptTot = 0; IndexType nRejectTot = 0; IndexType updatePeriod= (QMCDriverMode[QMC_UPDATE_MODE]) ? Period4CheckProperties : (nBlocks+1)*nSteps; int nat = W.getTotalNum(); int nw = W.getActiveWalkers(); vector<RealType> LocalEnergy(nw); vector<PosType> delpos(nw); vector<PosType> newpos(nw); vector<ValueType> ratios(nw); vector<GradType> oldG(nw), newG(nw); vector<ValueType> oldL(nw), newL(nw); vector<Walker_t*> accepted(nw); Matrix<ValueType> lapl(nw, nat); Matrix<GradType> grad(nw, nat); double Esum; // First do warmup steps for (int step=0; step<myWarmupSteps; step++) { for(int iat=0; iat<nat; ++iat) { //create a 3N-Dimensional Gaussian with variance=1 makeGaussRandomWithEngine(delpos,Random); for(int iw=0; iw<nw; ++iw) { PosType G = W[iw]->Grad[iat]; newpos[iw]=W[iw]->R[iat] + m_sqrttau*delpos[iw]; ratios[iw] = 1.0; } W.proposeMove_GPU(newpos, iat); Psi.ratio(W,iat,ratios,newG, newL); accepted.clear(); vector<bool> acc(nw, false); for(int iw=0; iw<nw; ++iw) { if(ratios[iw]*ratios[iw] > Random()) { accepted.push_back(W[iw]); nAccept++; W[iw]->R[iat] = newpos[iw]; acc[iw] = true; } else nReject++; } W.acceptMove_GPU(acc); if (accepted.size()) Psi.update(accepted,iat); } } do { IndexType step = 0; nAccept = nReject = 0; Esum = 0.0; Estimators->startBlock(nSteps); do { ++step; ++CurrentStep; for (int isub=0; isub<nSubSteps; isub++) { for(int iat=0; iat<nat; ++iat) { //create a 3N-Dimensional Gaussian with variance=1 makeGaussRandomWithEngine(delpos,Random); for(int iw=0; iw<nw; ++iw) { PosType G = W[iw]->Grad[iat]; newpos[iw]=W[iw]->R[iat] + m_sqrttau*delpos[iw]; ratios[iw] = 1.0; } W.proposeMove_GPU(newpos, iat); Psi.ratio(W,iat,ratios,newG, newL); accepted.clear(); vector<bool> acc(nw, false); for(int iw=0; iw<nw; ++iw) { if(ratios[iw]*ratios[iw] > Random()) { accepted.push_back(W[iw]); nAccept++; W[iw]->R[iat] = newpos[iw]; acc[iw] = true; } else nReject++; } W.acceptMove_GPU(acc); if (accepted.size()) Psi.update(accepted,iat); } } Psi.gradLapl(W, grad, lapl); H.evaluate (W, LocalEnergy); if (myPeriod4WalkerDump && (CurrentStep % myPeriod4WalkerDump)==0) W.saveEnsemble(); Estimators->accumulate(W); } while(step<nSteps); Psi.recompute(W); // vector<RealType> logPsi(W.WalkerList.size(), 0.0); // Psi.evaluateLog(W, logPsi); double accept_ratio = (double)nAccept/(double)(nAccept+nReject); Estimators->stopBlock(accept_ratio); nAcceptTot += nAccept; nRejectTot += nReject; ++block; recordBlock(block); } while(block<nBlocks); //Mover->stopRun(); //finalize a qmc section return finalize(block); }
bool VMCcuda::runWithDrift() { resetRun(); IndexType block = 0; IndexType nAcceptTot = 0; IndexType nRejectTot = 0; int nat = W.getTotalNum(); int nw = W.getActiveWalkers(); vector<RealType> LocalEnergy(nw), oldScale(nw), newScale(nw); vector<PosType> delpos(nw); vector<PosType> dr(nw); vector<PosType> newpos(nw); vector<ValueType> ratios(nw), rplus(nw), rminus(nw); vector<PosType> oldG(nw), newG(nw); vector<ValueType> oldL(nw), newL(nw); vector<Walker_t*> accepted(nw); Matrix<ValueType> lapl(nw, nat); Matrix<GradType> grad(nw, nat); // First, do warmup steps for (int step=0; step<myWarmupSteps; step++) { for(int iat=0; iat<nat; iat++) { Psi.getGradient (W, iat, oldG); //create a 3N-Dimensional Gaussian with variance=1 makeGaussRandomWithEngine(delpos,Random); for(int iw=0; iw<nw; iw++) { oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]); dr[iw] = (m_sqrttau*delpos[iw]) + (oldScale[iw]*oldG[iw]); newpos[iw]=W[iw]->R[iat] + dr[iw]; ratios[iw] = 1.0; } W.proposeMove_GPU(newpos, iat); Psi.ratio(W,iat,ratios,newG, newL); accepted.clear(); vector<bool> acc(nw, false); for(int iw=0; iw<nw; ++iw) { PosType drOld = newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]); RealType logGf = -m_oneover2tau * dot(drOld, drOld); newScale[iw] = getDriftScale(m_tauovermass,newG[iw]); PosType drNew = (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat]; RealType logGb = -m_oneover2tau * dot(drNew, drNew); RealType x = logGb - logGf; RealType prob = ratios[iw]*ratios[iw]*std::exp(x); if(Random() < prob) { accepted.push_back(W[iw]); nAccept++; W[iw]->R[iat] = newpos[iw]; acc[iw] = true; } else nReject++; } W.acceptMove_GPU(acc); if (accepted.size()) Psi.update(accepted,iat); } } // Now do data collection steps do { IndexType step = 0; nAccept = nReject = 0; Estimators->startBlock(nSteps); do { step++; CurrentStep++; for (int isub=0; isub<nSubSteps; isub++) { for(int iat=0; iat<nat; iat++) { Psi.getGradient (W, iat, oldG); //create a 3N-Dimensional Gaussian with variance=1 makeGaussRandomWithEngine(delpos,Random); for(int iw=0; iw<nw; iw++) { oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]); dr[iw] = (m_sqrttau*delpos[iw]) + (oldScale[iw]*oldG[iw]); newpos[iw]=W[iw]->R[iat] + dr[iw]; ratios[iw] = 1.0; } W.proposeMove_GPU(newpos, iat); Psi.ratio(W,iat,ratios,newG, newL); accepted.clear(); vector<bool> acc(nw, false); for(int iw=0; iw<nw; ++iw) { PosType drOld = newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]); // if (dot(drOld, drOld) > 25.0) // cerr << "Large drift encountered! Old drift = " << drOld << endl; RealType logGf = -m_oneover2tau * dot(drOld, drOld); newScale[iw] = getDriftScale(m_tauovermass,newG[iw]); PosType drNew = (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat]; // if (dot(drNew, drNew) > 25.0) // cerr << "Large drift encountered! Drift = " << drNew << endl; RealType logGb = -m_oneover2tau * dot(drNew, drNew); RealType x = logGb - logGf; RealType prob = ratios[iw]*ratios[iw]*std::exp(x); if(Random() < prob) { accepted.push_back(W[iw]); nAccept++; W[iw]->R[iat] = newpos[iw]; acc[iw] = true; } else nReject++; } W.acceptMove_GPU(acc); if (accepted.size()) Psi.update(accepted,iat); } // cerr << "Rank = " << myComm->rank() << // " CurrentStep = " << CurrentStep << " isub = " << isub << endl; } Psi.gradLapl(W, grad, lapl); H.evaluate (W, LocalEnergy); if (myPeriod4WalkerDump && (CurrentStep % myPeriod4WalkerDump)==0) W.saveEnsemble(); Estimators->accumulate(W); } while(step<nSteps); Psi.recompute(W); double accept_ratio = (double)nAccept/(double)(nAccept+nReject); Estimators->stopBlock(accept_ratio); nAcceptTot += nAccept; nRejectTot += nReject; ++block; recordBlock(block); } while(block<nBlocks); //finalize a qmc section if (!myComm->rank()) gpu::cuda_memory_manager.report(); return finalize(block); }
void DynamicLimit::reset() { std::memset(&global, 0, sizeof(global)); resetRun(); }
bool DMCcuda::run() { bool NLmove = NonLocalMove == "yes"; bool scaleweight = ScaleWeight == "yes"; if (NLmove) app_log() << " Using Casula nonlocal moves in DMCcuda.\n"; if (scaleweight) app_log() << " Scaling weight per Umrigar/Nightengale.\n"; resetRun(); Mover->MaxAge = 1; IndexType block = 0; IndexType nAcceptTot = 0; IndexType nRejectTot = 0; int nat = W.getTotalNum(); int nw = W.getActiveWalkers(); vector<RealType> LocalEnergy(nw), LocalEnergyOld(nw), oldScale(nw), newScale(nw); vector<PosType> delpos(nw); vector<PosType> dr(nw); vector<PosType> newpos(nw); vector<ValueType> ratios(nw), rplus(nw), rminus(nw), R2prop(nw), R2acc(nw); vector<PosType> oldG(nw), newG(nw); vector<ValueType> oldL(nw), newL(nw); vector<Walker_t*> accepted(nw); Matrix<ValueType> lapl(nw, nat); Matrix<GradType> grad(nw, nat); vector<ValueType> V2(nw), V2bar(nw); vector<vector<NonLocalData> > Txy(nw); for (int iw=0; iw<nw; iw++) W[iw]->Weight = 1.0; do { IndexType step = 0; nAccept = nReject = 0; Estimators->startBlock(nSteps); do { step++; CurrentStep++; nw = W.getActiveWalkers(); ResizeTimer.start(); LocalEnergy.resize(nw); oldScale.resize(nw); newScale.resize(nw); delpos.resize(nw); dr.resize(nw); newpos.resize(nw); ratios.resize(nw); rplus.resize(nw); rminus.resize(nw); oldG.resize(nw); newG.resize(nw); oldL.resize(nw); newL.resize(nw); accepted.resize(nw); lapl.resize(nw, nat); grad.resize(nw, nat); R2prop.resize(nw,0.0); R2acc.resize(nw,0.0); V2.resize(nw,0.0); V2bar.resize(nw,0.0); W.updateLists_GPU(); ResizeTimer.stop(); if (NLmove) { Txy.resize(nw); for (int iw=0; iw<nw; iw++) { Txy[iw].clear(); Txy[iw].push_back(NonLocalData(-1, 1.0, PosType())); } } for (int iw=0; iw<nw; iw++) W[iw]->Age++; DriftDiffuseTimer.start(); for(int iat=0; iat<nat; iat++) { Psi.getGradient (W, iat, oldG); //create a 3N-Dimensional Gaussian with variance=1 makeGaussRandomWithEngine(delpos,Random); for(int iw=0; iw<nw; iw++) { delpos[iw] *= m_sqrttau; oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]); dr[iw] = delpos[iw] + (oldScale[iw]*oldG[iw]); newpos[iw]=W[iw]->R[iat] + dr[iw]; ratios[iw] = 1.0; R2prop[iw] += dot(delpos[iw], delpos[iw]); } W.proposeMove_GPU(newpos, iat); Psi.ratio(W,iat,ratios,newG, newL); accepted.clear(); vector<bool> acc(nw, false); for(int iw=0; iw<nw; ++iw) { PosType drOld = newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]); RealType logGf = -m_oneover2tau * dot(drOld, drOld); newScale[iw] = getDriftScale(m_tauovermass,newG[iw]); PosType drNew = (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat]; RealType logGb = -m_oneover2tau * dot(drNew, drNew); RealType x = logGb - logGf; RealType prob = ratios[iw]*ratios[iw]*std::exp(x); if(Random() < prob && ratios[iw] > 0.0) { accepted.push_back(W[iw]); nAccept++; W[iw]->R[iat] = newpos[iw]; W[iw]->Age = 0; acc[iw] = true; R2acc[iw] += dot(delpos[iw], delpos[iw]); V2[iw] += m_tauovermass * m_tauovermass * dot(newG[iw],newG[iw]); V2bar[iw] += newScale[iw] * newScale[iw] * dot(newG[iw],newG[iw]); } else { nReject++; V2[iw] += m_tauovermass * m_tauovermass * dot(oldG[iw],oldG[iw]); V2bar[iw] += oldScale[iw] * oldScale[iw] * dot(oldG[iw],oldG[iw]); } } W.acceptMove_GPU(acc); if (accepted.size()) Psi.update(accepted,iat); } DriftDiffuseTimer.stop(); // Psi.recompute(W, false); Psi.gradLapl(W, grad, lapl); HTimer.start(); if (NLmove) H.evaluate (W, LocalEnergy, Txy); else H.evaluate (W, LocalEnergy); HTimer.stop(); // for (int iw=0; iw<nw; iw++) { // branchEngine->clampEnergy(LocalEnergy[iw]); // W[iw]->getPropertyBase()[LOCALENERGY] = LocalEnergy[iw]; // } if (CurrentStep == 1) LocalEnergyOld = LocalEnergy; if (NLmove) { // Now, attempt nonlocal move accepted.clear(); vector<int> iatList; vector<PosType> accPos; for (int iw=0; iw<nw; iw++) { /// HACK HACK HACK // if (LocalEnergy[iw] < -2300.0) { // cerr << "Walker " << iw << " has energy " // << LocalEnergy[iw] << endl;; // double maxWeight = 0.0; // int elMax = -1; // PosType posMax; // for (int j=1; j<Txy[iw].size(); j++) // if (std::fabs(Txy[iw][j].Weight) > std::fabs(maxWeight)) { // maxWeight = Txy[iw][j].Weight; // elMax = Txy[iw][j].PID; // posMax = W[iw]->R[elMax] + Txy[iw][j].Delta; // } // cerr << "Maximum weight is " << maxWeight << " for electron " // << elMax << " at position " << posMax << endl; // PosType unit = W.Lattice.toUnit(posMax); // unit[0] -= round(unit[0]); // unit[1] -= round(unit[1]); // unit[2] -= round(unit[2]); // cerr << "Reduced position = " << unit << endl; // } int ibar = NLop.selectMove(Random(), Txy[iw]); if (ibar) { accepted.push_back(W[iw]); int iat = Txy[iw][ibar].PID; iatList.push_back(iat); accPos.push_back(W[iw]->R[iat] + Txy[iw][ibar].Delta); } } if (accepted.size()) { Psi.ratio(accepted,iatList, accPos, ratios, newG, newL); Psi.update(accepted,iatList); for (int i=0; i<accepted.size(); i++) accepted[i]->R[iatList[i]] = accPos[i]; W.NLMove_GPU (accepted, accPos, iatList); // HACK HACK HACK // Recompute the kinetic energy // Psi.gradLapl(W, grad, lapl); // H.evaluate (W, LocalEnergy); //W.copyWalkersToGPU(); } } // Now branch BranchTimer.start(); for (int iw=0; iw<nw; iw++) { RealType v2=0.0, v2bar=0.0; for(int iat=0; iat<nat; iat++) { v2 += dot(W.G[iat],W.G[iat]); RealType newscale = getDriftScale(m_tauovermass,newG[iw]); v2 += m_tauovermass * m_tauovermass * dot(newG[iw],newG[iw]); v2bar += newscale * newscale * dot(newG[iw],newG[iw]); } //RealType scNew = std::sqrt(V2bar[iw] / V2[iw]); RealType scNew = std::sqrt(v2bar/v2); RealType scOld = (CurrentStep == 1) ? scNew : W[iw]->getPropertyBase()[DRIFTSCALE]; W[iw]->getPropertyBase()[DRIFTSCALE] = scNew; // fprintf (stderr, "iw = %d scNew = %1.8f scOld = %1.8f\n", iw, scNew, scOld); RealType tauRatio = R2acc[iw] / R2prop[iw]; if (tauRatio < 0.5) cerr << " tauRatio = " << tauRatio << endl; RealType taueff = m_tauovermass * tauRatio; if (scaleweight) W[iw]->Weight *= branchEngine->branchWeightTau (LocalEnergy[iw], LocalEnergyOld[iw], scNew, scOld, taueff); else W[iw]->Weight *= branchEngine->branchWeight (LocalEnergy[iw], LocalEnergyOld[iw]); W[iw]->getPropertyBase()[R2ACCEPTED] = R2acc[iw]; W[iw]->getPropertyBase()[R2PROPOSED] = R2prop[iw]; } Mover->setMultiplicity(W.begin(), W.end()); branchEngine->branch(CurrentStep,W); nw = W.getActiveWalkers(); LocalEnergyOld.resize(nw); for (int iw=0; iw<nw; iw++) LocalEnergyOld[iw] = W[iw]->getPropertyBase()[LOCALENERGY]; BranchTimer.stop(); } while(step<nSteps); Psi.recompute(W, true); double accept_ratio = (double)nAccept/(double)(nAccept+nReject); Estimators->stopBlock(accept_ratio); nAcceptTot += nAccept; nRejectTot += nReject; ++block; recordBlock(block); } while(block<nBlocks); //finalize a qmc section return finalize(block); }
bool DMCcuda::runWithNonlocal() { resetRun(); Mover->MaxAge = 1; IndexType block = 0; IndexType nAcceptTot = 0; IndexType nRejectTot = 0; int nat = W.getTotalNum(); int nw = W.getActiveWalkers(); vector<RealType> LocalEnergy(nw), LocalEnergyOld(nw), oldScale(nw), newScale(nw); vector<PosType> delpos(nw); vector<PosType> dr(nw); vector<PosType> newpos(nw); vector<ValueType> ratios(nw), rplus(nw), rminus(nw), R2prop(nw), R2acc(nw); vector<PosType> oldG(nw), newG(nw); vector<ValueType> oldL(nw), newL(nw); vector<Walker_t*> accepted(nw); Matrix<ValueType> lapl(nw, nat); Matrix<GradType> grad(nw, nat); vector<vector<NonLocalData> > Txy(nw); for (int iw=0; iw<nw; iw++) W[iw]->Weight = 1.0; do { IndexType step = 0; nAccept = nReject = 0; Estimators->startBlock(nSteps); do { step++; CurrentStep++; nw = W.getActiveWalkers(); LocalEnergy.resize(nw); oldScale.resize(nw); newScale.resize(nw); delpos.resize(nw); dr.resize(nw); newpos.resize(nw); ratios.resize(nw); rplus.resize(nw); rminus.resize(nw); oldG.resize(nw); newG.resize(nw); oldL.resize(nw); newL.resize(nw); accepted.resize(nw); lapl.resize(nw, nat); grad.resize(nw, nat); R2prop.resize(nw,0.0); R2acc.resize(nw,0.0); W.updateLists_GPU(); Txy.resize(nw); for (int iw=0; iw<nw; iw++) { Txy[iw].clear(); Txy[iw].push_back(NonLocalData(-1, 1.0, PosType())); W[iw]->Age++; } for(int iat=0; iat<nat; iat++) { Psi.getGradient (W, iat, oldG); //create a 3N-Dimensional Gaussian with variance=1 makeGaussRandomWithEngine(delpos,Random); for(int iw=0; iw<nw; iw++) { delpos[iw] *= m_sqrttau; oldScale[iw] = getDriftScale(m_tauovermass,oldG[iw]); dr[iw] = delpos[iw] + (oldScale[iw]*oldG[iw]); newpos[iw]=W[iw]->R[iat] + dr[iw]; ratios[iw] = 1.0; R2prop[iw] += dot(delpos[iw], delpos[iw]); } W.proposeMove_GPU(newpos, iat); Psi.ratio(W,iat,ratios,newG, newL); accepted.clear(); vector<bool> acc(nw, false); for(int iw=0; iw<nw; ++iw) { PosType drOld = newpos[iw] - (W[iw]->R[iat] + oldScale[iw]*oldG[iw]); RealType logGf = -m_oneover2tau * dot(drOld, drOld); newScale[iw] = getDriftScale(m_tauovermass,newG[iw]); PosType drNew = (newpos[iw] + newScale[iw]*newG[iw]) - W[iw]->R[iat]; RealType logGb = -m_oneover2tau * dot(drNew, drNew); RealType x = logGb - logGf; RealType prob = ratios[iw]*ratios[iw]*std::exp(x); if(Random() < prob && ratios[iw] > 0.0) { accepted.push_back(W[iw]); nAccept++; W[iw]->R[iat] = newpos[iw]; W[iw]->Age = 0; acc[iw] = true; R2acc[iw] += dot(delpos[iw], delpos[iw]); } else nReject++; } W.acceptMove_GPU(acc); if (accepted.size()) Psi.update(accepted,iat); } for (int iw=0; iw < nw; iw++) if (W[iw]->Age) cerr << "Encountered stuck walker with iw=" << iw << endl; // Psi.recompute(W, false); Psi.gradLapl(W, grad, lapl); H.evaluate (W, LocalEnergy, Txy); if (CurrentStep == 1) LocalEnergyOld = LocalEnergy; // Now, attempt nonlocal move accepted.clear(); vector<int> iatList; vector<PosType> accPos; for (int iw=0; iw<nw; iw++) { int ibar = NLop.selectMove(Random(), Txy[iw]); // cerr << "Txy[iw].size() = " << Txy[iw].size() << endl; if (ibar) { accepted.push_back(W[iw]); int iat = Txy[iw][ibar].PID; iatList.push_back(iat); accPos.push_back(W[iw]->R[iat] + Txy[iw][ibar].Delta); } } if (accepted.size()) { // W.proposeMove_GPU(newpos, iatList); Psi.ratio(accepted,iatList, accPos, ratios, newG, newL); Psi.update(accepted,iatList); for (int i=0; i<accepted.size(); i++) accepted[i]->R[iatList[i]] = accPos[i]; W.copyWalkersToGPU(); } // Now branch for (int iw=0; iw<nw; iw++) { W[iw]->Weight *= branchEngine->branchWeight(LocalEnergy[iw], LocalEnergyOld[iw]); W[iw]->getPropertyBase()[R2ACCEPTED] = R2acc[iw]; W[iw]->getPropertyBase()[R2PROPOSED] = R2prop[iw]; } Mover->setMultiplicity(W.begin(), W.end()); branchEngine->branch(CurrentStep,W); nw = W.getActiveWalkers(); LocalEnergyOld.resize(nw); for (int iw=0; iw<nw; iw++) LocalEnergyOld[iw] = W[iw]->getPropertyBase()[LOCALENERGY]; } while(step<nSteps); Psi.recompute(W, true); double accept_ratio = (double)nAccept/(double)(nAccept+nReject); Estimators->stopBlock(accept_ratio); nAcceptTot += nAccept; nRejectTot += nReject; ++block; recordBlock(block); } while(block<nBlocks); //finalize a qmc section return finalize(block); }
bool WFMCSingleOMP::run() { resetRun(); //start the main estimator Estimators->start(nBlocks); ///Load a single walkers position into the walker. MCWalkerConfiguration Keeper(W); Keeper.createWalkers(W.begin(),W.end()); MCWalkerConfiguration::iterator Kit=(Keeper.begin()), Kit_end(Keeper.end()); int block=0; while ((Kit!=Kit_end)&&(nBlocks>block)) { MCWalkerConfiguration::iterator Wit(W.begin()), Wit_end(W.end()); while ((Wit!=Wit_end)) { (*Wit)->R=(*Kit)->R; (*Wit)->G=(*Kit)->G; (*Wit)->L=(*Kit)->L; //(*Wit)->Drift=(*Kit)->Drift; (*Wit)->reset(); (*Wit)->resetPropertyHistory(); ++Wit; } #pragma omp parallel for for (int ip=0; ip<NumThreads; ++ip) Movers[ip]->initWalkers(W.begin()+wPerNode[ip],W.begin()+wPerNode[ip+1]); Wit=W.begin(); while ((Wit!=Wit_end)) { // app_log()<<std::exp((*Wit)->Properties(LOGPSI))<<endl; (*Wit)->PropertyHistory[0][0]=std::exp((*Wit)->Properties(LOGPSI)); ++Wit; } #pragma omp parallel { #pragma omp for for (int ip=0; ip<NumThreads; ++ip) Movers[ip]->startRun(nBlocks,false); #pragma omp for for (int ip=0; ip<NumThreads; ++ip) { //assign the iterators and resuse them MCWalkerConfiguration::iterator wit(W.begin()+wPerNode[ip]), wit_end(W.begin()+wPerNode[ip+1]); Movers[ip]->startBlock(nSteps); for (int step=0; step<nSteps; ++step) { Movers[ip]->advanceWalkers(wit,wit_end,false); // Movers[ip]->updateWalkers(wit,wit_end); // wClones[ip]->saveEnsemble(wit,wit_end); } Movers[ip]->accumulate(wit,wit_end); Movers[ip]->stopBlock(); } #pragma omp master { Estimators->stopBlock(estimatorClones); recordBlock(block+1); block++; ++Kit; } } }//end of parallel Estimators->stop(estimatorClones); //copy back the random states for (int ip=0; ip<NumThreads; ++ip) *(RandomNumberControl::Children[ip])=*(Rng[ip]); //finalize a qmc section return finalize(nBlocks); }
bool VMCSingleOMP::run() { resetRun(); //start the main estimator Estimators->start(nBlocks); for (int ip=0; ip<NumThreads; ++ip) Movers[ip]->startRun(nBlocks,false); Traces->startRun(nBlocks,traceClones); const bool has_collectables=W.Collectables.size(); ADIOS_PROFILE::profile_adios_init(nBlocks); for (int block=0; block<nBlocks; ++block) { ADIOS_PROFILE::profile_adios_start_comp(block); #pragma omp parallel { int ip=omp_get_thread_num(); //IndexType updatePeriod=(QMCDriverMode[QMC_UPDATE_MODE])?Period4CheckProperties:(nBlocks+1)*nSteps; IndexType updatePeriod=(QMCDriverMode[QMC_UPDATE_MODE])?Period4CheckProperties:0; //assign the iterators and resuse them MCWalkerConfiguration::iterator wit(W.begin()+wPerNode[ip]), wit_end(W.begin()+wPerNode[ip+1]); Movers[ip]->startBlock(nSteps); int now_loc=CurrentStep; RealType cnorm=1.0/static_cast<RealType>(wPerNode[ip+1]-wPerNode[ip]); for (int step=0; step<nSteps; ++step) { Movers[ip]->set_step(now_loc); //collectables are reset, it is accumulated while advancing walkers wClones[ip]->resetCollectables(); Movers[ip]->advanceWalkers(wit,wit_end,false); if(has_collectables) wClones[ip]->Collectables *= cnorm; Movers[ip]->accumulate(wit,wit_end); ++now_loc; //if (updatePeriod&& now_loc%updatePeriod==0) Movers[ip]->updateWalkers(wit,wit_end); if (Period4WalkerDump&& now_loc%Period4WalkerDump==0) wClones[ip]->saveEnsemble(wit,wit_end); // if(storeConfigs && (now_loc%storeConfigs == 0)) // ForwardWalkingHistory.storeConfigsForForwardWalking(*wClones[ip]); } Movers[ip]->stopBlock(false); }//end-of-parallel for //Estimators->accumulateCollectables(wClones,nSteps); CurrentStep+=nSteps; Estimators->stopBlock(estimatorClones); ADIOS_PROFILE::profile_adios_end_comp(block); ADIOS_PROFILE::profile_adios_start_trace(block); Traces->write_buffers(traceClones, block); ADIOS_PROFILE::profile_adios_end_trace(block); ADIOS_PROFILE::profile_adios_start_checkpoint(block); if(storeConfigs) recordBlock(block); ADIOS_PROFILE::profile_adios_end_checkpoint(block); }//block ADIOS_PROFILE::profile_adios_finalize(myComm, nBlocks); Estimators->stop(estimatorClones); for (int ip=0; ip<NumThreads; ++ip) Movers[ip]->stopRun2(); Traces->stopRun(); //copy back the random states for (int ip=0; ip<NumThreads; ++ip) *(RandomNumberControl::Children[ip])=*(Rng[ip]); ///write samples to a file bool wrotesamples=DumpConfig; if(DumpConfig) { wrotesamples=W.dumpEnsemble(wClones,wOut,myComm->size(),nBlocks); if(wrotesamples) app_log() << " samples are written to the config.h5" << endl; } //finalize a qmc section return finalize(nBlocks,!wrotesamples); }