Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions source/source_estate/elecstate_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void ElecStateLCAO<std::complex<double>>::psiToRho(const psi::Psi<std::complex<d

ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
#ifdef __OLD_GINT
this->gint_k->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
this->gint_k->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer dm2d to DM_grid in gint
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
this->gint_k->cal_gint(&inout);
#else
Expand Down Expand Up @@ -72,7 +72,7 @@ void ElecStateLCAO<double>::psiToRho(const psi::Psi<double>& psi)
ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");

#ifdef __OLD_GINT
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer dm2d to DM_grid in gint
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
this->gint_gamma->cal_gint(&inout);
#else
Expand Down Expand Up @@ -140,7 +140,7 @@ void ElecStateLCAO<double>::dmToRho(std::vector<double*> pexsi_DM, std::vector<d

ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
#ifdef __OLD_GINT
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer dm2d to DM_grid in gint
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
this->gint_gamma->cal_gint(&inout);
#else
Expand Down
10 changes: 5 additions & 5 deletions source/source_lcao/module_gint/gint.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Gint {

hamilt::HContainer<double>* get_hRGint() const { return hRGint; }

std::vector<hamilt::HContainer<double>*> get_DMRGint() const { return DMRGint; }
std::vector<hamilt::HContainer<double>*> get_DMRGint() const { return dmr_gint; }

int get_ncxyz() const { return ncxyz; }

Expand Down Expand Up @@ -58,14 +58,14 @@ class Gint {
void initialize_pvpR(const UnitCell& unitcell, const Grid_Driver* gd, const int& nspin);

/**
* @brief resize DMRGint to nspin and reallocate the memory
* @brief resize dmr_gint to nspin and reallocate the memory
*/
void reset_DMRGint(const int& nspin);

/**
* @brief transfer DMR (2D para) to DMR (Grid para) in elecstate_lcao.cpp
*/
void transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> DM2D);
void transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> dm2d);

const Grid_Technique* gridt = nullptr;
const UnitCell* ucell;
Expand Down Expand Up @@ -256,13 +256,13 @@ class Gint {
hamilt::HContainer<double>* hRGint = nullptr;

//! size of vec is 4, only used when nspin = 4
std::vector<hamilt::HContainer<double>*> hRGint_tmp;
std::vector<hamilt::HContainer<double>*> hr_gint_tmp;

//! stores Hamiltonian in sparse format
hamilt::HContainer<std::complex<double>>* hRGintCd = nullptr;

//! stores DMR in sparse format
std::vector<hamilt::HContainer<double>*> DMRGint;
std::vector<hamilt::HContainer<double>*> dmr_gint;

//! tmp tools used in transfer_DM2DtoGrid
hamilt::HContainer<double>* dm2d_tmp = nullptr;
Expand Down
10 changes: 5 additions & 5 deletions source/source_lcao/module_gint/gint_force_cpu_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void Gint::gint_kernel_force(Gint_inout* inout) {
cal_flag.get_ptr_2D(),
psir_vlbr3.get_ptr_2D(),
psir_vlbr3_DM.get_ptr_2D(),
this->DMRGint[inout->ispin],
this->dmr_gint[inout->ispin],
false);

if(inout->isforce)
Expand Down Expand Up @@ -230,19 +230,19 @@ void Gint::gint_kernel_force_meta(Gint_inout* inout) {
//calculating g_mu(r) = sum_nu rho_mu,nu f_nu(r)
Gint_Tools::mult_psi_DMR(*this->gridt, this->bxyz, LD_pool, grid_index,
na_grid, block_index.data(), block_size.data(), cal_flag.get_ptr_2D(),
psir_vlbr3.get_ptr_2D(), psir_vlbr3_DM.get_ptr_2D(), this->DMRGint[inout->ispin], false);
psir_vlbr3.get_ptr_2D(), psir_vlbr3_DM.get_ptr_2D(), this->dmr_gint[inout->ispin], false);

Gint_Tools::mult_psi_DMR(*this->gridt, this->bxyz, LD_pool, grid_index,
na_grid, block_index.data(), block_size.data(), cal_flag.get_ptr_2D(),
dpsir_x_vlbr3.get_ptr_2D(), dpsirx_v_DM.get_ptr_2D(), this->DMRGint[inout->ispin], false);
dpsir_x_vlbr3.get_ptr_2D(), dpsirx_v_DM.get_ptr_2D(), this->dmr_gint[inout->ispin], false);

Gint_Tools::mult_psi_DMR(*this->gridt, this->bxyz, LD_pool, grid_index,
na_grid, block_index.data(), block_size.data(), cal_flag.get_ptr_2D(),
dpsir_y_vlbr3.get_ptr_2D(), dpsiry_v_DM.get_ptr_2D(), this->DMRGint[inout->ispin], false);
dpsir_y_vlbr3.get_ptr_2D(), dpsiry_v_DM.get_ptr_2D(), this->dmr_gint[inout->ispin], false);

Gint_Tools::mult_psi_DMR(*this->gridt, this->bxyz, LD_pool, grid_index,
na_grid, block_index.data(), block_size.data(), cal_flag.get_ptr_2D(),
dpsir_z_vlbr3.get_ptr_2D(), dpsirz_v_DM.get_ptr_2D(), this->DMRGint[inout->ispin], false);
dpsir_z_vlbr3.get_ptr_2D(), dpsirz_v_DM.get_ptr_2D(), this->dmr_gint[inout->ispin], false);

