int main(int argc, char** argv) { MPI_Init(&argc, &argv); Communicator world; if(world.size() == 1) { std::cerr << ">1 process please." << std::endl; return 1; } if(world.rank() == 0) { int dim_num = 6; int dim_partition_size = 2; int number_of_partitions = 8; int size = world.size() - 1; IntegratorMain::Root root; root.main(dim_num, dim_partition_size, number_of_partitions, size); MPI_Finalize(); return 0; } else { int it_max = 5; double tol = 0.000001; int dim_num = 6; int dim_partition_size = 2; int number_of_partitions = 8; int size = world.size() - 1; int i = world.rank() - 1; std::cout << "Createing Peer(" << i << "," << size << ")" << std::endl; IntegratorMain::Peer peer(i, size); peer.main(it_max, tol, dim_num, dim_partition_size, number_of_partitions); MPI_Finalize(); return 0; } }
void mpsxx::DMRGInput::parse (const std::string& fname) { if(fname.size() == 0) return; Communicator world; if(world.rank() == 0) { std::ifstream fin(fname.c_str()); std::string entry; while(fin >> entry) { if(entry == "restart") this->restart = true; if(entry == "N") fin >> this->N_sites; if(entry == "spin") fin >> this->N_spins; if(entry == "elec") fin >> this->N_elecs; if(entry == "M" || entry == "max_states") fin >> this->N_max_states; if(entry == "nroots") fin >> this->N_roots; if(entry == "tole" || entry == "tolerance") fin >> this->tolerance; if(entry == "noise") fin >> this->noise; if(entry == "onesite" || entry == "onedot") this->algorithm = mpsxx::ONESITE; if(entry == "twosite" || entry == "twodot") this->algorithm = mpsxx::TWOSITE; if(entry == "maxiter") fin >> this->N_max_sweep_iter; } }
int main (int argc, char* argv[]) { using std::cout; using std::endl; using std::setw; using std::fixed; #ifndef _SERIAL boost::mpi::environment env(argc,argv); #endif Communicator world; std::string f_inp = "dmrg.conf"; std::string f_out; std::string prefx = "."; for(int iarg = 0; iarg < argc; ++iarg) { if(strcmp(argv[iarg],"-i") == 0) f_inp = argv[++iarg]; if(strcmp(argv[iarg],"-o") == 0) f_out = argv[++iarg]; if(strcmp(argv[iarg],"-s") == 0) prefx = argv[++iarg]; } mpsxx::DMRGInput input(f_inp); input.prefix = prefx; // // assign cout as alias to fout // std::streambuf *backup; backup = cout.rdbuf(); std::ofstream fout; if(f_out.size() > 0) { std::ostringstream oss; oss << f_out << "." << world.rank(); fout.open(oss.str().c_str()); cout.rdbuf(fout.rdbuf()); } time_stamp ts; // // dmrg optimization // input.energy = mpsxx::dmrg(input); pout << endl; pout.precision(2); pout << "\t\t\tTotal elapsed time: " << setw(8) << fixed << ts.elapsed() << endl; cout.rdbuf(backup); fout.close(); return 0; }
/// The main dmrg routine. /// \param input DMRGInput object which contains the diferent parameters that define this dmrg run std::vector<double> dmrg (const DMRGInput& input) { using std::endl; using std::setw; using std::setprecision; using std::fixed; using std::scientific; const size_t K_roots = input.N_roots; const size_t MAX_ITER = input.N_max_sweep_iter; std::vector<double> esav(K_roots,0.0); Communicator world; time_stamp ts; for(size_t iroot = 0; iroot < K_roots; ++iroot) { // Build initial MPSs if(!input.restart) make_random_mpss(input,iroot); bool conv = false; // Optimization with sweep algorithm for(size_t iter = 0; iter < MAX_ITER && !conv; ++iter) { pout << "\t====================================================================================================" << endl; pout << "\t\tSWEEP ITERATION [ " << setw(4) << iter << " ] :: ROOT = " << setw(2) << iroot << endl; pout << "\t====================================================================================================" << endl; ts.start(); double eswp = make_sweep(esav,input,iroot); double edif = eswp-esav[iroot]; pout << "\t====================================================================================================" << endl; pout << "\t\tSWEEP ITERATION [ " << setw(4) << iter << " ] :: ROOT = " << setw(2) << iroot << " FINISHED" << " ( " << fixed << setprecision(2) << setw(8) << ts.lap() << " sec. ) " << endl; pout.precision(16); pout << "\t\t\tSweep Energy = " << setw(24) << fixed << eswp << " ( delta E = "; pout.precision(2); pout << setw(8) << scientific << edif << " ) " << endl; pout << endl; if(world.rank() == 0) { esav[iroot] = eswp; if(iter > 0 && std::fabs(edif) < input.tolerance) conv = true; } #ifndef _SERIAL boost::mpi::broadcast(world,conv,0); boost::mpi::broadcast(world,esav,0); #endif } // Stop by no convergence if(!conv) { pout << "\t+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-" << endl; pout << "\t\tNO CONVERGENCE MET FOR ROOT = " << setw(2) << iroot << endl; pout << "\t\tPROGRAM STOPPED..." << endl; break; } if(input.algorithm == ONESITE) continue; DMRGInput in2nd = input; in2nd.algorithm = ONESITE; in2nd.restart = true; conv = false; // Optimization with sweep algorithm for(size_t iter = 0; iter < MAX_ITER && !conv; ++iter) { pout << "\t====================================================================================================" << endl; pout << "\t\tSWEEP ITERATION [ " << setw(4) << iter << " ] :: ROOT = " << setw(2) << iroot << endl; pout << "\t====================================================================================================" << endl; ts.start(); double eswp = make_sweep(esav,in2nd,iroot); double edif = eswp-esav[iroot]; pout << "\t====================================================================================================" << endl; pout << "\t\tSWEEP ITERATION [ " << setw(4) << iter << " ] :: ROOT = " << setw(2) << iroot << " FINISHED" << " ( " << fixed << setprecision(2) << setw(8) << ts.lap() << " sec. ) " << endl; pout.precision(16); pout << "\t\t\tSweep Energy = " << setw(24) << fixed << eswp << " ( delta E = "; pout.precision(2); pout << setw(8) << scientific << edif << " ) " << endl; pout << endl; if(world.rank() == 0) { esav[iroot] = eswp; if(iter > 0 && std::fabs(edif) < in2nd.tolerance) conv = true; } #ifndef _SERIAL boost::mpi::broadcast(world,conv,0); boost::mpi::broadcast(world,esav,0); #endif } // Stop by no convergence if(!conv) { pout << "\t+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-" << endl; pout << "\t\tNO CONVERGENCE MET FOR ROOT = " << setw(2) << iroot << endl; pout << "\t\tPROGRAM STOPPED..." << endl; break; } // gaugefix<fermion>(input,iroot); } pout << "\t====================================================================================================" << endl; pout.precision(16); for(size_t iroot = 0; iroot < K_roots; ++iroot) { pout << "\t\t\tSweep Energy = " << setw(24) << fixed << esav[iroot] << endl; } return esav; }
int main(int argc, char* argv[]) { #ifndef _SERIAL boost::mpi::environment env(argc,argv); #endif using std::cout; using std::endl; using namespace mpsxx; Communicator world; size_t iprint = 0; std::string f_dump = "FCIDUMP"; std::string prefix = "."; std::string f_rord; std::string f_iout; for(int iarg = 0; iarg < argc; ++iarg) { if(strcmp(argv[iarg],"-f") == 0) f_dump = argv[++iarg]; if(strcmp(argv[iarg],"-o") == 0) f_iout = argv[++iarg]; if(strcmp(argv[iarg],"-r") == 0) f_rord = argv[++iarg]; if(strcmp(argv[iarg],"-s") == 0) prefix = argv[++iarg]; if(strcmp(argv[iarg],"-v") == 0) iprint = 1; } // // assign cout as alias to ost_iout // std::streambuf *backup; backup = cout.rdbuf(); std::ofstream ost_iout; if(f_iout.size() > 0) { std::ostringstream oss; oss << f_iout << "." << world.rank(); ost_iout.open(oss.str().c_str()); cout.rdbuf(ost_iout.rdbuf()); } int Norbs; int Nelec; double Ecore; btas::TArray<double,2> oneint; btas::TArray<double,4> twoint; cout << "\t****************************************************************************************************" << endl; cout << "\t\t\t\tMPSXX::PROTOTYPE::MPO GENERATOR FOR QC " << endl; cout << "\t****************************************************************************************************" << endl; cout << endl; cout << "\t====================================================================================================" << endl; cout << "\t\tLoading integral information from FCIDUMP " << endl; cout << "\t====================================================================================================" << endl; cout << endl; if(world.rank() == 0) { std::ifstream ist_dump(f_dump.c_str()); if(!f_rord.empty()) { std::ifstream ist_rord(f_rord.c_str()); std::vector<int> reorder; parsing_reorder(ist_rord,reorder); parsing_fcidump(ist_dump,Norbs,Nelec,Ecore,oneint,twoint,reorder); } else { parsing_fcidump(ist_dump,Norbs,Nelec,Ecore,oneint,twoint); } } #ifndef _SERIAL boost::mpi::broadcast(world,Norbs,0); boost::mpi::broadcast(world,Nelec,0); boost::mpi::broadcast(world,Ecore,0); boost::mpi::broadcast(world,oneint,0); boost::mpi::broadcast(world,twoint,0); #endif cout << "\t====================================================================================================" << endl; cout << "\t\tGenerating QC MPOs from 1- and 2-particle integrals" << endl; cout << "\t====================================================================================================" << endl; cout << endl; std::vector<int> groups; std::vector<std::vector<btas::QSTArray<double,4,fermion>>> mpos; groups = gen_qc_naive_mpos(Norbs,Ecore,oneint,twoint,mpos); std::cout << "\t\t" << std::setw(6) << mpos.size() << " operators have generated." << std::endl; //std::fill(groups.begin(),groups.end(),1); std::vector<std::vector<btas::QSTArray<double,4,fermion>>> comp; groups = compress_qc_mpos(groups,mpos,comp); // deallocation std::vector<std::vector<btas::QSTArray<double,4,fermion>>>().swap(mpos); for(size_t i = 0; i < Norbs; ++i) { std::vector<btas::QSTArray<double,4,fermion>> impo(groups.size()); for(size_t g = 0; g < groups.size(); ++g) { impo[g] = comp[g][i]; } save(impo,getfile("mpo",prefix,i)); } std::cout.rdbuf(backup); ost_iout.close(); return 0; }