Skip to content

Commit 67685db

Browse files
author
dyzheng
committed
test
1 parent 44b2136 commit 67685db

File tree

2 files changed

+72
-28
lines changed

2 files changed

+72
-28
lines changed

source/module_hamilt_lcao/module_gint/gint.cpp

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, const Grid_Driver* gd, cons
171171
this->hRGint_tmp[is] = new hamilt::HContainer<double>(ucell_in.nat);
172172
}
173173
#ifdef __MPI
174+
if (this->DM2D_tmp != nullptr) {
175+
delete this->DM2D_tmp;
176+
}
177+
this->DM2D_tmp = new hamilt::HContainer<double>(ucell_in.nat);
174178
if (this->DMRGint_full != nullptr) {
175179
delete this->DMRGint_full;
176180
}
@@ -201,9 +205,14 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, const Grid_Driver* gd, cons
201205
this->hRGintCd->allocate(nullptr, true);
202206
ModuleBase::Memory::record("Gint::hRGintCd",
203207
this->hRGintCd->get_memory_size());
208+
this->DM2D_tmp->insert_ijrs(this->gridt->get_ijr_info(), ucell_in, npol);
209+
this->DM2D_tmp->allocate(nullptr, true);
210+
ModuleBase::Memory::record("Gint::DM2D_tmp",
211+
this->DM2D_tmp->get_memory_size());
204212
for(int is = 0; is < nspin; is++) {
205213
this->hRGint_tmp[is]->insert_ijrs(this->gridt->get_ijr_info(), ucell_in);
206214
this->DMRGint[is]->insert_ijrs(this->gridt->get_ijr_info(), ucell_in);
215+
207216
this->hRGint_tmp[is]->allocate(nullptr, true);
208217
this->DMRGint[is]->allocate(nullptr, true);
209218
}
@@ -218,6 +227,8 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, const Grid_Driver* gd, cons
218227
this->DMRGint_full->get_memory_size());
219228
#endif
220229
}
230+
// std::cout<<" DMRGint " << DMRGint[0]->get_atom_pair(0,1).get_row_size() << std::endl;
231+
// std::cout<<" DMRGint_full " << DMRGint[0]->get_atom_pair(0,1).get_row_size() << std::endl;
221232
}
222233