if(inout->isforce)
{
Expand Down
6 changes: 3 additions & 3 deletions source/source_lcao/module_gint/gint_gpu_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void Gint::gpu_vlocal_interface(Gint_inout* inout) {
ylmcoef[i] = ModuleBase::Ylm::ylmcoef[i];
}

hamilt::HContainer<double>* hRGint_kernel = PARAM.inp.nspin != 4 ? this->hRGint : this->hRGint_tmp[inout->ispin];
hamilt::HContainer<double>* hRGint_kernel = PARAM.inp.nspin != 4 ? this->hRGint : this->hr_gint_tmp[inout->ispin];
GintKernel::gint_vl_gpu(hRGint_kernel,
inout->vl,
ylmcoef,
Expand All @@ -45,7 +45,7 @@ void Gint::gpu_rho_interface(Gint_inout* inout) {
int nrxx = this->gridt->ncx * this->gridt->ncy * this->nplane;
for (int is = 0; is < PARAM.inp.nspin; ++is) {
ModuleBase::GlobalFunc::ZEROS(inout->rho[is], nrxx);
GintKernel::gint_rho_gpu(this->DMRGint[is],
GintKernel::gint_rho_gpu(this->dmr_gint[is],
ylmcoef,
dr,
this->gridt->rcuts.data(),
Expand Down Expand Up @@ -76,7 +76,7 @@ void Gint::gpu_force_interface(Gint_inout* inout) {
if (isforce || isstress) {
std::vector<double> force(nat * 3, 0.0);
std::vector<double> stress(6, 0.0);
GintKernel::gint_fvl_gpu(this->DMRGint[inout->ispin],
GintKernel::gint_fvl_gpu(this->dmr_gint[inout->ispin],
inout->vl,
force.data(),
stress.data(),
Expand Down
8 changes: 4 additions & 4 deletions source/source_lcao/module_gint/gint_k_pvpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
{
hamilt::AtomPair<std::complex<double>>* upper_ap = ap;
hamilt::AtomPair<std::complex<double>>* lower_ap = this->hRGintCd->find_pair(iat2, iat1);
const hamilt::AtomPair<double>* ap_nspin_0 = this->hRGint_tmp[0]->find_pair(iat1, iat2);
const hamilt::AtomPair<double>* ap_nspin_3 = this->hRGint_tmp[3]->find_pair(iat1, iat2);
const hamilt::AtomPair<double>* ap_nspin_0 = this->hr_gint_tmp[0]->find_pair(iat1, iat2);
const hamilt::AtomPair<double>* ap_nspin_3 = this->hr_gint_tmp[3]->find_pair(iat1, iat2);
for (int ir = 0; ir < upper_ap->get_R_size(); ir++)
{
const auto R_index = upper_ap->get_R_index(ir);
Expand All @@ -110,8 +110,8 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,

if (PARAM.globalv.domag)
{
const hamilt::AtomPair<double>* ap_nspin_1 = this->hRGint_tmp[1]->find_pair(iat1, iat2);
const hamilt::AtomPair<double>* ap_nspin_2 = this->hRGint_tmp[2]->find_pair(iat1, iat2);
const hamilt::AtomPair<double>* ap_nspin_1 = this->hr_gint_tmp[1]->find_pair(iat1, iat2);
const hamilt::AtomPair<double>* ap_nspin_2 = this->hr_gint_tmp[2]->find_pair(iat1, iat2);
const auto mat_nspin_1 = ap_nspin_1->find_matrix(R_index);
const auto mat_nspin_2 = ap_nspin_2->find_matrix(R_index);
for (int irow = 0; irow < mat_nspin_1->get_row_size(); ++irow)
Expand Down
132 changes: 69 additions & 63 deletions source/source_lcao/module_gint/gint_old.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ Gint::~Gint() {

delete this->hRGint;
delete this->hRGintCd;
// in gamma_only case, DMRGint.size()=0,
// in multi-k case, DMRGint.size()=nspin
for (int is = 0; is < this->DMRGint.size(); is++) {
delete this->DMRGint[is];
// in gamma_only case, dmr_gint.size()=0,
// in multi-k case, dmr_gint.size()=nspin
for (int is = 0; is < this->dmr_gint.size(); is++) {
delete this->dmr_gint[is];
}
for(int is = 0; is < this->hRGint_tmp.size(); is++) {
delete this->hRGint_tmp[is];
for(int is = 0; is < this->hr_gint_tmp .size(); is++) {
delete this->hr_gint_tmp [is];
}
#ifdef __MPI
delete this->dm2d_tmp;
Expand Down Expand Up @@ -141,13 +141,12 @@ void Gint::prep_grid(const Grid_Technique& gt,
void Gint::initialize_pvpR(const UnitCell& ucell_in, const Grid_Driver* gd, const int& nspin)
{
ModuleBase::TITLE("Gint", "initialize_pvpR");

int npol = 1;
// there is the only resize code of DMRGint
if (this->DMRGint.size() == 0) {
this->DMRGint.resize(nspin);
// there is the only resize code of dmr_gint
if (this->dmr_gint.size() == 0) {
this->dmr_gint.resize(nspin);
}
hRGint_tmp.resize(nspin);
hr_gint_tmp.resize(nspin);
if (nspin != 4) {
if (this->hRGint != nullptr) {
delete this->hRGint;
Expand All @@ -161,22 +160,21 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, const Grid_Driver* gd, cons
this->hRGintCd
= new hamilt::HContainer<std::complex<double>>(ucell_in.nat);
for (int is = 0; is < nspin; is++) {
if (this->DMRGint[is] != nullptr) {
delete this->DMRGint[is];
if (this->dmr_gint[is] != nullptr) {
delete this->dmr_gint[is];
}
if (this->hRGint_tmp[is] != nullptr) {
delete this->hRGint_tmp[is];
if (this->hr_gint_tmp[is] != nullptr) {
delete this->hr_gint_tmp[is];
}
this->DMRGint[is] = new hamilt::HContainer<double>(ucell_in.nat);
this->hRGint_tmp[is] = new hamilt::HContainer<double>(ucell_in.nat);
this->dmr_gint[is] = new hamilt::HContainer<double>(ucell_in.nat);
this->hr_gint_tmp[is] = new hamilt::HContainer<double>(ucell_in.nat);
}
#ifdef __MPI
if (this->dm2d_tmp != nullptr) {
delete this->dm2d_tmp;
}
#endif
}

if (PARAM.globalv.gamma_only_local && nspin != 4) {
this->hRGint->fix_gamma();
}
Expand All @@ -185,94 +183,100 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, const Grid_Driver* gd, cons
this->hRGint->allocate(nullptr, true);
ModuleBase::Memory::record("Gint::hRGint",
this->hRGint->get_memory_size());
// initialize DMRGint with hRGint when NSPIN != 4
for (int is = 0; is < this->DMRGint.size(); is++) {
if (this->DMRGint[is] != nullptr) {
delete this->DMRGint[is];
// initialize dmr_gint with hRGint when NSPIN != 4
for (int is = 0; is < this->dmr_gint.size(); is++) {
if (this->dmr_gint[is] != nullptr) {
delete this->dmr_gint[is];
}
this->DMRGint[is] = new hamilt::HContainer<double>(*this->hRGint);
this->dmr_gint[is] = new hamilt::HContainer<double>(*this->hRGint);
}
ModuleBase::Memory::record("Gint::DMRGint",
this->DMRGint[0]->get_memory_size()
* this->DMRGint.size());
ModuleBase::Memory::record("Gint::dmr_gint",
this->dmr_gint[0]->get_memory_size()
* this->dmr_gint.size());
} else {
this->hRGintCd->insert_ijrs(this->gridt->get_ijr_info(), ucell_in, npol);
this->hRGintCd->allocate(nullptr, true);
for(int is = 0; is < nspin; is++) {
this->hRGint_tmp[is]->insert_ijrs(this->gridt->get_ijr_info(), ucell_in);
this->DMRGint[is]->insert_ijrs(this->gridt->get_ijr_info(), ucell_in);
this->hRGint_tmp[is]->allocate(nullptr, true);
this->DMRGint[is]->allocate(nullptr, true);
this->hr_gint_tmp[is]->insert_ijrs(this->gridt->get_ijr_info(), ucell_in);
this->dmr_gint[is]->insert_ijrs(this->gridt->get_ijr_info(), ucell_in);
this->hr_gint_tmp[is]->allocate(nullptr, true);
this->dmr_gint[is]->allocate(nullptr, true);
}
ModuleBase::Memory::record("Gint::hRGint_tmp",
this->hRGint_tmp[0]->get_memory_size()*nspin);
ModuleBase::Memory::record("Gint::DMRGint",
this->DMRGint[0]->get_memory_size()
* this->DMRGint.size()*nspin);
ModuleBase::Memory::record("Gint::hr_gint_tmp",
this->hr_gint_tmp[0]->get_memory_size()*nspin);
ModuleBase::Memory::record("Gint::dmr_gint",
this->dmr_gint[0]->get_memory_size()
* this->dmr_gint.size()*nspin);
}
}

void Gint::reset_DMRGint(const int& nspin)
{
if (this->hRGint)
{
for (auto& d : this->DMRGint) { delete d; }
this->DMRGint.resize(nspin);
this->DMRGint.shrink_to_fit();
for (auto& d : this->DMRGint) { d = new hamilt::HContainer<double>(*this->hRGint); }
for (auto& d : this->dmr_gint) { delete d; }
this->dmr_gint.resize(nspin);
this->dmr_gint.shrink_to_fit();
for (auto& d : this->dmr_gint) { d = new hamilt::HContainer<double>(*this->hRGint); }
if (nspin == 4)
{
for (auto& d : this->DMRGint) { d->allocate(nullptr, false); }
for (auto& d : this->dmr_gint) { d->allocate(nullptr, false); }
#ifdef __MPI
delete this->dm2d_tmp;
#endif
}
}
}

void Gint::transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> DM2D) {
void Gint::transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> dm2d) {
ModuleBase::TITLE("Gint", "transfer_DMR");

// To check whether input parameter DM2D has been initialized
// To check whether input parameter dm2d has been initialized
#ifdef __DEBUG
assert(!DM2D.empty()
&& "Input parameter DM2D has not been initialized while calling "
assert(!dm2d.empty()
&& "Input parameter dm2d has not been initialized while calling "
"function transfer_DM2DtoGrid!");
#endif

ModuleBase::timer::tick("Gint", "transfer_DMR");
if (PARAM.inp.nspin != 4) {
for (int is = 0; is < this->DMRGint.size(); is++) {
for (int is = 0; is < this->dmr_gint.size(); is++) {
#ifdef __MPI
hamilt::transferParallels2Serials(*DM2D[is], DMRGint[is]);
hamilt::transferParallels2Serials(*dm2d[is], dmr_gint[is]);
#else
this->DMRGint[is]->set_zero();
this->DMRGint[is]->add(*DM2D[is]);
this->dmr_gint[is]->set_zero();
this->dmr_gint[is]->add(*dm2d[is]);
#endif
}
} else // NSPIN=4 case
{
#ifdef __MPI
// is=0:↑↑, 1:↑↓, 2:↓↑, 3:↓↓
const int row_set[4] = {0, 0, 1, 1};
const int col_set[4] = {0, 1, 0, 1};
int mg = DM2D[0]->get_paraV()->get_global_row_size()/2;
int ng = DM2D[0]->get_paraV()->get_global_col_size()/2;
int nb = DM2D[0]->get_paraV()->get_block_size()/2;
int blacs_ctxt = DM2D[0]->get_paraV()->blacs_ctxt;
int mg = dm2d[0]->get_paraV()->get_global_row_size()/2;
int ng = dm2d[0]->get_paraV()->get_global_col_size()/2;
int nb = dm2d[0]->get_paraV()->get_block_size()/2;
auto ijr_info = dm2d[0]->get_ijr_info();
#ifdef __MPI
int blacs_ctxt = dm2d[0]->get_paraV()->blacs_ctxt;
std::vector<int> iat2iwt(ucell->nat);
for (int iat = 0; iat < ucell->nat; iat++) {
iat2iwt[iat] = ucell->get_iat2iwt()[iat]/2;
}
Parallel_Orbitals pv{};
pv.set(mg, ng, nb, blacs_ctxt);
pv.set_atomic_trace(iat2iwt.data(), ucell->nat, mg);
auto ijr_info = DM2D[0]->get_ijr_info();
this-> dm2d_tmp = new hamilt::HContainer<double>(&pv, nullptr, &ijr_info);
#else
if (this->dm2d_tmp != nullptr) {
delete this->dm2d_tmp;
}
this-> dm2d_tmp = new hamilt::HContainer<double>(*this->hRGint);
this-> dm2d_tmp -> insert_ijrs(this->gridt->get_ijr_info(), *(this->ucell));
this-> dm2d_tmp -> allocate(nullptr, true);
#endif
ModuleBase::Memory::record("Gint::dm2d_tmp", this->dm2d_tmp->get_memory_size());
for (int is = 0; is < 4; is++){
for (int iap = 0; iap < DM2D[0]->size_atom_pairs(); ++iap) {
auto& ap = DM2D[0]->get_atom_pair(iap);
for (int iap = 0; iap < dm2d[0]->size_atom_pairs(); ++iap) {
auto& ap = dm2d[0]->get_atom_pair(iap);
int iat1 = ap.get_atom_i();
int iat2 = ap.get_atom_j();
for (int ir = 0; ir < ap.get_R_size(); ++ir) {
Expand All @@ -288,13 +292,15 @@ void Gint::transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> DM2D) {
}
}
}
hamilt::transferParallels2Serials( *(this->dm2d_tmp), this->DMRGint[is]);
}
delete this->dm2d_tmp;
this->dm2d_tmp = nullptr;
#ifdef __MPI
hamilt::transferParallels2Serials( *(this->dm2d_tmp), this->dmr_gint[is]);
#else
//this->DMRGint_full = DM2D[0];
this->dmr_gint[is]->set_zero();
this->dmr_gint[is]->add(*(this->dm2d_tmp));
#endif
}//is=4
delete this->dm2d_tmp;
this->dm2d_tmp = nullptr;
}
ModuleBase::timer::tick("Gint", "transfer_DMR");
}
Loading
Loading