Skip to content

Commit

Permalink
Enable 'calculation=test_memory" function again (#3919)
Browse files Browse the repository at this point in the history
* update timer, add std

* update the format of esolver_fp.cpp

* add description in esolver_fp.h

* update a few esolver files

* update esolver description for LCAO

* update some formats of esolver codes

* update esolver_ks_pw.cpp formats

* update formats of esolver_ks_pw.cpp and esolver_ks_pw.h

* update esolver_ks_lcao_tddft.cpp formats

* update format of esolver_sdft_pw.cpp

* update the format of esolver_sdft_pw_tool.cpp

* keep formating esolver_ks_pw.cpp

* formating esolver_of_interface.cpp

* change GlobalC::ucell to ucell in esolver_ks.cpp

* remove some GlobalC::ucell in esolver_sdft_pw.cpp

* refactor the code before getting rid of RA in esolver_lcao

* refactor before getting rid of LOWF

* refactor before getting rid of LCAO_hamilt.h and LCAO_matrix.h

* refactor wavefunc_in_pw

* refactor density matrix

* refactor the format cal_dm_psi.cpp

* format forces.cpp

* refactor esolver_of_tool.cpp

* change member function beforescf in Esolver to before_scf

* change afterscf to after_scf

* change updatepot to update_pot

* change eachiterinit to iter_init, change eachiterfinish to iter_finish

* refactor esolvers, change member function names of most esolvers

* reformat esolver.h

* update tests for esolvers

* add TITLE in esolver_ks_lcao

* update esolver_ks_lcao

* update esolver_lcao

* update timer::tick in esolver_lcao

* try to delete LCAO_Matrix in LCAO_Hamilt, and try to delete Parallel_Orbitals in Force_k

* fix the compiling issue with LCAO_hamilt.hpp

* try to divide the FORCE_k.cpp into several small files

* divide FORCE_k into foverlap_k.cpp ftvnl_dphi_k.cpp fvl_dphi_k.cpp fvnl_dbeta_k.cpp four files

* get rid of UHM in FORCE_k.cpp

* cannot compile, but I have modified some files in order to get rid of Gint_k and Gint_Gamma in UHM

* keep updating, cannot run

* update write_Vxc, cannot run yet

* keep updating gint_gamma and gint_k

* update LCAO_matrix.cpp

* divide force files, and update Makefile.Objects

* update LCAO_hamilt.cpp

* delete genH pointer in UHM

* divide LCAO_hamilt.cpp into small codes, grid_init.cpp is the first one

* update grid_init in esolver_ks_lcao

* add a new namespace named sparse_format, most of the functions that originally belong to LCAO_hamilt should be moved to sparse_format

* cannot find the mismatch of DFTU

* fix the DFTU error

* update

* enable the test_memory function again by setting calcalculation parameter in INPUT file

* update memory record functions
  • Loading branch information
mohanchen committed Apr 5, 2024
1 parent 8bee71b commit 534d1d8
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 131 deletions.
15 changes: 3 additions & 12 deletions source/driver_run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,15 @@ 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);


#ifdef __RAPIDJSON
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);
Expand All @@ -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);

Expand Down
Empty file modified source/module_base/math_chebyshev_def.h
100755 → 100644
Empty file.
44 changes: 20 additions & 24 deletions source/module_base/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// AUTHOR : mohan
// DATE : 2008-11-18
//==========================================================
#include <cassert>
#include "memory.h"
#include "global_variable.h"
#include "module_base/parallel_reduce.h"
Expand Down Expand Up @@ -230,20 +231,26 @@ void Memory::finish(std::ofstream &ofs)

void Memory::print_all(std::ofstream &ofs)
{
// std::cout<<"\n init_flag="<<init_flag;
if(!init_flag) return;
if(!init_flag)
{
return;
}

const double small = 1.0;
const double small = 1.0; // unit is MB
#ifdef __MPI
Parallel_Reduce::reduce_all(Memory::total);
Parallel_Reduce::reduce_all(Memory::total);
#endif
ofs <<"\n NAME---------------|MEMORY(MB)--------" << std::endl;
// std::cout<<"\n"<<std::setw(41)<< " " <<std::setprecision(4)<<total;
ofs <<std::setw(20)<< "total" << std::setw(15) <<std::setprecision(4)<< Memory::total << std::endl;
ofs <<"\n NAME-------------------------|MEMORY(MB)--------" << std::endl;
ofs <<std::setw(30)<< "total" << std::setw(15) <<std::setprecision(4)<< Memory::total << std::endl;

assert(n_memory>0);

bool *print_flag = new bool[n_memory];
for(int i=0; i<n_memory; i++) print_flag[i] = false;


for(int i=0; i<n_memory; i++)
{
print_flag[i] = false;
}

for (int i=0; i<n_memory; i++)
{
Expand Down Expand Up @@ -285,32 +292,21 @@ void Memory::print_all(std::ofstream &ofs)
}
}
print_flag[k] = true;
if ( consume[k] < small ){
if ( consume[k] < small )
{
continue;
}
else
{
ofs << std::setw(20) << name[k]
ofs << std::setw(30) << name[k]
<< std::setw(15) << consume[k] << std::endl;
}

}
// if ( consume[k] < small )
// {
// continue;
// }
// else
// {
// ofs << std::setw(20) << name[k]
// << std::setw(15) << consume[k] << std::endl;

