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
110 changes: 67 additions & 43 deletions source/module_hamilt_lcao/module_gint/gint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Gint::~Gint() {
delete this->hRGint_tmp[is];
}
#ifdef __MPI
delete this->DMRGint_full;
delete this->DM2D_tmp;
#endif
}

Expand Down Expand Up @@ -171,10 +171,9 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, const Grid_Driver* gd, cons
this->hRGint_tmp[is] = new hamilt::HContainer<double>(ucell_in.nat);
}
#ifdef __MPI
if (this->DMRGint_full != nullptr) {
delete this->DMRGint_full;
if (this->DM2D_tmp != nullptr) {
delete this->DM2D_tmp;
}
this->DMRGint_full = new hamilt::HContainer<double>(ucell_in.nat);
#endif
}

Expand All @@ -199,6 +198,8 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, const Grid_Driver* gd, cons
} else {
this->hRGintCd->insert_ijrs(this->gridt->get_ijr_info(), ucell_in, npol);
this->hRGintCd->allocate(nullptr, true);
ModuleBase::Memory::record("Gint::hRGintCd",
this->hRGintCd->get_memory_size());
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);
Expand All @@ -208,14 +209,7 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, const Grid_Driver* gd, cons
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);
#ifdef __MPI
this->DMRGint_full->insert_ijrs(this->gridt->get_ijr_info(), ucell_in, npol);
this->DMRGint_full->allocate(nullptr, true);
ModuleBase::Memory::record("Gint::DMRGint_full",
this->DMRGint_full->get_memory_size());
#endif
this->DMRGint[0]->get_memory_size()*nspin);
}
}

Expand All @@ -231,10 +225,8 @@ void Gint::reset_DMRGint(const int& nspin)
{
for (auto& d : this->DMRGint) { d->allocate(nullptr, false); }
#ifdef __MPI
delete this->DMRGint_full;
this->DMRGint_full = new hamilt::HContainer<double>(*this->hRGint);
this->DMRGint_full->allocate(nullptr, false);
#endif
delete this->DM2D_tmp;
#endif
}
}
}
Expand Down Expand Up @@ -262,37 +254,69 @@ void Gint::transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> DM2D) {
} else // NSPIN=4 case
{
#ifdef __MPI
hamilt::transferParallels2Serials(*DM2D[0], this->DMRGint_full);
#else
this->DMRGint_full = DM2D[0];
#endif
std::vector<double*> tmp_pointer(4, nullptr);
for (int iap = 0; iap < this->DMRGint_full->size_atom_pairs(); ++iap) {
auto& ap = this->DMRGint_full->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) {
const ModuleBase::Vector3<int> r_index = ap.get_R_index(ir);
for (int is = 0; is < 4; is++) {
tmp_pointer[is] = this->DMRGint[is]
->find_matrix(iat1, iat2, r_index)
->get_pointer();
}
double* data_full = ap.get_pointer(ir);
for (int irow = 0; irow < ap.get_row_size(); irow += 2) {
for (int icol = 0; icol < ap.get_col_size(); icol += 2) {
*(tmp_pointer[0])++ = data_full[icol];
*(tmp_pointer[1])++ = data_full[icol + 1];
}
data_full += ap.get_col_size();
for (int icol = 0; icol < ap.get_col_size(); icol += 2) {
*(tmp_pointer[2])++ = data_full[icol];
*(tmp_pointer[3])++ = data_full[icol + 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 *iat2iwt = new int[ucell->nat];
for (int iat = 0; iat < ucell->nat; iat++) {
iat2iwt[iat] = ucell->get_iat2iwt()[iat]/2;
}
Parallel_Orbitals *pv = new Parallel_Orbitals();
pv->set(mg, ng, nb, blacs_ctxt);
pv->set_atomic_trace(iat2iwt, ucell->nat, mg);
auto ijr_info = DM2D[0]->get_ijr_info();
this-> DM2D_tmp = new hamilt::HContainer<double>(pv, nullptr, &ijr_info);
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);
int iat1 = ap.get_atom_i();
int iat2 = ap.get_atom_j();
for (int ir = 0; ir < ap.get_R_size(); ++ir) {
const ModuleBase::Vector3<int> r_index = ap.get_R_index(ir);
double* tmp_pointer = this -> DM2D_tmp -> find_matrix(iat1, iat2, r_index)->get_pointer();
double* data_full = ap.get_pointer(ir);
for (int irow = 0; irow < ap.get_row_size(); irow += 2) {
switch (is) {//todo: It can be written more compactly
case 0:
for (int icol = 0; icol < ap.get_col_size(); icol += 2) {
*(tmp_pointer)++ = data_full[icol];
}
data_full += ap.get_col_size() * 2;
break;
case 1:
for (int icol = 0; icol < ap.get_col_size(); icol += 2) {
*(tmp_pointer)++ = data_full[icol + 1];
}
data_full += ap.get_col_size() * 2;
break;
case 2:
data_full += ap.get_col_size();
for (int icol = 0; icol < ap.get_col_size(); icol += 2) {
*(tmp_pointer)++ = data_full[icol];
}
data_full += ap.get_col_size();
break;
case 3:
data_full += ap.get_col_size();
for (int icol = 0; icol < ap.get_col_size(); icol += 2) {
*(tmp_pointer)++ = data_full[icol + 1];
}
data_full += ap.get_col_size();
break;
}
}
data_full += ap.get_col_size();
}
}
hamilt::transferParallels2Serials( *(this->DM2D_tmp), this->DMRGint[is]);
}
// delete iat2iwt;
// delete pv;
// delete this-> DM2D_tmp;
#else
//this->DMRGint_full = DM2D[0];
#endif
}
ModuleBase::timer::tick("Gint", "transfer_DMR");
}
2 changes: 1 addition & 1 deletion source/module_hamilt_lcao/module_gint/gint.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class Gint {
std::vector<hamilt::HContainer<double>*> DMRGint;

//! tmp tools used in transfer_DM2DtoGrid
hamilt::HContainer<double>* DMRGint_full = nullptr;
hamilt::HContainer<double>* DM2D_tmp = nullptr;

std::vector<hamilt::HContainer<double>> pvdpRx_reduced;
std::vector<hamilt::HContainer<double>> pvdpRy_reduced;
Expand Down
4 changes: 2 additions & 2 deletions source/module_lr/utils/gint_move.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ Gint& Gint::operator=(Gint&& rhs)
this->pvdpRz_reduced = std::move(rhs.pvdpRz_reduced);
this->DMRGint = std::move(rhs.DMRGint);
this->hRGint_tmp = std::move(rhs.hRGint_tmp);
this->DMRGint_full = rhs.DMRGint_full;
rhs.DMRGint_full = nullptr;
this->DM2D_tmp = rhs.DM2D_tmp;
rhs.DM2D_tmp = nullptr;

return *this;
}
Expand Down
Loading