Skip to content

Commit 0af862e

Browse files
committed
Merge branch 'LTS' of https://github.com/deepmodeling/abacus-develop into LTS
2 parents e8afb27 + 0f13efe commit 0af862e

File tree

2 files changed

+25
-34
lines changed

2 files changed

+25
-34
lines changed

source/module_hamilt_lcao/module_gint/gint.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, const Grid_Driver* gd, cons
194194
this->DMRGint[0]->get_memory_size()
195195
* this->DMRGint.size());
196196
} else {
197-
// this->hRGintCd->insert_ijrs(this->gridt->get_ijr_info(), ucell_in, npol);
198-
// this->hRGintCd->allocate(nullptr, true);
199-
// ModuleBase::Memory::record("Gint::hRGintCd",
200-
// this->hRGintCd->get_memory_size());
201197
for(int is = 0; is < nspin; is++) {
202198
this->hRGint_tmp[is]->insert_ijrs(this->gridt->get_ijr_info(), ucell_in);
203199
this->DMRGint[is]->insert_ijrs(this->gridt->get_ijr_info(), ucell_in);
@@ -255,45 +251,42 @@ void Gint::transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> DM2D) {
255251
// is=0:↑↑, 1:↑↓, 2:↓↑, 3:↓↓
256252
const int row_set[4] = {0, 0, 1, 1};
257253
const int col_set[4] = {0, 1, 0, 1};
258-
259254
int mg = DM2D[0]->get_paraV()->get_global_row_size()/2;
260255
int ng = DM2D[0]->get_paraV()->get_global_col_size()/2;
261256
int nb = DM2D[0]->get_paraV()->get_block_size()/2;
262257
int blacs_ctxt = DM2D[0]->get_paraV()->blacs_ctxt;
263-
int *iat2iwt = new int[ucell->nat];
258+
259+
std::vector<int> iat2iwt(ucell->nat);
264260
for (int iat = 0; iat < ucell->nat; iat++) {
265261
iat2iwt[iat] = ucell->get_iat2iwt()[iat]/2;
266262
}
267263
Parallel_Orbitals *pv = new Parallel_Orbitals();
268264
pv->set(mg, ng, nb, blacs_ctxt);
269-
pv->set_atomic_trace(iat2iwt, ucell->nat, mg);
265+
pv->set_atomic_trace(iat2iwt.data(), ucell->nat, mg);
270266
auto ijr_info = DM2D[0]->get_ijr_info();
271267
this-> DM2D_tmp = new hamilt::HContainer<double>(pv, nullptr, &ijr_info);
268+
this-> DM2D_tmp->set_zero();
272269
ModuleBase::Memory::record("Gint::DM2D_tmp", this->DM2D_tmp->get_memory_size());
273270
for (int is = 0; is < 4; is++){
274-
this->DM2D_tmp->set_zero();
275271
for (int iap = 0; iap < DM2D[0]->size_atom_pairs(); ++iap) {
276272
auto& ap = DM2D[0]->get_atom_pair(iap);
277273
int iat1 = ap.get_atom_i();
278274
int iat2 = ap.get_atom_j();
279275
for (int ir = 0; ir < ap.get_R_size(); ++ir) {
280276
const ModuleBase::Vector3<int> r_index = ap.get_R_index(ir);
281-
double* matrix_out = this -> DM2D_tmp -> find_matrix(iat1, iat2, r_index)->get_pointer();
277+
double* matrix_out = DM2D_tmp -> find_matrix(iat1, iat2, r_index)->get_pointer();
282278
double* matrix_in = ap.get_pointer(ir);
283279
for (int irow = 0; irow < ap.get_row_size()/2; irow ++) {
284-
for (int icol = 0; icol < ap.get_col_size()/2; icol++){
280+
for (int icol = 0; icol < ap.get_col_size()/2; icol ++) {
285281
int index_i = irow* ap.get_col_size()/2 + icol;
286282
int index_j = (irow*2+row_set[is]) * ap.get_col_size() + icol*2+col_set[is];
287-
matrix_out[index_i] = matrix_in[index_j];
283+
matrix_out[index_i] = matrix_in[index_j];
288284
}
289285
}
290286
}
291287
}
292288
hamilt::transferParallels2Serials( *(this->DM2D_tmp), this->DMRGint[is]);
293289
}
294-
// delete iat2iwt;
295-
// delete pv;
296-
// delete this-> DM2D_tmp;
297290
#else
298291
//this->DMRGint_full = DM2D[0];
299292
#endif

source/module_hamilt_lcao/module_gint/gint_k_pvpr.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,36 +81,38 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
8181
int mg = hR->get_paraV()->get_global_row_size()/2;
8282
int ng = hR->get_paraV()->get_global_col_size()/2;
8383
int nb = hR->get_paraV()->get_block_size()/2;
84-
hR->set_zero();
8584
#ifdef __MPI
8685
int blacs_ctxt = hR->get_paraV()->blacs_ctxt;
87-
int *iat2iwt = new int[ucell_in->nat];
86+
std::vector<int> iat2iwt(ucell_in->nat);
8887
for (int iat = 0; iat < ucell_in->nat; iat++) {
8988
iat2iwt[iat] = ucell_in->get_iat2iwt()[iat]/2;
9089
}
9190
Parallel_Orbitals *pv = new Parallel_Orbitals();
9291
pv->set(mg, ng, nb, blacs_ctxt);
93-
pv->set_atomic_trace(iat2iwt, ucell_in->nat, mg);
92+
pv->set_atomic_trace(iat2iwt.data(), ucell_in->nat, mg);
9493
auto ijr_info = hR->get_ijr_info();
9594

9695
this->hR_tmp = new hamilt::HContainer<std::complex<double>>(pv, nullptr, &ijr_info);
9796
ModuleBase::Memory::record("Gint::hRGintCd", this->hR_tmp->get_memory_size());
9897

99-
//0,3;1,2;1,2;0,3
98+
//select hRGint_tmp
10099
std::vector<int> first = {0, 1, 1, 0};
101100
std::vector<int> second= {3, 2, 2, 3};
101+
//select position in the big matrix
102102
std::vector<int> row_set = {0, 0, 1, 1};
103103
std::vector<int> col_set = {0, 1, 0, 1};
104+
//construct complex matrix
104105
std::vector<int> clx_i = {1, 0, 0, -1};
105106
std::vector<int> clx_j = {0, 1, -1, 0};
106107
for (int is = 0; is < 4; is++){
108+
if(!PARAM.globalv.domag && (is==1 || is==2)) continue;
109+
this->hR_tmp->set_zero();
107110
hamilt::HContainer<std::complex<double>>* hRGint_tmpCd = new hamilt::HContainer<std::complex<double>>(this->ucell->nat);
108111
hRGint_tmpCd->insert_ijrs(this->gridt->get_ijr_info(), *(this->ucell));
109112
hRGint_tmpCd->allocate(nullptr, true);
110113
hRGint_tmpCd->set_zero();
111114
for (int iap = 0; iap < hRGint_tmpCd->size_atom_pairs(); iap++)
112115
{
113-
//std::cout<<"iap: "<<iap<<std::endl;
114116
auto* ap = &hRGint_tmpCd->get_atom_pair(iap);
115117
const int iat1 = ap->get_atom_i();
116118
const int iat2 = ap->get_atom_j();
@@ -122,7 +124,6 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
122124
const hamilt::AtomPair<double>* ap_nspin2 = this->hRGint_tmp[second[is]] ->find_pair(iat1, iat2);
123125
for (int ir = 0; ir < upper_ap->get_R_size(); ir++)
124126
{
125-
//std::cout<<"ir"<<ir<<std::endl;
126127
const auto R_index = upper_ap->get_R_index(ir);
127128
auto upper_mat = upper_ap->find_matrix(R_index);
128129
auto mat_nspin1 = ap_nspin1->find_matrix(R_index);
@@ -137,29 +138,28 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
137138
}
138139
}
139140
//fill the lower triangle matrix
140-
if (PARAM.globalv.domag){
141-
if (iat1 < iat2)
141+
//When is=0 or 3, the real part does not need conjugation;
142+
//when is=1 or 2, the small matrix is not Hermitian, so conjugation is not needed
143+
if (iat1 < iat2)
144+
{
145+
auto lower_mat = lower_ap->find_matrix(-R_index);
146+
for (int irow = 0; irow < upper_mat->get_row_size(); ++irow)
142147
{
143-
auto lower_mat = lower_ap->find_matrix(-R_index);
144-
for (int irow = 0; irow < upper_mat->get_row_size(); ++irow)
148+
for (int icol = 0; icol < upper_mat->get_col_size(); ++icol)
145149
{
146-
for (int icol = 0; icol < upper_mat->get_col_size(); ++icol)
147-
{
148-
lower_mat->get_value(icol, irow) = conj(upper_mat->get_value(irow, icol));
149-
}
150+
lower_mat->get_value(icol, irow) = upper_mat->get_value(irow, icol);
150151
}
151152
}
152153
}
154+
153155
}
154156
}
155157
}
156-
157-
//std::cout<<"success"<<std::endl;
158-
this->hR_tmp->set_zero();
158+
// transfer hRGint_tmpCd to parallel hR_tmp
159159
hamilt::transferSerials2Parallels( *hRGint_tmpCd, this->hR_tmp);
160+
// merge hR_tmp to hR
160161
for (int iap = 0; iap < hR->size_atom_pairs(); iap++)
161162
{
162-
//std::cout<<"iap: "<<iap<<std::endl;
163163
auto* ap = &hR->get_atom_pair(iap);
164164
const int iat1 = ap->get_atom_i();
165165
const int iat2 = ap->get_atom_j();
@@ -169,7 +169,6 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
169169
const auto R_index = ap->get_R_index(ir);
170170
auto upper_mat = ap->find_matrix(R_index);
171171
auto mat_nspin = ap_nspin->find_matrix(R_index);
172-
173172
// The row size and the col size of upper_matrix is double that of matrix_nspin_0
174173
for (int irow = 0; irow < mat_nspin->get_row_size(); ++irow)
175174
{
@@ -187,7 +186,6 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
187186
#else
188187

189188
#endif
190-
191189
ModuleBase::timer::tick("Gint_k", "transfer_pvpR");
192190
return;
193191
}

0 commit comments

Comments
 (0)