// std::cout << "\n "
// << std::setw(20) << class_name[k]
// << std::setw(20) << name[k]
// << std::setw(15) << consume[k];
//std::cout<<"\n ----------------------------------------------------------"<<std::endl;
ofs<<" ------------- < 1.0 MB has been ignored ----------------"<<std::endl;
ofs<<" ----------------------------------------------------------"<<std::endl;

delete[] print_flag; //mohan fix by valgrind at 2012-04-02
return;
}
Expand Down
Empty file modified source/module_base/module_mixing/broyden_mixing.h
100755 → 100644
Empty file.
6 changes: 6 additions & 0 deletions source/module_esolver/esolver_fp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ ESolver_FP::~ESolver_FP()

void ESolver_FP::init(Input& inp, UnitCell& cell)
{
ModuleBase::TITLE("ESolver_FP", "init");

if(!GlobalV::use_paw)
{
cell.read_pseudo(GlobalV::ofs_running);
Expand Down Expand Up @@ -96,6 +98,8 @@ void ESolver_FP::init(Input& inp, UnitCell& cell)
}

this->print_rhofft(inp, GlobalV::ofs_running);

return;
}


Expand Down Expand Up @@ -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;
}


Expand Down
11 changes: 4 additions & 7 deletions source/module_esolver/esolver_ks.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
#include "esolver_ks.h"

#include <time.h>
#ifdef __MPI
#include <mpi.h>
#else
#include <chrono>
#endif

#include <iostream>

#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
Expand Down Expand Up @@ -75,6 +68,8 @@ ESolver_KS<T, Device>::~ESolver_KS()
template<typename T, typename Device>
void ESolver_KS<T, Device>::init(Input& inp, UnitCell& ucell)
{
ModuleBase::TITLE("ESolver_KS", "init");

ESolver_FP::init(inp,ucell);

//------------------Charge Mixing------------------
Expand Down Expand Up @@ -380,6 +375,8 @@ void ESolver_KS<T, Device>::print_wfcfft(Input& inp, std::ofstream &ofs)
template<typename T, typename Device>
void ESolver_KS<T, Device>::run(const int istep, UnitCell& ucell)
{
ModuleBase::TITLE("ESolver_KS", "run");

if (!(GlobalV::CALCULATION == "scf"
|| GlobalV::CALCULATION == "md"
|| GlobalV::CALCULATION == "relax"
Expand Down
58 changes: 41 additions & 17 deletions source/module_esolver/esolver_ks_lcao_elec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,14 @@ void ESolver_KS_LCAO<TK, TR>::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);
Expand All @@ -331,9 +335,10 @@ void ESolver_KS_LCAO<TK, TR>::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);
Expand All @@ -350,22 +355,21 @@ void ESolver_KS_LCAO<TK, TR>::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,
this->p_chgmix->get_mixing_mode(),
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)
Expand Down Expand Up @@ -452,14 +456,18 @@ void ESolver_KS_LCAO<TK, TR>::others(const int istep)
ModuleBase::timer::tick("ESolver_KS_LCAO", "others");
return;
}


template <>
void ESolver_KS_LCAO<double, double>::get_S()
void ESolver_KS_LCAO<double, double>::get_S(void)
{
ModuleBase::TITLE("ESolver_KS_LCAO", "get_S");
ModuleBase::WARNING_QUIT("ESolver_KS_LCAO<TK, TR>::get_S", "not implemented for");
ModuleBase::WARNING_QUIT("ESolver_KS_LCAO<double,double>::get_S", "not implemented for");
}


template <>
void ESolver_KS_LCAO<std::complex<double>, double>::get_S()
void ESolver_KS_LCAO<std::complex<double>, double>::get_S(void)
{
ModuleBase::TITLE("ESolver_KS_LCAO", "get_S");
// (1) Find adjacent atoms for each atom.
Expand All @@ -477,17 +485,21 @@ void ESolver_KS_LCAO<std::complex<double>, 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<std::complex<double>, double>(&this->LM, this->kv);
dynamic_cast<hamilt::OperatorLCAO<std::complex<double>, double>*>(this->p_hamilt->ops)->contributeHR();
}

ModuleIO::output_S_R(this->uhm, this->p_hamilt, "SR.csr");
}


template <>
void ESolver_KS_LCAO<std::complex<double>, std::complex<double>>::get_S()
void ESolver_KS_LCAO<std::complex<double>, std::complex<double>>::get_S(void)
{
ModuleBase::TITLE("ESolver_KS_LCAO", "get_S");
// (1) Find adjacent atoms for each atom.
Expand Down Expand Up @@ -516,8 +528,9 @@ void ESolver_KS_LCAO<std::complex<double>, std::complex<double>>::get_S()
ModuleIO::output_S_R(this->uhm, this->p_hamilt, "SR.csr");
}


template <typename TK, typename TR>
void ESolver_KS_LCAO<TK, TR>::nscf()
void ESolver_KS_LCAO<TK, TR>::nscf(void)
{
ModuleBase::TITLE("ESolver_KS_LCAO", "nscf");

Expand All @@ -533,9 +546,13 @@ void ESolver_KS_LCAO<TK, TR>::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<TK, TR>* hamilt_lcao = dynamic_cast<hamilt::HamiltLCAO<TK, TR>*>(this->p_hamilt);
auto exx = new hamilt::OperatorEXX<hamilt::OperatorLCAO<TK, TR>>(&this->LM,
Expand Down Expand Up @@ -625,7 +642,14 @@ void ESolver_KS_LCAO<TK, TR>::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)
{
Expand Down

0 comments on commit 534d1d8

Please sign in to comment.