@@ -78,86 +78,176 @@ void Gint_k::transfer_pvpR(hamilt::HContainer<std::complex<double>>* hR,
78
78
ModuleBase::TITLE (" Gint_k" , " transfer_pvpR" );
79
79
ModuleBase::timer::tick (" Gint_k" , " transfer_pvpR" );
80
80
81
- this ->hRGintCd ->set_zero ();
81
+ // this->hRGintCd->set_zero();
82
82
83
- for (int iap = 0 ; iap < this ->hRGintCd ->size_atom_pairs (); iap++)
84
- {
85
- auto * ap = &this ->hRGintCd ->get_atom_pair (iap);
86
- const int iat1 = ap->get_atom_i ();
87
- const int iat2 = ap->get_atom_j ();
88
- if (iat1 <= iat2)
89
- {
90
- hamilt::AtomPair<std::complex<double >>* upper_ap = ap;
91
- hamilt::AtomPair<std::complex<double >>* lower_ap = this ->hRGintCd ->find_pair (iat2, iat1);
92
- const hamilt::AtomPair<double >* ap_nspin_0 = this ->hRGint_tmp [0 ]->find_pair (iat1, iat2);
93
- const hamilt::AtomPair<double >* ap_nspin_3 = this ->hRGint_tmp [3 ]->find_pair (iat1, iat2);
94
- for (int ir = 0 ; ir < upper_ap->get_R_size (); ir++)
95
- {
96
- const auto R_index = upper_ap->get_R_index (ir);
97
- auto upper_mat = upper_ap->find_matrix (R_index);
98
- auto mat_nspin_0 = ap_nspin_0->find_matrix (R_index);
99
- auto mat_nspin_3 = ap_nspin_3->find_matrix (R_index);
83
+ #ifdef __MPI
84
+ int mg = hR->get_paraV ()->get_global_row_size ()/2 ;
85
+ int ng = hR->get_paraV ()->get_global_col_size ()/2 ;
86
+ int nb = hR->get_paraV ()->get_block_size ()/2 ;
87
+ int blacs_ctxt = hR->get_paraV ()->blacs_ctxt ;
88
+ int *iat2iwt = new int [ucell_in->nat ];
89
+ for (int iat = 0 ; iat < ucell_in->nat ; iat++) {
90
+ iat2iwt[iat] = ucell_in->get_iat2iwt ()[iat]/2 ;
91
+ }
92
+ Parallel_Orbitals *pv = new Parallel_Orbitals ();
93
+ pv->set (mg, ng, nb, blacs_ctxt);
94
+ pv->set_atomic_trace (iat2iwt, ucell_in->nat , mg);
95
+ auto ijr_info = hR->get_ijr_info ();
96
+
97
+
98
+ hamilt::HContainer<double >* hR_tmp = new hamilt::HContainer<double >(pv, nullptr , &ijr_info);
99
+ ModuleBase::Memory::record (" Gint::hRGintCd" , hR_tmp->get_memory_size ());
100
+ // std::cout<<"test1"<<std::endl;
101
+
102
+ // std::cout<<hRGint_tmp[0]->size_atom_pairs()<<std::endl;
103
+ // std::cout<<hR_tmp->size_atom_pairs()<<std::endl;
104
+ // for(int i =0; i < hRGint_tmp[0]->size_atom_pairs(); i++){
105
+ // std::cout<<"hRGint_tmp"<<hRGint_tmp[0]->get_atom_pair(i).get_row_size()<<' '<<hRGint_tmp[0]->get_atom_pair(i).get_row_size()<<std::endl;
106
+ // std::cout<<"hR_tmp"<<hR_tmp->get_atom_pair(i).get_row_size()<<' '<<hR_tmp->get_atom_pair(i).get_row_size()<<std::endl;
107
+ // std::cout<<"pv1:" << pv->get_indexes_col(0).size()<< ' '<<pv->get_indexes_row(0).size()<<std::endl;
108
+ // std::cout<<"pv2:" << pv->get_indexes_col().size()<< ' '<<pv->get_indexes_row().size()<<std::endl;
109
+ // }
110
+
100
111
101
- // The row size and the col size of upper_matrix is double that of matrix_nspin_0
102
- for (int irow = 0 ; irow < mat_nspin_0->get_row_size (); ++irow)
112
+
113
+ for (int is = 0 ; is < 4 ; is++){
114
+ hR_tmp->set_zero ();
115
+ // std::cout<<"is: "<<is<<std::endl;
116
+ hamilt::transferSerials2Parallels ( *(this ->hRGint_tmp [is]), hR_tmp);
117
+ for (int iap = 0 ; iap < hR->size_atom_pairs (); iap++)
118
+ {
119
+ // std::cout<<"iap: "<<iap<<std::endl;
120
+ auto * ap = &hR->get_atom_pair (iap);
121
+ const int iat1 = ap->get_atom_i ();
122
+ const int iat2 = ap->get_atom_j ();
123
+ const hamilt::AtomPair<double >* ap_nspin = nullptr ;
124
+ if (iat1 <= iat2)
125
+ {
126
+ hamilt::AtomPair<std::complex<double >>* upper_ap = ap;
127
+ hamilt::AtomPair<std::complex<double >>* lower_ap = hR->find_pair (iat2, iat1);
128
+ switch (is)
103
129
{
104
- for (int icol = 0 ; icol < mat_nspin_0->get_col_size (); ++icol)
105
- {
106
- upper_mat->get_value (2 *irow, 2 *icol) = mat_nspin_0->get_value (irow, icol) + mat_nspin_3->get_value (irow, icol);
107
- upper_mat->get_value (2 *irow+1 , 2 *icol+1 ) = mat_nspin_0->get_value (irow, icol) - mat_nspin_3->get_value (irow, icol);
108
- }
130
+ case 0 :
131
+ ap_nspin = hR_tmp->find_pair (iat1, iat2);
132
+ break ;
133
+ case 3 :
134
+ ap_nspin = hR_tmp->find_pair (iat1, iat2);
135
+ break ;
109
136
}
137
+ if (ap_nspin == nullptr ) break ;
138
+ // const hamilt::AtomPair<double>* ap_nspin_0 = this->hR_tmp[0]->find_pair(iat1, iat2);
139
+ // const hamilt::AtomPair<double>* ap_nspin_3 = this->hRGint_tmp[3]->find_pair(iat1, iat2);
140
+ for (int ir = 0 ; ir < upper_ap->get_R_size (); ir++)
141
+ {
142
+ const auto R_index = upper_ap->get_R_index (ir);
143
+ auto upper_mat = upper_ap->find_matrix (R_index);
144
+ // auto mat_nspin_0 = ap_nspin_0->find_matrix(R_index);
145
+ // auto mat_nspin_3 = ap_nspin_3->find_matrix(R_index);
146
+ auto mat_nspin = ap_nspin->find_matrix (R_index);
110
147
111
- if (PARAM.globalv .domag )
112
- {
113
- const hamilt::AtomPair<double >* ap_nspin_1 = this ->hRGint_tmp [1 ]->find_pair (iat1, iat2);
114
- const hamilt::AtomPair<double >* ap_nspin_2 = this ->hRGint_tmp [2 ]->find_pair (iat1, iat2);
115
- const auto mat_nspin_1 = ap_nspin_1->find_matrix (R_index);
116
- const auto mat_nspin_2 = ap_nspin_2->find_matrix (R_index);
117
- for (int irow = 0 ; irow < mat_nspin_1->get_row_size (); ++irow)
148
+ // The row size and the col size of upper_matrix is double that of matrix_nspin_0
149
+ for (int irow = 0 ; irow < mat_nspin->get_row_size (); ++irow)
118
150
{
119
- for (int icol = 0 ; icol < mat_nspin_1 ->get_col_size (); ++icol)
151
+ for (int icol = 0 ; icol < mat_nspin ->get_col_size (); ++icol)
120
152
{
121
- upper_mat->get_value (2 *irow, 2 *icol+1 ) = mat_nspin_1->get_value (irow, icol) + std::complex<double >(0.0 , 1.0 ) * mat_nspin_2->get_value (irow, icol);
122
- upper_mat->get_value (2 *irow+1 , 2 *icol) = mat_nspin_1->get_value (irow, icol) - std::complex<double >(0.0 , 1.0 ) * mat_nspin_2->get_value (irow, icol);
153
+ // upper_mat->get_value(2*irow, 2*icol) = mat_nspin_0->get_value(irow, icol) + mat_nspin_3->get_value(irow, icol);
154
+ // upper_mat->get_value(2*irow+1, 2*icol+1) = mat_nspin_0->get_value(irow, icol) - mat_nspin_3->get_value(irow, icol);
155
+ switch (is)
156
+ {
157
+ case 0 :
158
+ upper_mat->get_value (2 *irow, 2 *icol) = mat_nspin->get_value (irow, icol);
159
+ upper_mat->get_value (2 *irow+1 , 2 *icol+1 ) = mat_nspin->get_value (irow, icol);
160
+ break ;
161
+ case 3 :
162
+ upper_mat->get_value (2 *irow, 2 *icol) += mat_nspin->get_value (irow, icol);
163
+ upper_mat->get_value (2 *irow+1 , 2 *icol+1 ) -= mat_nspin->get_value (irow, icol);
164
+ break ;
165
+ }
123
166
}
124
167
}
125
- }
126
168
127
- // fill the lower triangle matrix
128
- if (iat1 < iat2)
129
- {
130
- auto lower_mat = lower_ap->find_matrix (-R_index);
131
- for (int irow = 0 ; irow < upper_mat->get_row_size (); ++irow)
169
+ if (PARAM.globalv .domag )
132
170
{
133
- for (int icol = 0 ; icol < upper_mat->get_col_size (); ++icol)
171
+ const hamilt::AtomPair<double >* ap_nspin = nullptr ;
172
+ switch (is)
173
+ {
174
+ case 1 :
175
+ ap_nspin = hR_tmp->find_pair (iat1, iat2);
176
+ break ;
177
+ case 2 :
178
+ ap_nspin = hR_tmp->find_pair (iat1, iat2);
179
+ break ;
180
+ }
181
+ // const hamilt::AtomPair<double>* ap_nspin_1 = this->hRGint_tmp[1]->find_pair(iat1, iat2);
182
+ // const hamilt::AtomPair<double>* ap_nspin_2 = this->hRGint_tmp[2]->find_pair(iat1, iat2);
183
+ // const auto mat_nspin_1 = ap_nspin_1->find_matrix(R_index);
184
+ // const auto mat_nspin_2 = ap_nspin_2->find_matrix(R_index);
185
+ const auto mat_nspin = ap_nspin->find_matrix (R_index);
186
+ for (int irow = 0 ; irow < mat_nspin->get_row_size (); ++irow)
134
187
{
135
- lower_mat->get_value (icol, irow) = conj (upper_mat->get_value (irow, icol));
188
+ for (int icol = 0 ; icol < mat_nspin->get_col_size (); ++icol)
189
+ {
190
+ switch (is)
191
+ {
192
+ case 1 :
193
+ upper_mat->get_value (2 *irow, 2 *icol+1 ) = mat_nspin->get_value (irow, icol);
194
+ upper_mat->get_value (2 *irow+1 , 2 *icol) = mat_nspin->get_value (irow, icol);
195
+ break ;
196
+ case 2 :
197
+ upper_mat->get_value (2 *irow, 2 *icol+1 ) += std::complex<double >(0.0 , 1.0 ) * mat_nspin->get_value (irow, icol);
198
+ upper_mat->get_value (2 *irow+1 , 2 *icol) -= std::complex<double >(0.0 , 1.0 ) * mat_nspin->get_value (irow, icol);
199
+ break ;
200
+ }
201
+ // upper_mat->get_value(2*irow, 2*icol+1) = mat_nspin->get_value(irow, icol) + std::complex<double>(0.0, 1.0) * mat_nspin_2->get_value(irow, icol);
202
+ // upper_mat->get_value(2*irow+1, 2*icol) = mat_nspin->get_value(irow, icol) - std::complex<double>(0.0, 1.0) * mat_nspin_2->get_value(irow, icol);
203
+ }
136
204
}
137
205
}
206
+
207
+ // fill the lower triangle matrix
208
+ if (is == 3 ){
209
+ if (iat1 < iat2)
210
+ {
211
+ auto lower_mat = lower_ap->find_matrix (-R_index);
212
+ for (int irow = 0 ; irow < upper_mat->get_row_size (); ++irow)
213
+ {
214
+ for (int icol = 0 ; icol < upper_mat->get_col_size (); ++icol)
215
+ {
216
+ lower_mat->get_value (icol, irow) = conj (upper_mat->get_value (irow, icol));
217
+ }
218
+ }
219
+ }
220
+ }
221
+ // std::cout<<"end"<<std::endl;
138
222
}
139
223
}
140
224
}
225
+
141
226
}
227
+ delete[] iat2iwt;
228
+ delete pv;
229
+ delete hR_tmp;
230
+ #else
231
+
232
+ #endif
142
233
143
234
// ===================================
144
235
// transfer HR from Gint to Veff<OperatorLCAO<std::complex<double>, std::complex<double>>>
145
236
// ===================================
146
- #ifdef __MPI
147
- int size;
148
- MPI_Comm_size (MPI_COMM_WORLD, &size);
149
- if (size == 1 )
150
- {
151
- hR->add (*this ->hRGintCd );
152
- }
153
- else
154
- {
155
- hamilt::transferSerials2Parallels<std::complex<double >>(*this ->hRGintCd , hR);
156
- }
157
- #else
158
- hR->add (*this ->hRGintCd );
159
- #endif
160
-
237
+ // #ifdef __MPI
238
+ // int size;
239
+ // MPI_Comm_size(MPI_COMM_WORLD, &size);
240
+ // if (size == 1)
241
+ // {
242
+ // hR->add(*this->hRGintCd);
243
+ // }
244
+ // else
245
+ // {
246
+ // hamilt::transferSerials2Parallels<std::complex<double>>(*this->hRGintCd, hR);
247
+ // }
248
+ // #else
249
+ // hR->add(*this->hRGintCd);
250
+ // #endif
161
251
ModuleBase::timer::tick (" Gint_k" , " transfer_pvpR" );
162
252
return ;
163
253
}
0 commit comments