Skip to content

Commit 9438146

Browse files
zgn-26714dyzheng
andauthored
Added the serial version incorporating code changes from deepmodeling#6487 and deepmodeling#6488. (deepmodeling#6511)
* Fixed the bug in memory statistics * delete tem Hcontainer to reduce memory usage * delete tem hRGintCd to reduce memory usage * fix parallel bug * Simplify the computational code * improve the serial code * fix bug --------- Co-authored-by: dyzheng <zhengdy@bjaisi.com>
1 parent 0f13efe commit 9438146

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

source/module_hamilt_lcao/module_gint/gint.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,25 +247,33 @@ void Gint::transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> DM2D) {
247247
}
248248
} else // NSPIN=4 case
249249
{
250-
#ifdef __MPI
250+
251251
// is=0:↑↑, 1:↑↓, 2:↓↑, 3:↓↓
252252
const int row_set[4] = {0, 0, 1, 1};
253253
const int col_set[4] = {0, 1, 0, 1};
254254
int mg = DM2D[0]->get_paraV()->get_global_row_size()/2;
255255
int ng = DM2D[0]->get_paraV()->get_global_col_size()/2;
256256
int nb = DM2D[0]->get_paraV()->get_block_size()/2;
257+
auto ijr_info = DM2D[0]->get_ijr_info();
258+
#ifdef __MPI
257259
int blacs_ctxt = DM2D[0]->get_paraV()->blacs_ctxt;
258-
259260
std::vector<int> iat2iwt(ucell->nat);
260261
for (int iat = 0; iat < ucell->nat; iat++) {
261262
iat2iwt[iat] = ucell->get_iat2iwt()[iat]/2;
262263
}
263264
Parallel_Orbitals *pv = new Parallel_Orbitals();
264265
pv->set(mg, ng, nb, blacs_ctxt);
265266
pv->set_atomic_trace(iat2iwt.data(), ucell->nat, mg);
266-
auto ijr_info = DM2D[0]->get_ijr_info();
267267
this-> DM2D_tmp = new hamilt::HContainer<double>(pv, nullptr, &ijr_info);
268268
this-> DM2D_tmp->set_zero();
269+
#else
270+
if (this->DM2D_tmp != nullptr) {
271+
delete this->DM2D_tmp;
272+
}
273+
this-> DM2D_tmp = new hamilt::HContainer<double>(*this->hRGint);
274+
this-> DM2D_tmp -> insert_ijrs(this->gridt->get_ijr_info(), *(this->ucell));
275+
this-> DM2D_tmp -> allocate(nullptr, true);
276+
#endif
269277
ModuleBase::Memory::record("Gint::DM2D_tmp", this->DM2D_tmp->get_memory_size());
270278
for (int is = 0; is < 4; is++){
271279
for (int iap = 0; iap < DM2D[0]->size_atom_pairs(); ++iap) {
@@ -274,7 +282,7 @@ void Gint::transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> DM2D) {
274282
int iat2 = ap.get_atom_j();
275283
for (int ir = 0; ir < ap.get_R_size(); ++ir) {
276284
const ModuleBase::Vector3<int> r_index = ap.get_R_index(ir);
277-
double* matrix_out = DM2D_tmp -> find_matrix(iat1, iat2, r_index)->get_pointer();
285+
double* matrix_out = this-> DM2D_tmp -> find_matrix(iat1, iat2, r_index)->get_pointer();
278286
double* matrix_in = ap.get_pointer(ir);
279287
for (int irow = 0; irow < ap.get_row_size()/2; irow ++) {
280288
for (int icol = 0; icol < ap.get_col_size()/2; icol ++) {
@@ -285,11 +293,14 @@ void Gint::transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> DM2D) {
285293
}
286294
}
287295
}
296+
#ifdef __MPI
288297
hamilt::transferParallels2Serials( *(this->DM2D_tmp), this->DMRGint[is]);
289-
}
290298
#else
291-
//this->DMRGint_full = DM2D[0];
299+
this->DMRGint[is]->set_zero();
300+
this->DMRGint[is]->add(*(this->DM2D_tmp));
292301
#endif
302+
}
303+
293304
}
294305
ModuleBase::timer::tick("Gint", "transfer_DMR");
295306
}

source/module_hamilt_lcao/module_gint/gint_k_pvpr.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
7878
ModuleBase::TITLE("Gint_k", "transfer_pvpR");
7979
ModuleBase::timer::tick("Gint_k", "transfer_pvpR");
8080

81+
auto ijr_info = hR->get_ijr_info();
82+
83+
#ifdef __MPI
8184
int mg = hR->get_paraV()->get_global_row_size()/2;
8285
int ng = hR->get_paraV()->get_global_col_size()/2;
8386
int nb = hR->get_paraV()->get_block_size()/2;
84-
#ifdef __MPI
8587
int blacs_ctxt = hR->get_paraV()->blacs_ctxt;
8688
std::vector<int> iat2iwt(ucell_in->nat);
8789
for (int iat = 0; iat < ucell_in->nat; iat++) {
@@ -90,9 +92,9 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
9092
Parallel_Orbitals *pv = new Parallel_Orbitals();
9193
pv->set(mg, ng, nb, blacs_ctxt);
9294
pv->set_atomic_trace(iat2iwt.data(), ucell_in->nat, mg);
93-
auto ijr_info = hR->get_ijr_info();
94-
9595
this->hR_tmp = new hamilt::HContainer<std::complex<double>>(pv, nullptr, &ijr_info);
96+
#endif
97+
9698
ModuleBase::Memory::record("Gint::hRGintCd", this->hR_tmp->get_memory_size());
9799

98100
//select hRGint_tmp
@@ -155,8 +157,12 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
155157
}
156158
}
157159
}
160+
#ifdef __MPI
158161
// transfer hRGint_tmpCd to parallel hR_tmp
159162
hamilt::transferSerials2Parallels( *hRGint_tmpCd, this->hR_tmp);
163+
#else
164+
this->hR_tmp = hRGint_tmpCd;
165+
#endif
160166
// merge hR_tmp to hR
161167
for (int iap = 0; iap < hR->size_atom_pairs(); iap++)
162168
{
@@ -182,9 +188,6 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
182188
}
183189
delete hRGint_tmpCd;
184190
}
185-
#else
186-
187-
#endif
188191
ModuleBase::timer::tick("Gint_k", "transfer_pvpR");
189192
return;
190193
}

0 commit comments

Comments
 (0)