diff --git a/source/driver_run.cpp b/source/driver_run.cpp index de6cb18193d..434223166b6 100644 --- a/source/driver_run.cpp +++ b/source/driver_run.cpp @@ -37,16 +37,7 @@ void Driver::driver_run(void) #endif GlobalC::ucell.setup_cell(GlobalV::stru_file, GlobalV::ofs_running); - //! 3: for these two types of calculations - // nothing else need to be initialized - if(GlobalV::CALCULATION == "test_neighbour" - || GlobalV::CALCULATION == "test_memory") - { - p_esolver->run(0, GlobalC::ucell); - ModuleBase::QUIT(); - } - - //! 4: initialize Esolver and fill json-structure + //! 3: initialize Esolver and fill json-structure p_esolver->init(INPUT, GlobalC::ucell); @@ -54,7 +45,7 @@ void Driver::driver_run(void) Json::gen_stru_wrapper(&GlobalC::ucell); #endif - //! 5: md or relax calculations + //! 4: md or relax calculations if(GlobalV::CALCULATION == "md") { Run_MD::md_line(GlobalC::ucell, p_esolver, INPUT.mdp); @@ -73,7 +64,7 @@ void Driver::driver_run(void) } } - //! 6: clean up esolver + //! 5: clean up esolver p_esolver->post_process(); ModuleESolver::clean_esolver(p_esolver); diff --git a/source/module_base/math_chebyshev_def.h b/source/module_base/math_chebyshev_def.h old mode 100755 new mode 100644 diff --git a/source/module_base/memory.cpp b/source/module_base/memory.cpp index aec79dd8802..931d17f3600 100644 --- a/source/module_base/memory.cpp +++ b/source/module_base/memory.cpp @@ -2,6 +2,7 @@ // AUTHOR : mohan // DATE : 2008-11-18 //========================================================== +#include #include "memory.h" #include "global_variable.h" #include "module_base/parallel_reduce.h" @@ -230,20 +231,26 @@ void Memory::finish(std::ofstream &ofs) void Memory::print_all(std::ofstream &ofs) { -// std::cout<<"\n init_flag="<0); + bool *print_flag = new bool[n_memory]; - for(int i=0; iprint_rhofft(inp, GlobalV::ofs_running); + + return; } @@ -164,6 +168,8 @@ void ESolver_FP::init_after_vc(Input& inp, UnitCell& cell) kv.set_after_vc(cell.symm, GlobalV::global_kpoint_card, GlobalV::NSPIN, cell.G, cell.latvec); ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT K-POINTS"); + + return; } diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index de479128f3a..02b21e71e18 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -1,30 +1,23 @@ #include "esolver_ks.h" - #include #ifdef __MPI #include #else #include #endif - #include - #include "module_io/print_info.h" #include "module_base/timer.h" #include "module_io/input.h" #include "module_io/json_output/init_info.h" - - //--------------Temporary---------------- #include "module_base/global_variable.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" //--------------------------------------- - #ifdef USE_PAW #include "module_cell/module_paw/paw_cell.h" #include "module_base/parallel_common.h" #endif - #include "module_io/json_output/output_info.h" namespace ModuleESolver @@ -75,6 +68,8 @@ ESolver_KS::~ESolver_KS() template void ESolver_KS::init(Input& inp, UnitCell& ucell) { + ModuleBase::TITLE("ESolver_KS", "init"); + ESolver_FP::init(inp,ucell); //------------------Charge Mixing------------------ @@ -380,6 +375,8 @@ void ESolver_KS::print_wfcfft(Input& inp, std::ofstream &ofs) template void ESolver_KS::run(const int istep, UnitCell& ucell) { + ModuleBase::TITLE("ESolver_KS", "run"); + if (!(GlobalV::CALCULATION == "scf" || GlobalV::CALCULATION == "md" || GlobalV::CALCULATION == "relax" diff --git a/source/module_esolver/esolver_ks_lcao_elec.cpp b/source/module_esolver/esolver_ks_lcao_elec.cpp index b01522210ee..e33f8170738 100644 --- a/source/module_esolver/esolver_ks_lcao_elec.cpp +++ b/source/module_esolver/esolver_ks_lcao_elec.cpp @@ -312,10 +312,14 @@ void ESolver_KS_LCAO::before_scf(int istep) this->beforesolver(istep); // Peize Lin add 2016-12-03 #ifdef __EXX // set xc type before the first cal of xc in pelec->init_scf - if (GlobalC::exx_info.info_ri.real_number) - this->exd->exx_beforescf(this->kv, *this->p_chgmix); - else - this->exc->exx_beforescf(this->kv, *this->p_chgmix); + if (GlobalC::exx_info.info_ri.real_number) + { + this->exd->exx_beforescf(this->kv, *this->p_chgmix); + } + else + { + this->exc->exx_beforescf(this->kv, *this->p_chgmix); + } #endif // __EXX this->pelec->init_scf(istep, this->sf.strucFac); @@ -331,9 +335,10 @@ void ESolver_KS_LCAO::before_scf(int istep) for (int is = 0; is < GlobalV::NSPIN; is++) { srho.begin(is, *(this->pelec->charge), this->pw_rho, GlobalC::Pgrid, GlobalC::ucell.symm); - } - // 1. calculate ewald energy. - // mohan update 2021-02-25 + } + + // 1. calculate ewald energy. + // mohan update 2021-02-25 if (!GlobalV::test_skip_ewald) { this->pelec->f_en.ewald_energy = H_Ewald_pw::compute_ewald(GlobalC::ucell, this->pw_rho, this->sf.strucFac); @@ -350,13 +355,13 @@ void ESolver_KS_LCAO::others(const int istep) { ModuleBase::TITLE("ESolver_KS_LCAO", "others"); ModuleBase::timer::tick("ESolver_KS_LCAO", "others"); + if (GlobalV::CALCULATION == "get_S") { this->get_S(); ModuleBase::QUIT(); } - - if (GlobalV::CALCULATION == "test_memory") + else if (GlobalV::CALCULATION == "test_memory") { Cal_Test::test_memory(this->pw_rho, this->pw_wfc, @@ -364,8 +369,7 @@ void ESolver_KS_LCAO::others(const int istep) this->p_chgmix->get_mixing_ndim()); return; } - - if (GlobalV::CALCULATION == "test_neighbour") + else if (GlobalV::CALCULATION == "test_neighbour") { // test_search_neighbor(); if (GlobalV::SEARCH_RADIUS < 0) @@ -452,14 +456,18 @@ void ESolver_KS_LCAO::others(const int istep) ModuleBase::timer::tick("ESolver_KS_LCAO", "others"); return; } + + template <> -void ESolver_KS_LCAO::get_S() +void ESolver_KS_LCAO::get_S(void) { ModuleBase::TITLE("ESolver_KS_LCAO", "get_S"); - ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::get_S", "not implemented for"); + ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::get_S", "not implemented for"); } + + template <> -void ESolver_KS_LCAO, double>::get_S() +void ESolver_KS_LCAO, double>::get_S(void) { ModuleBase::TITLE("ESolver_KS_LCAO", "get_S"); // (1) Find adjacent atoms for each atom. @@ -477,17 +485,21 @@ void ESolver_KS_LCAO, double>::get_S() GlobalV::test_atom_input); this->RA.for_2d(this->orb_con.ParaV, GlobalV::GAMMA_ONLY_LOCAL); + this->LM.ParaV = &this->orb_con.ParaV; + if (this->p_hamilt == nullptr) { this->p_hamilt = new hamilt::HamiltLCAO, double>(&this->LM, this->kv); dynamic_cast, double>*>(this->p_hamilt->ops)->contributeHR(); } + ModuleIO::output_S_R(this->uhm, this->p_hamilt, "SR.csr"); } + template <> -void ESolver_KS_LCAO, std::complex>::get_S() +void ESolver_KS_LCAO, std::complex>::get_S(void) { ModuleBase::TITLE("ESolver_KS_LCAO", "get_S"); // (1) Find adjacent atoms for each atom. @@ -516,8 +528,9 @@ void ESolver_KS_LCAO, std::complex>::get_S() ModuleIO::output_S_R(this->uhm, this->p_hamilt, "SR.csr"); } + template -void ESolver_KS_LCAO::nscf() +void ESolver_KS_LCAO::nscf(void) { ModuleBase::TITLE("ESolver_KS_LCAO", "nscf"); @@ -533,9 +546,13 @@ void ESolver_KS_LCAO::nscf() // GlobalC::exx_lcao.cal_exx_elec_nscf(this->LOWF.ParaV[0]); const std::string file_name_exx = GlobalV::global_out_dir + "HexxR" + std::to_string(GlobalV::MY_RANK); if (GlobalC::exx_info.info_ri.real_number) + { this->exd->read_Hexxs_csr(file_name_exx, GlobalC::ucell); + } else + { this->exc->read_Hexxs_csr(file_name_exx, GlobalC::ucell); + } hamilt::HamiltLCAO* hamilt_lcao = dynamic_cast*>(this->p_hamilt); auto exx = new hamilt::OperatorEXX>(&this->LM, @@ -625,7 +642,14 @@ void ESolver_KS_LCAO::nscf() INPUT.wannier_spin ); - myWannier.calculate(this->pelec->ekb, this->pw_wfc, this->pw_big, this->sf, this->kv, this->psi, this->LOWF.ParaV); + myWannier.calculate( + this->pelec->ekb, + this->pw_wfc, + this->pw_big, + this->sf, + this->kv, + this->psi, + this->LOWF.ParaV); } else if (INPUT.wannier_method == 2) { diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_gen_fixedH.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_gen_fixedH.cpp index 0df16fe3644..9ba4ffbed98 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_gen_fixedH.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_gen_fixedH.cpp @@ -58,6 +58,7 @@ void LCAO_gen_fixedH::calculate_S_no(double* SlocR) void LCAO_gen_fixedH::build_ST_new(const char& dtype, const bool& calc_deri, const UnitCell &ucell, double* HSloc, bool cal_syns, double dmax) { ModuleBase::TITLE("LCAO_gen_fixedH","build_ST_new"); + ModuleBase::timer::tick("LCAO_gen_fixedH","build_ST_new"); int total_nnr = 0; const Parallel_Orbitals* pv = this->LM->ParaV; @@ -236,18 +237,38 @@ void LCAO_gen_fixedH::build_ST_new(const char& dtype, const bool& calc_deri, con int M1 = (m1 % 2 == 0) ? -m1/2 : (m1+1)/2; int M2 = (m2 % 2 == 0) ? -m2/2 : (m2+1)/2; switch (dtype) - { - case 'S': - GlobalC::UOT.two_center_bundle->overlap_orb->calculate(T1, L1, N1, M1, - T2, L2, N2, M2, dtau * ucell.lat0, nullptr, olm); - break; - case 'T': - GlobalC::UOT.two_center_bundle->kinetic_orb->calculate(T1, L1, N1, M1, - T2, L2, N2, M2, dtau * ucell.lat0, nullptr, olm); - break; - default: // not supposed to happen - ModuleBase::WARNING_QUIT("LCAO_gen_fixedH::build_ST_new","dtype must be S or T"); - } + { + case 'S': + GlobalC::UOT.two_center_bundle->overlap_orb->calculate( + T1, + L1, + N1, + M1, + T2, + L2, + N2, + M2, + dtau * ucell.lat0, + nullptr, + olm); + break; + case 'T': + GlobalC::UOT.two_center_bundle->kinetic_orb->calculate( + T1, + L1, + N1, + M1, + T2, + L2, + N2, + M2, + dtau * ucell.lat0, + nullptr, + olm); + break; + default: // not supposed to happen + ModuleBase::WARNING_QUIT("LCAO_gen_fixedH::build_ST_new","dtype must be S or T"); + } #else GlobalC::UOT.snap_psipsi( GlobalC::ORB, olm, 1, dtype, tau1, T1, L1, m1, N1, @@ -363,6 +384,7 @@ void LCAO_gen_fixedH::build_ST_new(const char& dtype, const bool& calc_deri, con } } + ModuleBase::timer::tick("LCAO_gen_fixedH","build_ST_new"); return; } @@ -535,7 +557,8 @@ void LCAO_gen_fixedH::build_Nonlocal_mu_new(double* NLloc, const bool &calc_deri ModuleBase::Vector3 dtau1, dtau2, tau0; double distance = 0.0; double rcut = 0.0; - double rcut1, rcut2; + double rcut1 = 0.0; + double rcut2 = 0.0; // Record_adj RA; // RA.for_2d(); @@ -624,7 +647,10 @@ void LCAO_gen_fixedH::build_Nonlocal_mu_new(double* NLloc, const bool &calc_deri const int iat = GlobalC::ucell.itia2iat(T0,I0); // mohan add 2010-12-19 - if( GlobalC::ucell.infoNL.nproj[T0] == 0) continue; + if( GlobalC::ucell.infoNL.nproj[T0] == 0) + { + continue; + } //const int I0 = GlobalC::GridD.getNatom(ad0); //const int start0 = GlobalC::ucell.itiaiw2iwt(T0, I0, 0); diff --git a/source/module_hamilt_lcao/module_gint/gint_k_pvpr.cpp b/source/module_hamilt_lcao/module_gint/gint_k_pvpr.cpp index ca672bcfbb9..4c179aabf8b 100644 --- a/source/module_hamilt_lcao/module_gint/gint_k_pvpr.cpp +++ b/source/module_hamilt_lcao/module_gint/gint_k_pvpr.cpp @@ -46,7 +46,10 @@ void Gint_k::destroy_pvpR(void) return; } - for(int is =0;ispvpR_alloc_flag = false; @@ -194,8 +197,6 @@ void Gint_k::folding_vl_k(const int &ik, for(int iw2 = 0; iw2nw; ++iw2) { vij[iw2_lo[iw2]] += vijR[iw2] * phase; - //if(((start1+iw == 238 ) && ( start2+iw2 == 1089 ))) - // GlobalV::ofs_running<<__FILE__<<__LINE__<<" "<nw; } @@ -699,4 +700,4 @@ void Gint_k::transfer_pvpR(hamilt::HContainer> *hR) ModuleBase::timer::tick("Gint_k","transfer_pvpR"); return; -} \ No newline at end of file +} diff --git a/source/module_io/cal_test.cpp b/source/module_io/cal_test.cpp index 3bccc866d14..9575b991f5d 100644 --- a/source/module_io/cal_test.cpp +++ b/source/module_io/cal_test.cpp @@ -4,54 +4,64 @@ #include "module_base/memory.h" #include "cal_test.h" -double Cal_Test::mporter; +double Cal_Test::mporter=0.0; // about charge density -double Cal_Test::mrho; -double Cal_Test::mrho_save; -double Cal_Test::mrho_core; +double Cal_Test::mrho=0.0; +double Cal_Test::mrho_save=0.0; +double Cal_Test::mrho_core=0.0; // about pulay mixing. -double Cal_Test::mRrho; -double Cal_Test::mdRrho; -double Cal_Test::mdrho; -double Cal_Test::mrho_save2; +double Cal_Test::mRrho=0.0; +double Cal_Test::mdRrho=0.0; +double Cal_Test::mdrho=0.0; +double Cal_Test::mrho_save2=0.0; // about potential on FFT grid. -double Cal_Test::mvltot; -double Cal_Test::mvr; -double Cal_Test::mvrs; -double Cal_Test::mvrs1; -double Cal_Test::mvnew; +double Cal_Test::mvltot=0.0; +double Cal_Test::mvr=0.0; +double Cal_Test::mvrs=0.0; +double Cal_Test::mvrs1=0.0; +double Cal_Test::mvnew=0.0; // about charge in g space. -double Cal_Test::mrhog; -double Cal_Test::mrhog_save; -double Cal_Test::mrhog_core; +double Cal_Test::mrhog=0.0; +double Cal_Test::mrhog_save=0.0; +double Cal_Test::mrhog_core=0.0; // others -double Cal_Test::mhs; -double Cal_Test::mwf; -double Cal_Test::mnonzero; -double Cal_Test::mspar_hsrho; +double Cal_Test::mhs=0.0; +double Cal_Test::mwf=0.0; +double Cal_Test::mnonzero=0.0; +double Cal_Test::mspar_hsrho=0.0; // plane waves -double Cal_Test::mgvec; -double Cal_Test::mig2fftw; -double Cal_Test::mig2fftc; -double Cal_Test::mgg; -double Cal_Test::mig123; -double Cal_Test::mstrucFac; -double Cal_Test::meigts123; - -double Cal_Test::mtot; - -void Cal_Test::test_memory(const ModulePW::PW_Basis* rhopw, const ModulePW::PW_Basis_K* wfcpw, const std::string chr_mixing_mode, const int chr_mixing_ndim) +double Cal_Test::mgvec=0.0; +double Cal_Test::mig2fftw=0.0; +double Cal_Test::mig2fftc=0.0; +double Cal_Test::mgg=0.0; +double Cal_Test::mig123=0.0; +double Cal_Test::mstrucFac=0.0; +double Cal_Test::meigts123=0.0; + +double Cal_Test::mtot=0.0; + +void Cal_Test::test_memory( + const ModulePW::PW_Basis* rhopw, + const ModulePW::PW_Basis_K* wfcpw, + const std::string chr_mixing_mode, + const int chr_mixing_ndim) { ModuleBase::TITLE("Cal_Test","test_memory"); const int ngmw = Cal_Test::cal_np(wfcpw->ggecut, rhopw->nx, rhopw->ny, rhopw->nz); const int ngmc = Cal_Test::cal_np(rhopw->ggecut, rhopw->nx, rhopw->ny, rhopw->nz); +// const int ecut_wfc = INPUT.ecutwfc; +// const int ecut_chg = INPUT.ecutrho; + +// const int ngmw = Cal_Test::cal_np(ecut_wfc, rhopw->nx, rhopw->ny, rhopw->nz); +// const int ngmc = Cal_Test::cal_np(ecut_chg, rhopw->nx, rhopw->ny, rhopw->nz); + std::cout << " number of atoms = " << GlobalC::ucell.nat << std::endl; std::cout << " plane wave number for wave functions = " << ngmw << std::endl; std::cout << " plane wave number for chage density = " << ngmc << std::endl; @@ -90,7 +100,6 @@ void Cal_Test::test_memory(const ModulePW::PW_Basis* rhopw, const ModulePW::PW_B // mohan comment out 2021-02-11 // mspar_hsrho = Memory::calculate_mem( Hnnz*3, "double"); - mgvec = ModuleBase::Memory::calculate_mem( ngmc * 3 * 2, "double" ); mig2fftw = ModuleBase::Memory::calculate_mem( ngmw , "int"); mig2fftc = ModuleBase::Memory::calculate_mem( ngmc , "int"); @@ -99,40 +108,51 @@ void Cal_Test::test_memory(const ModulePW::PW_Basis* rhopw, const ModulePW::PW_B mstrucFac = ModuleBase::Memory::calculate_mem( GlobalC::ucell.ntype*ngmc, "cdouble"); meigts123 = ModuleBase::Memory::calculate_mem( GlobalC::ucell.nat * (2*rhopw->nx+1+2*rhopw->ny+1+2*rhopw->nz+1), "cdouble"); -// std::cout << " Memory for " - - //(3) Memory for H,S matrix. std::cout << " NLOCAL = " << GlobalV::NLOCAL << std::endl; - std::cout << " NBANdS = " << GlobalV::NBANDS << std::endl; + std::cout << " NBANDS = " << GlobalV::NBANDS << std::endl; -// std::cout << " Memory for H,S matrix ( " -// << GlobalV::NLOCAL << ", " -// << GlobalV::NLOCAL << ") = " -// << mhs << " MB" << std::endl; + std::cout << " Memory for H,S matrix ( " + << GlobalV::NLOCAL << ", " + << GlobalV::NLOCAL << ") = " + << mhs << " MB" << std::endl; //(4) Memory for wave functions. -// std::cout << " Memory for wave functions ( " -// << GlobalV::NLOCAL << ", " -// << GlobalV::NBANDS << ") = " -// << mwf << " MB" << std::endl; + std::cout << " Memory for wave functions ( " + << GlobalV::NLOCAL << ", " + << GlobalV::NBANDS << ") = " + << mwf << " MB" << std::endl; print_mem(1); - print_mem(8); - print_mem(16); +// print_mem(8); +// print_mem(16); - if(GlobalC::ucell.nat > 200) - { - print_mem(32); - print_mem(64); - } +// if(GlobalC::ucell.nat > 200) +// { +// print_mem(32); +// print_mem(64); +// } return; } +//! compute the number of plane waves int Cal_Test::cal_np(const double &ggcut, const int &n1, const int &n2, const int &n3) { - int ibox[3]; + +/* + std::cout << "ggcut=" << ggcut << std::endl; + std::cout << "n1=" << n1 << std::endl; + std::cout << "n2=" << n2 << std::endl; + std::cout << "n3=" << n3 << std::endl; +*/ + + assert(n1>=0); + assert(n2>=0); + assert(n3>=0); + + int ibox[3]={0}; + // set the center at origin point. ibox[0] = int(n1 / 2.0) + 1; ibox[1] = int(n2 / 2.0) + 1; @@ -202,5 +222,7 @@ void Cal_Test::print_mem(const int &nproc) std::cout << " MEMORY FOR eigts1,2,3 : " << std::setw(15) << meigts123/nproc << " MB" << std::endl; std::cout << " TOTAL MEMORY : " << std::setw(15) << mtot/nproc << " MB" << std::endl; - std::cout << " MEMORY FOR nonzero : " << std::setw(15) << (double)GlobalV::NLOCAL*(GlobalV::NLOCAL+1)/1028/1028/2.0/nproc << " MB" << std::endl; //mohan for tmp + std::cout << " MEMORY FOR nonzero : " << std::setw(15) + << (double)GlobalV::NLOCAL*(GlobalV::NLOCAL+1)/1028/1028/2.0/nproc + << " MB" << std::endl; } diff --git a/source/module_io/cal_test.h b/source/module_io/cal_test.h index 636fd786d98..be272e914b2 100644 --- a/source/module_io/cal_test.h +++ b/source/module_io/cal_test.h @@ -9,7 +9,9 @@ namespace Cal_Test const ModulePW::PW_Basis_K* wfcpw, const std::string chr_mixing_mode, const int chr_mixing_ndim); + int cal_np(const double &ggcut, const int &n1, const int &n2, const int &n3); + void print_mem(const int &nproc); extern double mporter;