223234
void Gint::reset_DMRGint(const int& nspin)
@@ -262,38 +273,68 @@ void Gint::transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> DM2D) {
262273
}
263274
} else // NSPIN=4 case
264275
{
276+
277+
for (int is = 0; is < 4; is++) {
265278
#ifdef __MPI
266-
hamilt::transferParallels2Serials(*DM2D[0], this->DMRGint_full);
267-
#else
268-
this->DMRGint_full = DM2D[0];
269-
#endif
270-
std::vector<double*> tmp_pointer(4, nullptr);
271-
for (int iap = 0; iap < this->DMRGint_full->size_atom_pairs(); ++iap) {
272-
auto& ap = this->DMRGint_full->get_atom_pair(iap);
273-
int iat1 = ap.get_atom_i();
274-
int iat2 = ap.get_atom_j();
275-
for (int ir = 0; ir < ap.get_R_size(); ++ir) {
276-
const ModuleBase::Vector3<int> r_index = ap.get_R_index(ir);
277-
for (int is = 0; is < 4; is++) {
278-
tmp_pointer[is] = this->DMRGint[is]
279-
->find_matrix(iat1, iat2, r_index)
280-
->get_pointer();
281-
}
282-
double* data_full = ap.get_pointer(ir);
283-
for (int irow = 0; irow < ap.get_row_size(); irow += 2) {
284-
for (int icol = 0; icol < ap.get_col_size(); icol += 2) {
285-
*(tmp_pointer[0])++ = data_full[icol];
286-
*(tmp_pointer[1])++ = data_full[icol + 1];
279+
std::vector<double*> tmp_pointer(4, nullptr);
280+
for (int iap = 0; iap < DM2D[0]->size_atom_pairs(); ++iap) {
281+
auto& ap = DM2D[0]->get_atom_pair(iap);
282+
int iat1 = ap.get_atom_i();
283+
int iat2 = ap.get_atom_j();
284+
for (int ir = 0; ir < ap.get_R_size(); ++ir) {
285+
const ModuleBase::Vector3<int> r_index = ap.get_R_index(ir);
286+
for (int is = 0; is < 4; is++) {
287+
tmp_pointer[is] = this -> DM2D_tmp->find_matrix(iat1, iat2, r_index)->get_pointer();
287288
}
288-
data_full += ap.get_col_size();
289-
for (int icol = 0; icol < ap.get_col_size(); icol += 2) {
290-
*(tmp_pointer[2])++ = data_full[icol];
291-
*(tmp_pointer[3])++ = data_full[icol + 1];
289+
double* data_full = ap.get_pointer(ir);
290+
for (int irow = 0; irow < ap.get_row_size(); irow += 2) {
291+
for (int icol = 0; icol < ap.get_col_size(); icol += 2) {
292+
*(tmp_pointer[0])++ = data_full[icol];
293+
*(tmp_pointer[1])++ = data_full[icol + 1];
294+
}
295+
data_full += ap.get_col_size();
296+
for (int icol = 0; icol < ap.get_col_size(); icol += 2) {
297+
*(tmp_pointer[2])++ = data_full[icol];
298+
*(tmp_pointer[3])++ = data_full[icol + 1];
299+
}
300+
data_full += ap.get_col_size();
292301
}
293-
data_full += ap.get_col_size();
294302
}
295303
}
304+
hamilt::transferParallels2Serials( *(this->DM2D_tmp), this->DMRGint[is]);
305+
306+
307+
#else
308+
this->DMRGint[is] = DM2D[0];
309+
#endif
296310
}
297-
}
311+
// std::vector<double*> tmp_pointer(4, nullptr);
312+
// for (int iap = 0; iap < this->DMRGint_full->size_atom_pairs(); ++iap) {
313+
// auto& ap = this->DMRGint_full->get_atom_pair(iap);
314+
// int iat1 = ap.get_atom_i();
315+
// int iat2 = ap.get_atom_j();
316+
// for (int ir = 0; ir < ap.get_R_size(); ++ir) {
317+
// const ModuleBase::Vector3<int> r_index = ap.get_R_index(ir);
318+
// for (int is = 0; is < 4; is++) {
319+
// tmp_pointer[is] = this->DMRGint[is]
320+
// ->find_matrix(iat1, iat2, r_index)
321+
// ->get_pointer();
322+
// }
323+
// double* data_full = ap.get_pointer(ir);
324+
// for (int irow = 0; irow < ap.get_row_size(); irow += 2) {
325+
// for (int icol = 0; icol < ap.get_col_size(); icol += 2) {
326+
// *(tmp_pointer[0])++ = data_full[icol];
327+
// *(tmp_pointer[1])++ = data_full[icol + 1];
328+
// }
329+
// data_full += ap.get_col_size();
330+
// for (int icol = 0; icol < ap.get_col_size(); icol += 2) {
331+
// *(tmp_pointer[2])++ = data_full[icol];
332+
// *(tmp_pointer[3])++ = data_full[icol + 1];
333+
// }
334+
// data_full += ap.get_col_size();
335+
// }
336+
// }
337+
// }
338+
}
298339
ModuleBase::timer::tick("Gint", "transfer_DMR");
299340
}

source/module_hamilt_lcao/module_gint/gint.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,17 @@ class Gint {
261261
hamilt::HContainer<std::complex<double>>* hRGintCd = nullptr;
262262

263263
//! stores DMR in sparse format
264-
std::vector<hamilt::HContainer<double>*> DMRGint;
264+
std::vector<hamilt::HContainer<double>*> DMRGint;
265+
265266

266267
//! tmp tools used in transfer_DM2DtoGrid
267268
hamilt::HContainer<double>* DMRGint_full = nullptr;
269+
hamilt::HContainer<double>* DM2D_tmp = nullptr;
268270

269271
std::vector<hamilt::HContainer<double>> pvdpRx_reduced;
270272
std::vector<hamilt::HContainer<double>> pvdpRy_reduced;
271273
std::vector<hamilt::HContainer<double>> pvdpRz_reduced;
274+
272275
};
273276

274277
#endif

0 commit comments

Comments
 (0)