@@ -93,33 +93,42 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
9393 std::vector<double > exc ( nrxx );
9494 std::vector<double > vrho ( nrxx * nspin );
9595 std::vector<double > vsigma ( nrxx * ((1 ==nspin)?1 :3 ) );
96- switch ( func.info ->family )
96+
97+ ModuleBase::timer::start (" Libxc" ," xc_lda/gga_exc_vxc" );
98+ constexpr int batch_size = 1024 ;
99+ #ifdef _OPENMP
100+ #pragma omp parallel for schedule(static, batch_size)
101+ #endif
102+ for ( int ibatch = 0 ; ibatch < nrxx; ibatch += batch_size )
97103 {
98- case XC_FAMILY_LDA :
99- // call Libxc function: xc_lda_exc_vxc
100- xc_lda_exc_vxc ( &func, nrxx, rho.data (),
101- exc.data (), vrho.data () );
102- break ;
103- case XC_FAMILY_GGA :
104- case XC_FAMILY_HYB_GGA :
105- // call Libxc function: xc_gga_exc_vxc
106- xc_gga_exc_vxc ( &func, nrxx, rho.data (), sigma.data (),
107- exc.data (), vrho.data (), vsigma.data () );
108- break ;
109- default :
110- throw std::domain_error (" func.info->family =" +std::to_string (func.info ->family )
111- +" unfinished in " +std::string (__FILE__)+" line " +std::to_string (__LINE__));
112- break ;
104+ const int ir_end = std::min (ibatch + batch_size, nrxx);
105+ const int npts = ir_end - ibatch;
106+
107+ switch ( func.info ->family )
108+ {
109+ case XC_FAMILY_LDA :
110+ xc_lda_exc_vxc ( &func, npts, rho.data () + ibatch,
111+ exc.data () + ibatch, vrho.data () + ibatch * nspin );
112+ break ;
113+ case XC_FAMILY_GGA :
114+ case XC_FAMILY_HYB_GGA :
115+ xc_gga_exc_vxc ( &func, npts, rho.data () + ibatch, sigma.data () + ibatch,
116+ exc.data () + ibatch, vrho.data () + ibatch * nspin, vsigma.data () + ibatch * ((1 ==nspin)?1 :3 ) );
117+ break ;
118+ default :
119+ throw std::domain_error (" func.info->family =" +std::to_string (func.info ->family )
120+ +" unfinished in " +std::string (__FILE__)+" line " +std::to_string (__LINE__));
121+ }
113122 }
123+ ModuleBase::timer::end (" Libxc" ," xc_lda/gga_exc_vxc" );
114124
115125 // added by jghan, 2024-10-10
116126 double factor = 1.0 ;
117- if ( scaling_factor == nullptr ) { ;
118- } else
127+ if ( scaling_factor )
119128 {
120129 auto pair_factor = scaling_factor->find (func.info ->number );
121- if ( pair_factor != scaling_factor->end () ) { factor = pair_factor-> second ;
122- }
130+ if ( pair_factor != scaling_factor->end () )
131+ { factor = pair_factor-> second ; }
123132 }
124133
125134 // time factor is added by jghan, 2024-10-10
@@ -268,8 +277,29 @@ std::tuple<double,double,ModuleBase::matrix,ModuleBase::matrix> XC_Functional_Li
268277 for ( xc_func_type &func : funcs )
269278 {
270279 assert (func.info ->family == XC_FAMILY_MGGA );
271- xc_mgga_exc_vxc (&func, nrxx, rho.data (), sigma.data (), sigma.data (),
272- kin_r.data (), exc.data (), vrho.data (), vsigma.data (), vlapl.data (), vtau.data ());
280+
281+ ModuleBase::timer::start (" Libxc" ," xc_mgga_exc_vxc" );
282+ constexpr int batch_size = 1024 ;
283+ #ifdef _OPENMP
284+ #pragma omp parallel for schedule(static, batch_size)
285+ #endif
286+ for ( int ibatch = 0 ; ibatch < nrxx; ibatch += batch_size )
287+ {
288+ const int ir_end = std::min (ibatch + batch_size, nrxx);
289+ const int npts = ir_end - ibatch;
290+
291+ xc_mgga_exc_vxc (&func, npts,
292+ rho.data () + ibatch,
293+ sigma.data () + ibatch,
294+ sigma.data () + ibatch,
295+ kin_r.data () + ibatch * nspin,
296+ exc.data () + ibatch,
297+ vrho.data () + ibatch * nspin,
298+ vsigma.data () + ibatch * ((1 ==nspin)?1 :3 ),
299+ vlapl.data () + ibatch * nspin,
300+ vtau.data () + ibatch * nspin);
301+ }
302+ ModuleBase::timer::end (" Libxc" ," xc_mgga_exc_vxc" );
273303
274304 // process etxc
275305 for ( int is=0 ; is!=nspin; ++is )
0 commit comments