Skip to content

Commit 1a154f6

Browse files
committed
Remove unnecessary comments, optimize calculation code
1 parent 61360c7 commit 1a154f6

File tree

2 files changed

+21
-36
lines changed

2 files changed

+21
-36
lines changed

source/module_hamilt_lcao/module_gint/gint.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ void Gint::transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> DM2D) {
259259
int ng = DM2D[0]->get_paraV()->get_global_col_size()/2;
260260
int nb = DM2D[0]->get_paraV()->get_block_size()/2;
261261
int blacs_ctxt = DM2D[0]->get_paraV()->blacs_ctxt;
262-
int *iat2iwt = new int[ucell->nat];
262+
std::vector<int> iat2iwt(ucell->nat);
263263
for (int iat = 0; iat < ucell->nat; iat++) {
264264
iat2iwt[iat] = ucell->get_iat2iwt()[iat]/2;
265265
}
@@ -290,9 +290,8 @@ void Gint::transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> DM2D) {
290290
}
291291
hamilt::transferParallels2Serials( *(this->DM2D_tmp), this->DMRGint[is]);
292292
}
293-
// delete iat2iwt [];
294-
// delete pv;
295-
// delete this-> DM2D_tmp;
293+
delete pv;
294+
delete this-> DM2D_tmp;
296295
#else
297296
//this->DMRGint_full = DM2D[0];
298297
#endif

source/module_hamilt_lcao/module_gint/gint_k_pvpr.cpp

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,25 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
8383
int nb = hR->get_paraV()->get_block_size()/2;
8484
#ifdef __MPI
8585
int blacs_ctxt = hR->get_paraV()->blacs_ctxt;
86-
int *iat2iwt = new int[ucell_in->nat];
86+
std::vector<int> iat2iwt(ucell_in->nat);
8787
for (int iat = 0; iat < ucell_in->nat; iat++) {
8888
iat2iwt[iat] = ucell_in->get_iat2iwt()[iat]/2;
8989
}
9090
Parallel_Orbitals *pv = new Parallel_Orbitals();
9191
pv->set(mg, ng, nb, blacs_ctxt);
92-
pv->set_atomic_trace(iat2iwt, ucell_in->nat, mg);
92+
pv->set_atomic_trace(iat2iwt.data(), ucell_in->nat, mg);
9393
auto ijr_info = hR->get_ijr_info();
9494

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

98-
//0,3;1,2;1,2;0,3
98+
//select hRGint_tmp
9999
std::vector<int> first = {0, 1, 1, 0};
100100
std::vector<int> second= {3, 2, 2, 3};
101+
//select position in the big matrix
101102
std::vector<int> row_set = {0, 0, 1, 1};
102103
std::vector<int> col_set = {0, 1, 0, 1};
104+
//construct complex matrix
103105
std::vector<int> clx_i = {1, 0, 0, -1};
104106
std::vector<int> clx_j = {0, 1, -1, 0};
105107
for (int is = 0; is < 4; is++){
@@ -111,7 +113,6 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
111113
hRGint_tmpCd->set_zero();
112114
for (int iap = 0; iap < hRGint_tmpCd->size_atom_pairs(); iap++)
113115
{
114-
//std::cout<<"iap: "<<iap<<std::endl;
115116
auto* ap = &hRGint_tmpCd->get_atom_pair(iap);
116117
const int iat1 = ap->get_atom_i();
117118
const int iat2 = ap->get_atom_j();
@@ -123,7 +124,6 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
123124
const hamilt::AtomPair<double>* ap_nspin2 = this->hRGint_tmp[second[is]] ->find_pair(iat1, iat2);
124125
for (int ir = 0; ir < upper_ap->get_R_size(); ir++)
125126
{
126-
//std::cout<<"ir"<<ir<<std::endl;
127127
const auto R_index = upper_ap->get_R_index(ir);
128128
auto upper_mat = upper_ap->find_matrix(R_index);
129129
auto mat_nspin1 = ap_nspin1->find_matrix(R_index);
@@ -138,42 +138,28 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
138138
}
139139
}
140140
//fill the lower triangle matrix
141-
if (is == 3 || is == 0){
142-
if (iat1 < iat2)
143-
{
144-
auto lower_mat = lower_ap->find_matrix(-R_index);
145-
for (int irow = 0; irow < upper_mat->get_row_size(); ++irow)
146-
{
147-
for (int icol = 0; icol < upper_mat->get_col_size(); ++icol)
148-
{
149-
lower_mat->get_value(icol, irow) = conj(upper_mat->get_value(irow, icol));
150-
}
151-
}
152-
}
153-
}
154-
if (is == 1 || is == 2){
155-
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)
156147
{
157-
auto lower_mat = lower_ap->find_matrix(-R_index);
158-
for (int irow = 0; irow < upper_mat->get_row_size(); ++irow)
148+
for (int icol = 0; icol < upper_mat->get_col_size(); ++icol)
159149
{
160-
for (int icol = 0; icol < upper_mat->get_col_size(); ++icol)
161-
{
162-
lower_mat->get_value(icol, irow) = upper_mat->get_value(irow, icol);
163-
}
150+
lower_mat->get_value(icol, irow) = upper_mat->get_value(irow, icol);
164151
}
165152
}
166153
}
154+
167155
}
168156
}
169157
}
170-
171-
//std::cout<<"success"<<std::endl;
172-
158+
// transfer hRGint_tmpCd to parallel hR_tmp
173159
hamilt::transferSerials2Parallels( *hRGint_tmpCd, this->hR_tmp);
160+
// merge hR_tmp to hR
174161
for (int iap = 0; iap < hR->size_atom_pairs(); iap++)
175162
{
176-
//std::cout<<"iap: "<<iap<<std::endl;
177163
auto* ap = &hR->get_atom_pair(iap);
178164
const int iat1 = ap->get_atom_i();
179165
const int iat2 = ap->get_atom_j();
@@ -183,7 +169,6 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
183169
const auto R_index = ap->get_R_index(ir);
184170
auto upper_mat = ap->find_matrix(R_index);
185171
auto mat_nspin = ap_nspin->find_matrix(R_index);
186-
187172
// The row size and the col size of upper_matrix is double that of matrix_nspin_0
188173
for (int irow = 0; irow < mat_nspin->get_row_size(); ++irow)
189174
{
@@ -197,7 +182,8 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
197182
}
198183
delete hRGint_tmpCd;
199184
}
200-
delete[] iat2iwt;
185+
delete pv;
186+
delete this->hR_tmp;
201187
#else
202188

203189
#endif

0 commit comments

Comments
 (0)