@@ -285,6 +285,7 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::calculate_HR()
285285 const int npol = this ->ucell ->get_npol ();
286286
287287 // 1. calculate <phi|alpha> for each pair of atoms
288+ #pragma omp parallel for schedule(dynamic)
288289 for (int iat0 = 0 ; iat0 < this ->ucell ->nat ; iat0++)
289290 {
290291 auto tau0 = ucell->get_tau (iat0);
@@ -342,14 +343,13 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::calculate_HR()
342343 // --------------------------------------------------
343344
344345 // if nlm_tot is not calculated already, calculate it on the fly now
345- int iat00 = iat0;
346- if (nlm_tot.size () != this ->ucell ->nat )
346+ std::vector<std::unordered_map<int , std::vector<double >>> nlm_on_the_fly;
347+ const bool is_on_the_fly = (nlm_tot.size () != this ->ucell ->nat );
348+ if (is_on_the_fly)
347349 {
348- iat00 = 0 ;
349- nlm_tot[iat00].clear ();
350- this ->pre_calculate_nlm (iat0, nlm_tot[iat00]);
350+ this ->pre_calculate_nlm (iat0, nlm_on_the_fly);
351351 }
352- std::vector<std::unordered_map<int , std::vector<double >>>& nlm_iat = nlm_tot[iat00 ];
352+ std::vector<std::unordered_map<int , std::vector<double >>>& nlm_iat = is_on_the_fly ? nlm_on_the_fly : nlm_tot[iat0 ];
353353
354354 // 2. calculate <phi_I|beta>D<beta|phi_{J,R}> for each pair of <IJR> atoms
355355 for (int ad1 = 0 ; ad1 < adjs.adj_num + 1 ; ++ad1)
@@ -432,8 +432,11 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::calculate_HR()
432432 hr_current.data (),
433433 &col_size);
434434 // add data of HR to target BaseMatrix
435+ #pragma omp critical
436+ {
435437 this ->cal_HR_IJR (hr_current.data (), row_size, col_size, tmp->get_pointer ());
436438 }
439+ }
437440 }
438441 }
439442 ModuleBase::timer::tick (" DeePKS" , " calculate_HR" );
0 commit comments