Skip to content

Commit cf7d9de

Browse files
committed
use for-loop with omp
1 parent 8fbdead commit cf7d9de

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

source/module_lr/potentials/xc_kernel.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,19 @@ void LR::KernelXC::f_xc_libxc(const int& nspin, const double& omega, const doubl
188188
break;
189189
}
190190
// add onto the total components
191-
std::transform(vrho_tmp.begin(), vrho_tmp.end(), this->vrho_.begin(), this->vrho_.begin(), std::plus<double>());
192-
std::transform(v2rho2_tmp.begin(), v2rho2_tmp.end(), this->v2rho2_.begin(), this->v2rho2_.begin(), std::plus<double>());
193-
std::transform(vsigma_tmp.begin(), vsigma_tmp.end(), this->vsigma_.begin(), this->vsigma_.begin(), std::plus<double>());
194-
std::transform(v2rhosigma_tmp.begin(), v2rhosigma_tmp.end(), this->v2rhosigma_.begin(), this->v2rhosigma_.begin(), std::plus<double>());
195-
std::transform(v2sigma2_tmp.begin(), v2sigma2_tmp.end(), this->v2sigma2_.begin(), this->v2sigma2_.begin(), std::plus<double>());
191+
auto omp_add_vector = [](const std::vector<double>& src, std::vector<double>& dst)
192+
{
193+
assert(src.size() == dst.size());
194+
#ifdef _OPENMP
195+
#pragma omp parallel for
196+
#endif
197+
for (size_t i = 0; i < src.size(); ++i) { dst[i] += src[i]; }
198+
};
199+
omp_add_vector(vrho_tmp, this->vrho_);
200+
omp_add_vector(v2rho2_tmp, this->v2rho2_);
201+
omp_add_vector(vsigma_tmp, this->vsigma_);
202+
omp_add_vector(v2rhosigma_tmp, this->v2rhosigma_);
203+
omp_add_vector(v2sigma2_tmp, this->v2sigma2_);
196204
} // end for( xc_func_type &func : funcs )
197205

198206
XC_Functional_Libxc::finish_func(funcs);
@@ -213,12 +221,17 @@ void LR::KernelXC::f_xc_libxc(const int& nspin, const double& omega, const doubl
213221
this->drho_gs_ = gradrho[0];
214222
// 1. $2f^{\rho\sigma}*\nabla\rho$
215223
this->v2rhosigma_2drho_.resize(nrxx);
216-
std::transform(gradrho[0].begin(), gradrho[0].end(), v2rs.begin(), this->v2rhosigma_2drho_.begin(),
217-
[](const V3& a, const V3& b) {return a * b * 2.; });
224+
#ifdef _OPENMP
225+
#pragma omp parallel for
226+
#endif
227+
for (size_t i = 0; i < nrxx; ++i) { this->v2rhosigma_2drho_[i] = gradrho[0][i] * v2rs[i] * 2.; }
228+
218229
// 2. $4f^{\sigma\sigma}*\nabla\rho$
219230
this->v2sigma2_4drho_.resize(nrxx);
220-
std::transform(sigma.begin(), sigma.end(), v2s2.begin(), v2sigma2_4drho_.begin(),
221-
[](const V3& a, const V3& b) {return a * b * 4.; });
231+
#ifdef _OPENMP
232+
#pragma omp parallel for
233+
#endif
234+
for (size_t i = 0; i < nrxx; ++i) { this->v2sigma2_4drho_[i] = gradrho[0][i] * v2s2[i] * 4.; }
222235
}
223236
else
224237
{

0 commit comments

Comments
 (0)