@@ -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