void TestMain() { boost::shared_ptr<A> spA(new A); boost::shared_ptr<B> spB(new B); spA->m_spB = spB; spB->m_spA = spA; }
/** create Input Analytic function * * \xmlonly * <jastrow name="Jne" * type="Two-Body|One-Body|Polarization|Three-Body-Geminal" * function="pade|pade2|no-cusp" * transform="no|yes" spin="no|yes" * source="ionic system"> * <grid/> * <correlation speciesA="sourceSpecies" speciesB="targetSpecies" type="pade|pade2|no-cusp"> * <parameter name=" ">value<parameter> * </correlation> * </jastrow> * \endxmlonly */ bool NJABBuilder::putInFunc(xmlNodePtr cur) { string corr_tag("correlation"); string jastfunction("pade"); int ng=1; const xmlChar *ftype = xmlGetProp(cur, (const xmlChar *)"function"); if(ftype != NULL) jastfunction = (const char*) ftype; const xmlChar* s=xmlGetProp(cur,(const xmlChar*)"source"); if(s != NULL) { map<string,ParticleSet*>::iterator pa_it(ptclPool.find((const char*)s)); if(pa_it == ptclPool.end()) return false; sourcePtcl = (*pa_it).second; ng=sourcePtcl->getSpeciesSet().getTotalNum(); } int ia=0, ib=0, iab=0; cur = cur->children; while(cur != NULL) { string cname((const char*)(cur->name)); if(cname == "grid") { gridPtr=cur; //save the pointer } else if(cname == dtable_tag) { string source_name((const char*)(xmlGetProp(cur,(const xmlChar *)"source"))); map<string,ParticleSet*>::iterator pa_it(ptclPool.find(source_name)); if(pa_it == ptclPool.end()) return false; sourcePtcl=(*pa_it).second; ng = sourcePtcl->getSpeciesSet().getTotalNum(); XMLReport("Number of sources " << ng) InFunc.resize(ng,0); } else if(cname ==corr_tag) { if(sourcePtcl==0) return false; string jfunctype(jastfunction); string spA((const char*)(xmlGetProp(cur,(const xmlChar *)"speciesA"))); ftype = xmlGetProp(cur, (const xmlChar *)"type"); if(ftype) { jfunctype=(const char*)ftype; } ia = sourcePtcl->getSpeciesSet().findSpecies(spA); if(!(InFunc[ia])) { InFuncType *j1=createInFunc(jfunctype); InFunc[ia]= j1; app_log() <<" Added Jastrow Correlation ("<<jfunctype << ") between " <<spA<<" and "<<targetPtcl.getName() << endl; } InFunc[ia]->put(cur); InFunc[ia]->addOptimizables(targetPsi.VarList); } cur = cur->next; } // while cur return true; }
bool NJAABuilder::putInFunc(xmlNodePtr cur) { string corr_tag("correlation"); string jastfunction("pade"); const xmlChar *ftype = xmlGetProp(cur, (const xmlChar *)"function"); if(ftype) jastfunction = (const char*) ftype; int ng = targetPtcl.groups(); ///happends only once if(InFunc.size() != ng*ng) { InFunc.resize(ng*ng,0); } int ia=0, ib=0, iab=0; cur = cur->children; while(cur != NULL) { string cname((const char*)(cur->name)); if(cname == "grid") { gridPtr=cur; //save the pointer } else if(cname ==corr_tag) { string spA((const char*)(xmlGetProp(cur,(const xmlChar *)"speciesA"))); string spB((const char*)(xmlGetProp(cur,(const xmlChar *)"speciesB"))); const xmlChar* refptr=xmlGetProp(cur,(const xmlChar *)"ref"); const xmlChar* idptr=xmlGetProp(cur,(const xmlChar *)"id"); if(!IgnoreSpin) { //get the species ia = targetPtcl.getSpeciesSet().findSpecies(spA); ib = targetPtcl.getSpeciesSet().findSpecies(spB); iab = ia*ng+ib; } if(!(InFunc[ia*ng+ib])) { InFuncType *j2=createInFunc(jastfunction,ia,ib); j2->put(cur,targetPsi.VarList); InFunc[ia*ng+ib]= j2; XMLReport("Added Jastrow Correlation between "<<spA<<" and "<<spB) } else {
int main(int argc, char **argv) { if(argc != 4) { std::cout<<"No enough arugments\n"; exit(0); } double alpha = 0.15; int maxIter = 50; int n_threads; std::string meta_file, data_file; n_threads = atoi(argv[1]); meta_file = argv[2]; data_file = argv[3]; int row, col, size; //reading the meta file std::ifstream fmeta(meta_file.c_str()); fmeta >> row >> col >> size; double *R = new double[col]; for(int i=0; i<col; i++) { R[i] = (double)1/col; } double *Y = new double[col](); double *pM = new double[col](); //create a sparse matrix pr_spMatrix spA(n_threads, data_file); spA.getpM(pM, alpha); spA.initNodes(R, Y); spA.initEdges(pM); spA.initV(alpha, col); //--------timing-------------------- Galois::StatTimer T; T.start(); for(size_t i=0; i<maxIter; i++) { spA.pagerank_multiply(); } T.stop(); int maxTop = 10; spA.getR(R); int* idx = new int[col]; sort_idx(R, idx, col); for(int i=0; i<maxTop; i++) { printf("rank: %d | %d | %0.15f\n", i+1, idx[i], R[idx[i]]); } printf("total running time: %f seconds\n", double(T.get())/1000); delete[] idx; delete[] pM; delete[] Y; delete[] R; }
/** Create a two-body Jatrow function with a template *@param cur the current xmlNode *@param dummy null pointer used to identify FN * *The template class JeeType is a functor which handles the *evaluation of the function value, gradients and laplacians using *distance tables. This is a specialized builder function for *spin-dependent Jastrow function,e.g., for electrons, two functions *are created for uu(dd) and ud(du). */ template <class FN> TwoBodyJastrowOrbital<FN>* JAABuilder::createJAA(xmlNodePtr cur, const string& jname) { string corr_tag("correlation"); int ng = targetPtcl.groups(); int ia=0, ib=0, iab=0; xmlNodePtr gridPtr=NULL; cur = cur->children; const SpeciesSet& species(targetPtcl.getSpeciesSet()); typedef TwoBodyJastrowOrbital<FN> JeeType; JeeType *J2 = new JeeType(targetPtcl,targetPsi.is_manager()); typedef DiffTwoBodyJastrowOrbital<FN> dJ2Type; dJ2Type *dJ2 = new dJ2Type(targetPtcl); RealType rc=targetPtcl.Lattice.WignerSeitzRadius; int pairs=0; while (cur != NULL) { string cname((const char*)(cur->name)); if (cname == corr_tag) { string spA("u"); string spB("u"); OhmmsAttributeSet rAttrib; rAttrib.add(spA, "speciesA"); rAttrib.add(spA, "species1"); rAttrib.add(spB, "speciesB"); rAttrib.add(spB, "species2"); rAttrib.put(cur); if (spA==targetPsi.getName()) //could have used the particle name { spA=species.speciesName[0]; spB=species.speciesName[0]; } int ia = species.findSpecies(spA); int ib = species.findSpecies(spB); if (ia==species.size() || ia == species.size()) { APP_ABORT("JAABuilder::createJAA is trying to use invalid species"); } string pairID=spA+spB; FN *j= new FN; j->cutoff_radius=rc; j->put(cur); J2->addFunc(pairID,ia,ib,j); dJ2->addFunc(pairID,ia,ib,j); ++pairs; } cur = cur->next; } // while cur if (pairs) { J2->dPsi=dJ2; string j2name="J2_"+jname; targetPsi.addOrbital(J2,j2name); return J2; } else {//clean up and delete the twobody orbitals APP_ABORT("JAABuilder::put Failed to create Two-Body with "+jname); return 0; } }
bool JastrowBuilder::createTwoBodySpin(xmlNodePtr cur, JeeType* J2) { /**\typedef The type of a simple function,e.g., PadeJastrow<double> */ typedef typename JeeType::FuncType FuncType; int cur_var = targetPsi.VarList.size(); DistanceTableData* d_table = DistanceTable::getTable(DistanceTable::add(targetPtcl)); int ng = targetPtcl.groups(); map<string,FuncType*> jastrowMap; vector<FuncType*> jastrow(ng*ng); for(int i=0; i<ng*ng; i++) jastrow[i]=0; int nj = 0; cur = cur->children; while(cur != NULL) { string cname((const char*)(cur->name)); //if(cname == dtable_tag) { // string source_name((const char*)(xmlGetProp(cur,(const xmlChar *)"source"))); // //int iptcl = 0; // map<string,ParticleSet*>::iterator pit(ptclPool.find(source_name)); // if(pit == ptclPool.end()) return false; // ParticleSet* a = (*pit).second; // d_table = DistanceTable::getTable(DistanceTable::add(*a)); // ng = a->groups(); // //create a Jastrow function for each pair type // //for spin 1/2 particles (up-up, down-up = up-down, // //down-down) // for(int i=0; i<ng*ng; i++) jastrow.push_back(NULL); //} else if(cname ==corr_tag) { if(cname ==corr_tag) { string spA((const char*)(xmlGetProp(cur,(const xmlChar *)"speciesA"))); string spB((const char*)(xmlGetProp(cur,(const xmlChar *)"speciesB"))); const xmlChar* refptr=xmlGetProp(cur,(const xmlChar *)"ref"); const xmlChar* idptr=xmlGetProp(cur,(const xmlChar *)"id"); int ia = targetPtcl.getSpeciesSet().findSpecies(spA); int ib = targetPtcl.getSpeciesSet().findSpecies(spB); int iab = ia*ng+ib; if(!(jastrow[iab])) { //create the new Jastrow function FuncType *j2=NULL; if(refptr == NULL) { j2 = new FuncType; } else { typename map<string,FuncType*>::iterator it(jastrowMap.find((const char*)refptr)); if(it != jastrowMap.end()) { j2 = new FuncType((*it).second); } else { j2 = new FuncType; } } if(idptr == NULL) { ostringstream idassigned; idassigned << "j2"<<iab; jastrowMap[idassigned.str()]=j2; } else { jastrowMap[(const char*)idptr]=j2; } //initialize j2->put(cur,targetPsi.VarList); jastrow[iab]= j2; if(ia != ib) {//up-down-type pair, treat down-up the same way jastrow[ib*ng+ia] = j2; } else { for(int iaa=0; iaa<ng; iaa++) if(iaa != ia) jastrow[iaa*ng+iaa] = j2; } XMLReport("Added Jastrow Correlation between "<<spA<<" and "<<spB) nj++; } else { ERRORMSG("Using an existing Jastrow Correlation "<<spA<<" and "<<spB) } } cur = cur->next; } // while cur
bool BsplineJastrowBuilder::put(xmlNodePtr cur) { ReportEngine PRE(ClassName,"put(xmlNodePtr)"); bool PrintTables=false; typedef BsplineFunctor<RealType> RadFuncType; // Create a one-body Jastrow if (sourcePtcl) { string j1spin("no"); OhmmsAttributeSet jAttrib; jAttrib.add(j1spin,"spin"); jAttrib.put(cur); #ifdef QMC_CUDA return createOneBodyJastrow<OneBodyJastrowOrbitalBspline,DiffOneBodySpinJastrowOrbital<RadFuncType> >(cur); #else //if(sourcePtcl->IsGrouped) //{ // app_log() << "Creating OneBodySpinJastrowOrbital<T> " << endl; // return createOneBodyJastrow<OneBodySpinJastrowOrbital<RadFuncType>,DiffOneBodySpinJastrowOrbital<RadFuncType> >(cur); //} //else //{ // app_log() << "Creating OneBodyJastrowOrbital<T> " << endl; // return createOneBodyJastrow<OneBodyJastrowOrbital<RadFuncType>,DiffOneBodyJastrowOrbital<RadFuncType> >(cur); //} if(j1spin=="yes") return createOneBodyJastrow<OneBodySpinJastrowOrbital<RadFuncType>,DiffOneBodySpinJastrowOrbital<RadFuncType> >(cur); else return createOneBodyJastrow<OneBodyJastrowOrbital<RadFuncType>,DiffOneBodyJastrowOrbital<RadFuncType> >(cur); #endif } else // Create a two-body Jastrow { string init_mode("0"); { OhmmsAttributeSet hAttrib; hAttrib.add(init_mode,"init"); hAttrib.put(cur); } BsplineInitializer<RealType> j2Initializer; xmlNodePtr kids = cur->xmlChildrenNode; #ifdef QMC_CUDA typedef TwoBodyJastrowOrbitalBspline J2Type; #else typedef TwoBodyJastrowOrbital<BsplineFunctor<RealType> > J2Type; #endif typedef DiffTwoBodyJastrowOrbital<BsplineFunctor<RealType> > dJ2Type; int taskid=(targetPsi.is_manager())?targetPsi.getGroupID():-1; J2Type *J2 = new J2Type(targetPtcl,taskid); dJ2Type *dJ2 = new dJ2Type(targetPtcl); SpeciesSet& species(targetPtcl.getSpeciesSet()); int chargeInd=species.addAttribute("charge"); //std::map<std::string,RadFuncType*> functorMap; bool Opt(false); 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) { RealType qq=species(chargeInd,ia)*species(chargeInd,ib); cusp = (ia==ib)? -0.25*qq:-0.5*qq; } app_log() << " BsplineJastrowBuilder adds a functor with cusp = " << cusp << endl; RadFuncType *functor = new RadFuncType(cusp); functor->cutoff_radius = targetPtcl.Lattice.WignerSeitzRadius; bool initialized_p=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(); } //RPA INIT if(!initialized_p && init_mode =="rpa") { app_log() << " Initializing Two-Body with RPA Jastrow " << endl; j2Initializer.initWithRPA(targetPtcl,*functor,-cusp/0.5); } J2->addFunc(ia,ib,functor); dJ2->addFunc(ia,ib,functor); Opt=(!functor->notOpt or Opt); if(qmc_common.io_node) { char fname[32]; if(qmc_common.mpi_groups>1) sprintf(fname,"J2.%s.g%03d.dat",pairType.c_str(),taskid); else sprintf(fname,"J2.%s.dat",pairType.c_str()); functor->setReportLevel(ReportLevel,fname); functor->print(); } } kids = kids->next; } //dJ2->initialize(); //J2->setDiffOrbital(dJ2); J2->dPsi=dJ2; targetPsi.addOrbital(J2,"J2_bspline"); J2->setOptimizable(Opt); } return true; }