void QMCCostFunctionOMP::resetPsi(bool final_reset) { if (OptVariables.size() < OptVariablesForPsi.size()) for (int i=0; i<equalVarMap.size(); ++i) OptVariablesForPsi[equalVarMap[i][0]]=OptVariables[equalVarMap[i][1]]; else for (int i=0; i<OptVariables.size(); ++i) OptVariablesForPsi[i]=OptVariables[i]; if (final_reset) { for (int i=0; i<psiClones.size(); ++i) psiClones[i]->stopOptimization(); #pragma omp parallel { int ip = omp_get_thread_num(); MCWalkerConfiguration& wRef(*wClones[ip]); MCWalkerConfiguration::iterator it(wRef.begin()); MCWalkerConfiguration::iterator it_end(wRef.end()); for (; it!=it_end; ++it) (**it).DataSetForDerivatives.clear(); } // is this correct with OMP? // MCWalkerConfiguration::iterator it(W.begin()); // MCWalkerConfiguration::iterator it_end(W.end()); // for (; it!=it_end; ++it) // (**it).DataSetForDerivatives.clear(); } //cout << "######### QMCCostFunctionOMP::resetPsi " << endl; //OptVariablesForPsi.print(cout); //cout << "-------------------------------------- " << endl; Psi.resetParameters(OptVariablesForPsi); for (int i=0; i<psiClones.size(); ++i) psiClones[i]->resetParameters(OptVariablesForPsi); }
extern "C" KDE_EXPORT int kdemain( int argc, char **argv ) { // here we go, construct the Kate version QString kateVersion = KateApp::kateVersion(); KAboutData aboutData ("kate", I18N_NOOP("Kate"), kateVersion.latin1(), I18N_NOOP( "Kate - Advanced Text Editor" ), KAboutData::License_LGPL_V2, I18N_NOOP( "(c) 2000-2005 The Kate Authors" ), 0, "http://kate.kde.org"); aboutData.addAuthor ("Christoph Cullmann", I18N_NOOP("Maintainer"), "*****@*****.**", "http://www.babylon2k.de"); aboutData.addAuthor ("Anders Lund", I18N_NOOP("Core Developer"), "*****@*****.**", "http://www.alweb.dk"); aboutData.addAuthor ("Joseph Wenninger", I18N_NOOP("Core Developer"), "*****@*****.**","http://stud3.tuwien.ac.at/~e9925371"); aboutData.addAuthor ("Hamish Rodda",I18N_NOOP("Core Developer"), "*****@*****.**"); aboutData.addAuthor ("Waldo Bastian", I18N_NOOP( "The cool buffersystem" ), "*****@*****.**" ); aboutData.addAuthor ("Charles Samuels", I18N_NOOP("The Editing Commands"), "*****@*****.**"); aboutData.addAuthor ("Matt Newell", I18N_NOOP("Testing, ..."), "*****@*****.**"); aboutData.addAuthor ("Michael Bartl", I18N_NOOP("Former Core Developer"), "*****@*****.**"); aboutData.addAuthor ("Michael McCallum", I18N_NOOP("Core Developer"), "*****@*****.**"); aboutData.addAuthor ("Jochen Wilhemly", I18N_NOOP( "KWrite Author" ), "*****@*****.**" ); aboutData.addAuthor ("Michael Koch",I18N_NOOP("KWrite port to KParts"), "*****@*****.**"); aboutData.addAuthor ("Christian Gebauer", 0, "*****@*****.**" ); aboutData.addAuthor ("Simon Hausmann", 0, "*****@*****.**" ); aboutData.addAuthor ("Glen Parker",I18N_NOOP("KWrite Undo History, Kspell integration"), "*****@*****.**"); aboutData.addAuthor ("Scott Manson",I18N_NOOP("KWrite XML Syntax highlighting support"), "*****@*****.**"); aboutData.addAuthor ("John Firebaugh",I18N_NOOP("Patches and more"), "*****@*****.**"); aboutData.addAuthor ("Dominik Haumann", I18N_NOOP("Developer & Highlight wizard"), "*****@*****.**"); aboutData.addCredit ("Matteo Merli",I18N_NOOP("Highlighting for RPM Spec-Files, Perl, Diff and more"), "*****@*****.**"); aboutData.addCredit ("Rocky Scaletta",I18N_NOOP("Highlighting for VHDL"), "*****@*****.**"); aboutData.addCredit ("Yury Lebedev",I18N_NOOP("Highlighting for SQL"),""); aboutData.addCredit ("Chris Ross",I18N_NOOP("Highlighting for Ferite"),""); aboutData.addCredit ("Nick Roux",I18N_NOOP("Highlighting for ILERPG"),""); aboutData.addCredit ("Carsten Niehaus", I18N_NOOP("Highlighting for LaTeX"),""); aboutData.addCredit ("Per Wigren", I18N_NOOP("Highlighting for Makefiles, Python"),""); aboutData.addCredit ("Jan Fritz", I18N_NOOP("Highlighting for Python"),""); aboutData.addCredit ("Daniel Naber","",""); aboutData.addCredit ("Roland Pabel",I18N_NOOP("Highlighting for Scheme"),""); aboutData.addCredit ("Cristi Dumitrescu",I18N_NOOP("PHP Keyword/Datatype list"),""); aboutData.addCredit ("Carsten Pfeiffer", I18N_NOOP("Very nice help"), ""); aboutData.addCredit (I18N_NOOP("All people who have contributed and I have forgotten to mention"),"",""); aboutData.setTranslator(I18N_NOOP2("NAME OF TRANSLATORS","Your names"), I18N_NOOP2("EMAIL OF TRANSLATORS","Your emails")); // command line args init and co KCmdLineArgs::init (argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions (options); KCmdLineArgs::addTempFileOption(); KateApp::addCmdLineOptions (); // get our command line args ;) KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); // now, first try to contact running kate instance if needed if ( args->isSet("use") || (::getenv("KATE_PID")!=0) ) { DCOPClient client; client.attach (); // get all attached clients ;) QCStringList allClients = client.registeredApplications(); // search for a kate app client, use the first found QCString kateApp; if ( args->isSet("start") ) { for (unsigned int i=0; i < allClients.count(); i++) { if (allClients[i] == "kate" || allClients[i].left(5) == "kate-") { DCOPRef ref( allClients[i], "KateApplication" ); QString s = ref.call( "session" ); if ( QString(args->getOption("start")) == s ) { kateApp = allClients[i]; break; } } } } else if ( (args->isSet("pid")) || (::getenv("KATE_PID") !=0 ) ) { QCString tryApp; if ( args->isSet("pid") ) tryApp = args->getOption("pid"); else tryApp = ::getenv("KATE_PID"); if ( client.isApplicationRegistered( tryApp.prepend("kate-") ) ) kateApp = tryApp; } else { for (unsigned int i=0; i < allClients.count(); ++i) { if (allClients[i] == "kate" || allClients[i].left(5) == "kate-") { kateApp = allClients[i]; break; } } } // found a matching kate client ;) if (!kateApp.isEmpty()) { kdDebug () << "kate app: " << kateApp << endl; // make kdeinit happy client.registerAs( "kate" ); DCOPRef kRef (kateApp, "KateApplication"); if (args->isSet ("start")) kRef.call( "activateSession", QString (args->getOption("start")) ); QString enc = args->isSet("encoding") ? args->getOption("encoding") : QCString(""); bool tempfileSet = KCmdLineArgs::isTempFileSet(); for (int z=0; z<args->count(); z++) kRef.call( "openURL", args->url(z), enc, tempfileSet ); if( args->isSet( "stdin" ) ) { QTextIStream input(stdin); // set chosen codec QTextCodec *codec = args->isSet("encoding") ? QTextCodec::codecForName(args->getOption("encoding")) : 0; if (codec) input.setCodec (codec); QString line; QString text; do { line = input.readLine(); text.append( line + "\n" ); } while( !line.isNull() ); kRef.call( "openInput", text ); } int line = 0; int column = 0; bool nav = false; if (args->isSet ("line")) { line = args->getOption ("line").toInt(); nav = true; } if (args->isSet ("column")) { column = args->getOption ("column").toInt(); nav = true; } if (nav) kRef.call( "setCursor", line, column ); // since the user tried to open a document, let us assume [s]he // wants to see that document. // ### what to do about the infamous focus stealing prevention? uint mwn = kRef.call("activeMainWindowNumber"); QCString smwn; DCOPRef wRef( kateApp, QCString( "__KateMainWindow#") + smwn.setNum(mwn) ); if ( wRef.call("minimized") ) { if ( wRef.call( "maximized" ) ) wRef.call( "maximize" ); else wRef.call("restore"); } wRef.call( "raise" ); // stop startup notification KStartupInfo::appStarted( ); return 0; } } // construct the real kate app object ;) KateApp app (args); // app execution should already end :) if (app.shouldExit()) { return 0; } // execute ourself ;) return app.exec(); }
QMCCostFunctionOMP::Return_t QMCCostFunctionOMP::correlatedSampling(bool needGrad) { for(int ip=0; ip<NumThreads; ++ip) { // synchronize the random number generator with the node (*MoverRng[ip]) = (*RngSaved[ip]); hClones[ip]->setRandomGenerator(MoverRng[ip]); } Return_t wgt_tot=0.0; Return_t wgt_tot2=0.0; Return_t NSm1 = 1.0/NumSamples; Return_t inv_n_samples=1.0/NumSamples; typedef MCWalkerConfiguration::Walker_t Walker_t; #pragma omp parallel reduction(+:wgt_tot,wgt_tot2) { int ip = omp_get_thread_num(); MCWalkerConfiguration& wRef(*wClones[ip]); Return_t wgt_node=0.0, wgt_node2=0.0; //int totalElements=W.getTotalNum()*OHMMS_DIM; MCWalkerConfiguration::iterator it(wRef.begin()); MCWalkerConfiguration::iterator it_end(wRef.end()); int iw=0,iwg=wPerNode[ip]; for (; it!= it_end; ++it,++iw,++iwg) { ParticleSet::Walker_t& thisWalker(**it); wRef.R=thisWalker.R; wRef.update(); Return_t* restrict saved = (*RecordsOnNode[ip])[iw]; // buffer for MultiSlaterDet data Return_t logpsi; // Return_t logpsi_old = thisWalker.getPropertyBase()[LOGPSI]; // if((usebuffer=="yes")||(includeNonlocalH=="yes")) if(StoreDerivInfo) { Walker_t::Buffer_t& tbuffer=thisWalker.DataSetForDerivatives; logpsi=psiClones[ip]->evaluateDeltaLog(wRef,tbuffer); wRef.G += *dLogPsi[iwg]; wRef.L += *d2LogPsi[iwg]; } else { logpsi=psiClones[ip]->evaluateDeltaLog(wRef); wRef.G += *dLogPsi[iwg]; wRef.L += *d2LogPsi[iwg]; // logpsi=psiClones[ip]->evaluateLog(wRef); } // Return_t weight = std::exp(2.0*(logpsi-saved[LOGPSI_FREE])); Return_t weight = saved[REWEIGHT] = vmc_or_dmc*(logpsi-saved[LOGPSI_FREE])+std::log(thisWalker.Weight); // if(std::isnan(weight)||std::isinf(weight)) weight=0; saved[ENERGY_NEW] = H_KE_Node[ip]->evaluate(wRef) + saved[ENERGY_FIXED]; if (needGrad) { vector<Return_t> Dsaved(NumOptimizables,0); vector<Return_t> HDsaved(NumOptimizables,0); psiClones[ip]->evaluateDerivatives(wRef, OptVariablesForPsi, Dsaved, HDsaved); for( int i=0; i<NumOptimizables; i++) if(OptVariablesForPsi.recompute(i)) { (*DerivRecords[ip])(iw,i) = Dsaved[i]; (*HDerivRecords[ip])(iw,i) = HDsaved[i]; } } wgt_node+=inv_n_samples*weight; wgt_node2+=inv_n_samples*weight*weight; } wgt_tot += wgt_node; wgt_tot2 += wgt_node2; } //this is MPI barrier OHMMS::Controller->barrier(); //collect the total weight for normalization and apply maximum weight myComm->allreduce(wgt_tot); myComm->allreduce(wgt_tot2); // app_log()<<"Before Purge"<<wgt_tot<<" "<<wgt_tot2<<endl; Return_t wgtnorm = (wgt_tot==0)?0:wgt_tot; wgt_tot=0.0; for (int ip=0; ip<NumThreads; ip++) { int nw=wClones[ip]->getActiveWalkers(); for (int iw=0; iw<nw; iw++) { Return_t* restrict saved = (*RecordsOnNode[ip])[iw]; saved[REWEIGHT] = std::min(std::exp(saved[REWEIGHT]-wgtnorm), numeric_limits<Return_t>::max()*0.1 ); wgt_tot+= inv_n_samples*saved[REWEIGHT]; } } myComm->allreduce(wgt_tot); // app_log()<<"During Purge"<<wgt_tot<<" "<<endl; wgtnorm =(wgt_tot==0)?1:1.0/wgt_tot; wgt_tot=0.0; for (int ip=0; ip<NumThreads; ip++) { int nw=wClones[ip]->getActiveWalkers(); for (int iw=0; iw<nw; iw++) { Return_t* restrict saved = (*RecordsOnNode[ip])[iw]; saved[REWEIGHT] = std::min(saved[REWEIGHT]*wgtnorm,MaxWeight); wgt_tot+= inv_n_samples*saved[REWEIGHT]; } } myComm->allreduce(wgt_tot); // app_log()<<"After Purge"<<wgt_tot<<" "<<endl; for (int i=0; i<SumValue.size(); i++) SumValue[i]=0.0; CSWeight=wgt_tot=(wgt_tot==0)?1:1.0/wgt_tot; for (int ip=0; ip<NumThreads; ip++) { int nw=wClones[ip]->getActiveWalkers(); for (int iw=0; iw<nw; iw++) { const Return_t* restrict saved = (*RecordsOnNode[ip])[iw]; Return_t weight=saved[REWEIGHT]*wgt_tot; Return_t eloc_new=saved[ENERGY_NEW]; Return_t delE=std::pow(abs(eloc_new-EtargetEff),PowerE); SumValue[SUM_E_BARE] += eloc_new; SumValue[SUM_ESQ_BARE] += eloc_new*eloc_new; SumValue[SUM_ABSE_BARE] += delE; SumValue[SUM_E_WGT] += eloc_new*saved[REWEIGHT]; SumValue[SUM_ESQ_WGT] += eloc_new*eloc_new*saved[REWEIGHT]; SumValue[SUM_ABSE_WGT] += delE*saved[REWEIGHT]; SumValue[SUM_WGT] += saved[REWEIGHT]; SumValue[SUM_WGTSQ] += saved[REWEIGHT]*saved[REWEIGHT]; } } //collect everything myComm->allreduce(SumValue); // for (int i=0; i<SumValue.size(); i++) cerr<<SumValue[i]<<" "; // cerr<<endl; // app_log()<<"After purge Energy Variance Weight " // << SumValue[SUM_E_WGT]/SumValue[SUM_WGT] << " " // << SumValue[SUM_ESQ_WGT]/SumValue[SUM_WGT] -(SumValue[SUM_E_WGT]/SumValue[SUM_WGT])*(SumValue[SUM_E_WGT]/SumValue[SUM_WGT]) << " " // << SumValue[SUM_WGT]*SumValue[SUM_WGT]/SumValue[SUM_WGTSQ] << endl; return SumValue[SUM_WGT]*SumValue[SUM_WGT]/SumValue[SUM_WGTSQ]; }
/** evaluate everything before optimization */ void QMCCostFunctionOMP::checkConfigurations() { /* mmorales: Since there are cases when memory is an issue (too many dets), the use of a buffer is decoupled from the use of includeNonlocalH in the cost function. Without a buffer, everything is recalculated. Options: - "yes" or "all" : store everything - "minimum" : store orbitals and inverses only, recalculate dets FIX FIX FIX: right now, there is no way to include the nonlocalH in the cost function without using a buffer because evaluateLog needs to be called to get the inverse of psiM This implies that isOptimizable must be set to true, which is risky. Fix this somehow */ StoreDerivInfo=false; DerivStorageLevel=-1; if(usebuffer == "yes" || usebuffer == "all") { StoreDerivInfo=true; if(includeNonlocalH!="no") DerivStorageLevel=0; else DerivStorageLevel=1; app_log() <<"Using buffers for temporary storage in QMCCostFunction.\n" <<endl; } else if (usebuffer == "minimum") { StoreDerivInfo=true; // in this case the use of nonlocalH is irrelevant, since the same inf is enough for both cases DerivStorageLevel=2; app_log() <<"Using minimum storage for determinant evaluation. \n"; } else { if(includeNonlocalH!="no") { APP_ABORT("Need to enable the use of includeNonlocalH=='name' without a buffer."); } } int numW = 0; for(int i=0; i<wClones.size(); i++) numW += wClones[i]->getActiveWalkers(); app_log() <<"Memory usage: " <<endl; app_log() <<"Linear method (approx matrix usage: 4*N^2): " <<NumParams()*NumParams()*sizeof(QMCTraits::RealType)*4.0/1.0e6 <<" MB" <<endl; // assuming 4 matrices app_log() <<"Deriv,HDerivRecord: " <<numW*NumOptimizables*sizeof(QMCTraits::RealType)*3.0/1.0e6 <<" MB" <<endl; if(StoreDerivInfo) { MCWalkerConfiguration& dummy(*wClones[0]); long memorb=0,meminv=0,memdets=0,memorbs_only=0; Psi.memoryUsage_DataForDerivatives(dummy,memorbs_only,memorb,meminv,memdets); memorbs_only*=sizeof(QMCTraits::RealType); memorb*=sizeof(QMCTraits::RealType); meminv*=sizeof(QMCTraits::RealType); memdets*=sizeof(QMCTraits::RealType); app_log() <<"Buffer memory cost: MB/walker MB/total " <<endl; app_log() <<"Orbitals only: " <<memorbs_only/1.0e6 <<" " <<memorbs_only*numW/1.0e6 <<endl; app_log() <<"Orbitals + dervs: " <<memorb/1.0e6 <<" " <<memorb*numW/1.0e6 <<endl; app_log() <<"Inverse: " <<meminv/1.0e6 <<" " <<meminv*numW/1.0e6 <<endl; app_log() <<"Determinants: " <<memdets/1.0e6 <<" " <<memdets*numW/1.0e6 <<endl; } app_log().flush(); RealType et_tot=0.0; RealType e2_tot=0.0; #pragma omp parallel reduction(+:et_tot,e2_tot) { int ip = omp_get_thread_num(); MCWalkerConfiguration& wRef(*wClones[ip]); if (RecordsOnNode[ip] ==0) { RecordsOnNode[ip]=new Matrix<Return_t>; RecordsOnNode[ip]->resize(wRef.getActiveWalkers(),SUM_INDEX_SIZE); if (needGrads) { DerivRecords[ip]=new Matrix<Return_t>; DerivRecords[ip]->resize(wRef.getActiveWalkers(),NumOptimizables); HDerivRecords[ip]=new Matrix<Return_t>; HDerivRecords[ip]->resize(wRef.getActiveWalkers(),NumOptimizables); } } else if (RecordsOnNode[ip]->size1()!=wRef.getActiveWalkers()) { RecordsOnNode[ip]->resize(wRef.getActiveWalkers(),SUM_INDEX_SIZE); if (needGrads) { DerivRecords[ip]->resize(wRef.getActiveWalkers(),NumOptimizables); HDerivRecords[ip]->resize(wRef.getActiveWalkers(),NumOptimizables); } } QMCHamiltonianBase* nlpp = (includeNonlocalH =="no")? 0: hClones[ip]->getHamiltonian(includeNonlocalH.c_str()); //set the optimization mode for the trial wavefunction psiClones[ip]->startOptimization(); // synchronize the random number generator with the node (*MoverRng[ip]) = (*RngSaved[ip]); hClones[ip]->setRandomGenerator(MoverRng[ip]); //int nat = wRef.getTotalNum(); //int totalElements=W.getTotalNum()*OHMMS_DIM; typedef MCWalkerConfiguration::Walker_t Walker_t; Return_t e0=0.0; // Return_t ef=0.0; Return_t e2=0.0; for (int iw=0, iwg=wPerNode[ip]; iw<wRef.getActiveWalkers(); ++iw,++iwg) { ParticleSet::Walker_t& thisWalker(*wRef[iw]); wRef.R=thisWalker.R; wRef.update(); Return_t* restrict saved=(*RecordsOnNode[ip])[iw]; // Return_t logpsi(0); // psiClones[ip]->evaluateDeltaLog(wRef, saved[LOGPSI_FIXED], saved[LOGPSI_FREE], *dLogPsi[iwg],*d2LogPsi[iwg]); // buffer for MultiSlaterDet data // if((usebuffer=="yes")||(includeNonlocalH=="yes")) if(StoreDerivInfo) { psiClones[ip]->registerDataForDerivatives(wRef, thisWalker.DataSetForDerivatives,DerivStorageLevel); psiClones[ip]->evaluateDeltaLog(wRef, saved[LOGPSI_FIXED], saved[LOGPSI_FREE], *dLogPsi[iwg], *d2LogPsi[iwg], thisWalker.DataSetForDerivatives); // logpsi = saved[LOGPSI_FIXED] + saved[LOGPSI_FREE]; } else { psiClones[ip]->evaluateDeltaLog(wRef, saved[LOGPSI_FIXED], saved[LOGPSI_FREE], *dLogPsi[iwg], *d2LogPsi[iwg]); // logpsi = psiClones[ip]->evaluateLog(wRef); } // if(includeNonlocalH!="no") logpsi = saved[LOGPSI_FIXED] + saved[LOGPSI_FREE]; Return_t x= hClones[ip]->evaluate(wRef); e0 += saved[ENERGY_TOT] = x; e2 += x*x; saved[ENERGY_FIXED] = hClones[ip]->getLocalPotential(); if(nlpp) saved[ENERGY_FIXED] -= nlpp->Value; //if (includeNonlocalH!="no") // saved[ENERGY_FIXED] = hClones[ip]->getLocalPotential() - (*(hClones[ip]->getHamiltonian(includeNonlocalH.c_str()))).Value; //else // saved[ENERGY_FIXED] = hClones[ip]->getLocalPotential(); // ef += saved[ENERGY_FIXED]; saved[REWEIGHT]=thisWalker.Weight=1.0; // thisWalker.resetProperty(logpsi,psiClones[ip]->getPhase(),x); if (needGrads) { //allocate vector vector<Return_t> Dsaved(NumOptimizables,0.0); vector<Return_t> HDsaved(NumOptimizables,0.0); psiClones[ip]->evaluateDerivatives(wRef, OptVariablesForPsi, Dsaved, HDsaved); std::copy(Dsaved.begin(),Dsaved.end(),(*DerivRecords[ip])[iw]); std::copy(HDsaved.begin(),HDsaved.end(),(*HDerivRecords[ip])[iw]); } } //add them all using reduction et_tot+=e0; e2_tot+=e2; // #pragma omp atomic // eft_tot+=ef; } OptVariablesForPsi.setComputed(); // app_log() << " VMC Efavg = " << eft_tot/static_cast<Return_t>(wPerNode[NumThreads]) << endl; //Need to sum over the processors vector<Return_t> etemp(3); etemp[0]=et_tot; etemp[1]=static_cast<Return_t>(wPerNode[NumThreads]); etemp[2]=e2_tot; myComm->allreduce(etemp); Etarget = static_cast<Return_t>(etemp[0]/etemp[1]); NumSamples = static_cast<int>(etemp[1]); app_log() << " VMC Eavg = " << Etarget << endl; app_log() << " VMC Evar = " << etemp[2]/etemp[1]-Etarget*Etarget << endl; app_log() << " Total weights = " << etemp[1] << endl; app_log().flush(); setTargetEnergy(Etarget); ReportCounter=0; }