Skip to content

Commit 7316e09

Browse files
committed
openmp for cal_force_stress in dspin
1 parent 59a8303 commit 7316e09

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/dspin_force_stress.hpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ void DeltaSpin<OperatorLCAO<TK, TR>>::cal_force_stress(const bool cal_force,
3232
}
3333
// 1. calculate <psi|beta> for each pair of atoms
3434
// loop over all on-site atoms
35-
int atom_index = 0;
35+
#pragma omp parallel
36+
{
37+
std::vector<double> stress_local(6, 0);
38+
#pragma omp for schedule(dynamic)
3639
for (int iat0 = 0; iat0 < this->ucell->nat; iat0++)
3740
{
3841
if(!this->constraint_atom_list[iat0])
@@ -183,12 +186,20 @@ void DeltaSpin<OperatorLCAO<TK, TR>>::cal_force_stress(const bool cal_force,
183186
this->nspin,
184187
dis1,
185188
dis2,
186-
stress_tmp.data());
189+
stress_local.data());
187190
}
188191
}
189192
}
190193
}
191194
}
195+
#pragma omp critical
196+
{
197+
for(int i = 0; i < 6; i++)
198+
{
199+
stress_tmp[i] += stress_local[i];
200+
}
201+
}
202+
}
192203

193204
if (cal_force)
194205
{
@@ -281,9 +292,14 @@ void DeltaSpin<OperatorLCAO<TK, TR>>::cal_force_IJR(const int& iat1,
281292
tmp[2] = lambda_tmp * nlm1[index + length * 3] * nlm2[index] * dm_pointer[step_trace[is]];
282293
// force1 = - VU * <d phi_{I,R1}/d R1|chi_m> * <chi_m'|phi_{J,R2}>
283294
// force2 = - VU * <phi_{I,R1}|d chi_m/d R0> * <chi_m'|phi_{J,R2>}
295+
#pragma omp atomic
284296
force1[0] += tmp[0];
297+
#pragma omp atomic
285298
force1[1] += tmp[1];
299+
#pragma omp atomic
286300
force1[2] += tmp[2];
301+
// different threads have different addresses for force2,
302+
// so there is no need to add atomic here.
287303
force2[0] -= tmp[0];
288304
force2[1] -= tmp[1];
289305
force2[2] -= tmp[2];

0 commit comments

Comments
 (0)