@@ -180,26 +180,23 @@ void Forces<FPTYPE, Device>::cal_force_cc(ModuleBase::matrix& forcecc,
180180 syncmem_var_h2d_op ()(rhocgigg_vec_d, rhocgigg_vec.data (), rho_basis->npw );
181181 }
182182
183- double force[3 ] = {0 , 0 , 0 };
184-
185183 if (this ->device == base_device::GpuDevice ) {
186184 hamilt::cal_force_npw_op<FPTYPE, Device>()(
187185 psiv_d, gv_d, rhocgigg_vec_d, force_it_d, tau_it_d,
188186 rho_basis->npw , ucell_in.omega , ucell_in.tpiba , ucell_in.atoms [it].na
189187 );
190- tau_it_d += 3 * ucell_in.atoms [it].na ; // update the start address of each atom type's tau
191- force_it_d += 3 * ucell_in.atoms [it].na ;
192188 } else {
193189 #pragma omp for
194190 for (int ia = 0 ; ia < ucell_in.atoms [it].na ; ia++)
195191 {
196192 double fx = 0.0 , fy = 0.0 , fz = 0.0 ;
193+ int iat = ucell_in.itia2iat (it, ia);
197194 for (int ig = 0 ; ig < rho_basis->npw ; ig++)
198195 {
199196 const std::complex <double > psiv_conj = conj (psiv[ig]);
200197
201- const double arg = ModuleBase::TWO_PI * (gv_h[ig * 3 ] * tau_h[ia * 3 ]
202- + gv_h[ig * 3 + 1 ] * tau_h[ia * 3 + 1 ] + gv_h[ig * 3 + 2 ] * tau_h[ia * 3 + 2 ]);
198+ const double arg = ModuleBase::TWO_PI * (gv_h[ig * 3 ] * tau_h[iat * 3 ]
199+ + gv_h[ig * 3 + 1 ] * tau_h[iat * 3 + 1 ] + gv_h[ig * 3 + 2 ] * tau_h[iat * 3 + 2 ]);
203200 double sinp, cosp;
204201 ModuleBase::libm::sincos (arg, &sinp, &cosp);
205202 const std::complex <double > expiarg = std::complex <double >(sinp, cosp);
@@ -215,20 +212,18 @@ void Forces<FPTYPE, Device>::cal_force_cc(ModuleBase::matrix& forcecc,
215212 const std::complex <double > ipol2 = tmp_var * gv_h[ig * 3 + 2 ];
216213 fz += ipol2.real ();
217214 }
218- int iat = ucell_in.itia2iat (it, ia);
219215 forcecc (iat, 0 ) += fx;
220216 forcecc (iat, 1 ) += fy;
221217 forcecc (iat, 2 ) += fz;
222218 }
223219 }
224220 }
225- if (this ->device == base_device::GpuDevice)
226- {
227- syncmem_var_d2h_op ()(forcecc.c , force_d, 3 * nat);
228- }
221+ tau_it_d += 3 * ucell_in.atoms [it].na ; // update the start address of each atom type's tau
222+ force_it_d += 3 * ucell_in.atoms [it].na ;
229223 }
230- if (this ->device == base_device::GpuDevice)
224+ if (this ->device == base_device::GpuDevice)
231225 {
226+ syncmem_var_d2h_op ()(forcecc.c , force_d, 3 * nat);
232227 delmem_var_op ()(gv_d);
233228 delmem_var_op ()(tau_d);
234229 delmem_var_op ()(force_d);
0 commit comments