Skip to content

Commit

Permalink
replace array pool with vector
Browse files Browse the repository at this point in the history
  • Loading branch information
dzzz2001 committed Jan 13, 2025
1 parent 5e193d1 commit 50b692e
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ void GintAtom::set_phi_dphi(
}

std::vector<double> rly(std::pow(atom_->nwl + 1, 2));
// TODO: replace array_pool with std::vector
ModuleBase::Array_Pool<double> grly(std::pow(atom_->nwl + 1, 2), 3);

for(int im = 0; im < num_mgrids; im++)
Expand Down
30 changes: 18 additions & 12 deletions source/module_hamilt_lcao/module_gint/new_grid_tech/gint_fvl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "module_base/array_pool.h"
#include "module_base/global_function.h"
#include "gint_fvl.h"
#include "gint_common.h"
Expand Down Expand Up @@ -28,6 +27,12 @@ void Gint_fvl::cal_fvl_svl_()
#pragma omp parallel
{
PhiOperator phi_op;
std::vector<double> phi;
std::vector<double> phi_vldr3;
std::vector<double> phi_vldr3_DM;
std::vector<double> dphi_x;
std::vector<double> dphi_y;
std::vector<double> dphi_z;
ModuleBase::matrix* fvl_thread = nullptr;
ModuleBase::matrix* svl_thread = nullptr;
if(isforce_)
Expand All @@ -48,24 +53,25 @@ void Gint_fvl::cal_fvl_svl_()
continue;
}
phi_op.set_bgrid(biggrid);
ModuleBase::Array_Pool<double> phi(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> phi_vldr3(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> phi_vldr3_DM(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_x(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_y(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_z(phi_op.get_rows(), phi_op.get_cols());
phi_op.set_phi_dphi(phi.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D());
const int phi_len = phi_op.get_rows() * phi_op.get_cols();
phi.resize(phi_len);
phi_vldr3.resize(phi_len);
phi_vldr3_DM.resize(phi_len);
dphi_x.resize(phi_len);
dphi_y.resize(phi_len);
dphi_z.resize(phi_len);
phi_op.set_phi_dphi(phi.data(), dphi_x.data(), dphi_y.data(), dphi_z.data());
for (int is = 0; is < nspin_; is++)
{
phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D());
phi_op.phi_mul_dm(phi_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, phi_vldr3_DM.get_ptr_1D());
phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.data(), phi_vldr3.data());
phi_op.phi_mul_dm(phi_vldr3.data(), *DMRGint_vec_[is], false, phi_vldr3_DM.data());
if(isforce_)
{
phi_op.phi_dot_dphi(phi_vldr3_DM.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D(), fvl_thread);
phi_op.phi_dot_dphi(phi_vldr3_DM.data(), dphi_x.data(), dphi_y.data(), dphi_z.data(), fvl_thread);
}
if(isstress_)
{
phi_op.phi_dot_dphi_r(phi_vldr3_DM.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D(), svl_thread);
phi_op.phi_dot_dphi_r(phi_vldr3_DM.data(), dphi_x.data(), dphi_y.data(), dphi_z.data(), svl_thread);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "module_base/array_pool.h"
#include "module_base/global_function.h"
#include "gint_fvl_meta.h"
#include "gint_common.h"
Expand Down Expand Up @@ -28,6 +27,24 @@ void Gint_fvl_meta::cal_fvl_svl_()
#pragma omp parallel
{
PhiOperator phi_op;
std::vector<double> phi;
std::vector<double> phi_vldr3;
std::vector<double> phi_vldr3_DM;
std::vector<double> dphi_x;
std::vector<double> dphi_y;
std::vector<double> dphi_z;
std::vector<double> dphi_x_vldr3;
std::vector<double> dphi_y_vldr3;
std::vector<double> dphi_z_vldr3;
std::vector<double> dphi_x_vldr3_DM;
std::vector<double> dphi_y_vldr3_DM;
std::vector<double> dphi_z_vldr3_DM;
std::vector<double> ddphi_xx;
std::vector<double> ddphi_xy;
std::vector<double> ddphi_xz;
std::vector<double> ddphi_yy;
std::vector<double> ddphi_yz;
std::vector<double> ddphi_zz;
ModuleBase::matrix* fvl_thread = nullptr;
ModuleBase::matrix* svl_thread = nullptr;
if(isforce_)
Expand All @@ -48,50 +65,51 @@ void Gint_fvl_meta::cal_fvl_svl_()
continue;
}
phi_op.set_bgrid(biggrid);
ModuleBase::Array_Pool<double> phi(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_x(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_y(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_z(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> ddphi_xx(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> ddphi_xy(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> ddphi_xz(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> ddphi_yy(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> ddphi_yz(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> ddphi_zz(phi_op.get_rows(), phi_op.get_cols());
phi_op.set_phi_dphi(phi.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D());
phi_op.set_ddphi(ddphi_xx.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_xz.get_ptr_1D(),
ddphi_yy.get_ptr_1D(), ddphi_yz.get_ptr_1D(), ddphi_zz.get_ptr_1D());
ModuleBase::Array_Pool<double> phi_vldr3(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> phi_vldr3_DM(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_x_vldr3(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_y_vldr3(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_z_vldr3(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_x_vldr3_DM(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_y_vldr3_DM(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_z_vldr3_DM(phi_op.get_rows(), phi_op.get_cols());
const int phi_len = phi_op.get_rows() * phi_op.get_cols();
phi.resize(phi_len);
phi_vldr3.resize(phi_len);
phi_vldr3_DM.resize(phi_len);
dphi_x.resize(phi_len);
dphi_y.resize(phi_len);
dphi_z.resize(phi_len);
dphi_x_vldr3.resize(phi_len);
dphi_y_vldr3.resize(phi_len);
dphi_z_vldr3.resize(phi_len);
dphi_x_vldr3_DM.resize(phi_len);
dphi_y_vldr3_DM.resize(phi_len);
dphi_z_vldr3_DM.resize(phi_len);
ddphi_xx.resize(phi_len);
ddphi_xy.resize(phi_len);
ddphi_xz.resize(phi_len);
ddphi_yy.resize(phi_len);
ddphi_yz.resize(phi_len);
ddphi_zz.resize(phi_len);
phi_op.set_phi_dphi(phi.data(), dphi_x.data(), dphi_y.data(), dphi_z.data());
phi_op.set_ddphi(ddphi_xx.data(), ddphi_xy.data(), ddphi_xz.data(),
ddphi_yy.data(), ddphi_yz.data(), ddphi_zz.data());
for (int is = 0; is < nspin_; is++)
{
phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D());
phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.get_ptr_1D(), dphi_x_vldr3.get_ptr_1D());
phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.get_ptr_1D(), dphi_y_vldr3.get_ptr_1D());
phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_z.get_ptr_1D(), dphi_z_vldr3.get_ptr_1D());
phi_op.phi_mul_dm(phi_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, phi_vldr3_DM.get_ptr_1D());
phi_op.phi_mul_dm(dphi_x_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, dphi_x_vldr3_DM.get_ptr_1D());
phi_op.phi_mul_dm(dphi_y_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, dphi_y_vldr3_DM.get_ptr_1D());
phi_op.phi_mul_dm(dphi_z_vldr3.get_ptr_1D(), *DMRGint_vec_[is], false, dphi_z_vldr3_DM.get_ptr_1D());
phi_op.phi_mul_vldr3(vr_eff_[is], dr3_, phi.data(), phi_vldr3.data());
phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_x.data(), dphi_x_vldr3.data());
phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_y.data(), dphi_y_vldr3.data());
phi_op.phi_mul_vldr3(vofk_[is], dr3_, dphi_z.data(), dphi_z_vldr3.data());
phi_op.phi_mul_dm(phi_vldr3.data(), *DMRGint_vec_[is], false, phi_vldr3_DM.data());
phi_op.phi_mul_dm(dphi_x_vldr3.data(), *DMRGint_vec_[is], false, dphi_x_vldr3_DM.data());
phi_op.phi_mul_dm(dphi_y_vldr3.data(), *DMRGint_vec_[is], false, dphi_y_vldr3_DM.data());
phi_op.phi_mul_dm(dphi_z_vldr3.data(), *DMRGint_vec_[is], false, dphi_z_vldr3_DM.data());
if(isforce_)
{
phi_op.phi_dot_dphi(phi_vldr3_DM.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D(), fvl_thread);
phi_op.phi_dot_dphi(dphi_x_vldr3_DM.get_ptr_1D(), ddphi_xx.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_xz.get_ptr_1D(), fvl_thread);
phi_op.phi_dot_dphi(dphi_y_vldr3_DM.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_yy.get_ptr_1D(), ddphi_yz.get_ptr_1D(), fvl_thread);
phi_op.phi_dot_dphi(dphi_z_vldr3_DM.get_ptr_1D(), ddphi_xz.get_ptr_1D(), ddphi_yz.get_ptr_1D(), ddphi_zz.get_ptr_1D(), fvl_thread);
phi_op.phi_dot_dphi(phi_vldr3_DM.data(), dphi_x.data(), dphi_y.data(), dphi_z.data(), fvl_thread);
phi_op.phi_dot_dphi(dphi_x_vldr3_DM.data(), ddphi_xx.data(), ddphi_xy.data(), ddphi_xz.data(), fvl_thread);
phi_op.phi_dot_dphi(dphi_y_vldr3_DM.data(), ddphi_xy.data(), ddphi_yy.data(), ddphi_yz.data(), fvl_thread);
phi_op.phi_dot_dphi(dphi_z_vldr3_DM.data(), ddphi_xz.data(), ddphi_yz.data(), ddphi_zz.data(), fvl_thread);
}
if(isstress_)
{
phi_op.phi_dot_dphi_r(phi_vldr3_DM.get_ptr_1D(), dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D(), svl_thread);
phi_op.phi_dot_dphi_r(dphi_x_vldr3_DM.get_ptr_1D(), ddphi_xx.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_xz.get_ptr_1D(), svl_thread);
phi_op.phi_dot_dphi_r(dphi_y_vldr3_DM.get_ptr_1D(), ddphi_xy.get_ptr_1D(), ddphi_yy.get_ptr_1D(), ddphi_yz.get_ptr_1D(), svl_thread);
phi_op.phi_dot_dphi_r(dphi_z_vldr3_DM.get_ptr_1D(), ddphi_xz.get_ptr_1D(), ddphi_yz.get_ptr_1D(), ddphi_zz.get_ptr_1D(), svl_thread);
phi_op.phi_dot_dphi_r(phi_vldr3_DM.data(), dphi_x.data(), dphi_y.data(), dphi_z.data(), svl_thread);
phi_op.phi_dot_dphi_r(dphi_x_vldr3_DM.data(), ddphi_xx.data(), ddphi_xy.data(), ddphi_xz.data(), svl_thread);
phi_op.phi_dot_dphi_r(dphi_y_vldr3_DM.data(), ddphi_xy.data(), ddphi_yy.data(), ddphi_yz.data(), svl_thread);
phi_op.phi_dot_dphi_r(dphi_z_vldr3_DM.data(), ddphi_xz.data(), ddphi_yz.data(), ddphi_zz.data(), svl_thread);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ GintInfo::GintInfo(
unitcell_info_ = std::make_shared<UnitCellInfo>(ucell_->a1 * ucell_->lat0, ucell_->a2 * ucell_->lat0, ucell_->a3 * ucell_->lat0,
nbx, nby, nbz, nmx, nmy, nmz);

biggrid_info_ = unitcell_info_->get_biggrid_info();
meshgrid_info_ = biggrid_info_->get_meshgrid_info();

// initialize the divide information
divide_info_ = std::make_shared<DivideInfo>(startidx_bx, startidx_by, startidx_bz,
nbx_local, nby_local, nbz_local, unitcell_info_, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class GintInfo
// getter functions
std::vector<std::shared_ptr<BigGrid>> get_biggrids() const { return biggrids_; };
double get_local_mgrid_num() const { return localcell_info_->get_mgrid_num(); };
double get_mgrid_volume() const { return unitcell_info_->get_meshgrid_info()->get_volume(); };
double get_mgrid_volume() const { return meshgrid_info_->get_volume(); };

//=========================================
// functions about hcontainer
Expand All @@ -51,6 +51,12 @@ class GintInfo
// the unitcell information
std::shared_ptr<const UnitCellInfo> unitcell_info_;

// the biggrid information
std::shared_ptr<const BigGridInfo> biggrid_info_;

// the meshgrid information
std::shared_ptr<const MeshGridInfo> meshgrid_info_;

// the divide information
std::shared_ptr<const DivideInfo> divide_info_;

Expand Down
14 changes: 8 additions & 6 deletions source/module_hamilt_lcao/module_gint/new_grid_tech/gint_rho.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "module_base/array_pool.h"
#include "module_base/global_function.h"
#include "gint_rho.h"
#include "gint_common.h"
Expand Down Expand Up @@ -28,6 +27,8 @@ void Gint_rho::cal_rho_()
#pragma omp parallel
{
PhiOperator phi_op;
std::vector<double> phi;
std::vector<double> phi_DMR;
#pragma omp for schedule(dynamic)
for(const auto& biggrid: gint_info_->get_biggrids())
{
Expand All @@ -36,13 +37,14 @@ void Gint_rho::cal_rho_()
continue;
}
phi_op.set_bgrid(biggrid);
ModuleBase::Array_Pool<double> phi(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> phi_DMR(phi_op.get_rows(), phi_op.get_cols());
phi_op.set_phi(phi.get_ptr_1D());
const int phi_len = phi_op.get_rows() * phi_op.get_cols();
phi.resize(phi_len);
phi_DMR.resize(phi_len);
phi_op.set_phi(phi.data());
for (int is = 0; is < nspin_; is++)
{
phi_op.phi_mul_dm(phi.get_ptr_1D(), *DMRGint_vec_[is], true, phi_DMR.get_ptr_1D());
phi_op.phi_dot_phi_dm(phi.get_ptr_1D(), phi_DMR.get_ptr_1D(), rho_[is]);
phi_op.phi_mul_dm(phi.data(), *DMRGint_vec_[is], true, phi_DMR.data());
phi_op.phi_dot_phi_dm(phi.data(), phi_DMR.data(), rho_[is]);
}
}
}
Expand Down
34 changes: 20 additions & 14 deletions source/module_hamilt_lcao/module_gint/new_grid_tech/gint_tau.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "module_base/array_pool.h"
#include "module_base/global_function.h"
#include "gint_tau.h"
#include "gint_common.h"
Expand Down Expand Up @@ -28,6 +27,12 @@ void Gint_tau::cal_tau_()
#pragma omp parallel
{
PhiOperator phi_op;
std::vector<double> dphi_x;
std::vector<double> dphi_y;
std::vector<double> dphi_z;
std::vector<double> dphi_x_DM;
std::vector<double> dphi_y_DM;
std::vector<double> dphi_z_DM;
#pragma omp for schedule(dynamic)
for(const auto& biggrid: gint_info_->get_biggrids())
{
Expand All @@ -36,21 +41,22 @@ void Gint_tau::cal_tau_()
continue;
}
phi_op.set_bgrid(biggrid);
ModuleBase::Array_Pool<double> dphi_x(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_y(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_z(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_x_DM(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_y_DM(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> dphi_z_DM(phi_op.get_rows(), phi_op.get_cols());
phi_op.set_phi_dphi(nullptr, dphi_x.get_ptr_1D(), dphi_y.get_ptr_1D(), dphi_z.get_ptr_1D());
const int phi_len = phi_op.get_rows() * phi_op.get_cols();
dphi_x.resize(phi_len);
dphi_y.resize(phi_len);
dphi_z.resize(phi_len);
dphi_x_DM.resize(phi_len);
dphi_y_DM.resize(phi_len);
dphi_z_DM.resize(phi_len);
phi_op.set_phi_dphi(nullptr, dphi_x.data(), dphi_y.data(), dphi_z.data());
for (int is = 0; is < nspin_; is++)
{
phi_op.phi_mul_dm(dphi_x.get_ptr_1D(), *DMRGint_vec_[is], true, dphi_x_DM.get_ptr_1D());
phi_op.phi_mul_dm(dphi_y.get_ptr_1D(), *DMRGint_vec_[is], true, dphi_y_DM.get_ptr_1D());
phi_op.phi_mul_dm(dphi_z.get_ptr_1D(), *DMRGint_vec_[is], true, dphi_z_DM.get_ptr_1D());
phi_op.phi_dot_phi_dm(dphi_x.get_ptr_1D(), dphi_x_DM.get_ptr_1D(), kin_[is]);
phi_op.phi_dot_phi_dm(dphi_y.get_ptr_1D(), dphi_y_DM.get_ptr_1D(), kin_[is]);
phi_op.phi_dot_phi_dm(dphi_z.get_ptr_1D(), dphi_z_DM.get_ptr_1D(), kin_[is]);
phi_op.phi_mul_dm(dphi_x.data(), *DMRGint_vec_[is], true, dphi_x_DM.data());
phi_op.phi_mul_dm(dphi_y.data(), *DMRGint_vec_[is], true, dphi_y_DM.data());
phi_op.phi_mul_dm(dphi_z.data(), *DMRGint_vec_[is], true, dphi_z_DM.data());
phi_op.phi_dot_phi_dm(dphi_x.data(), dphi_x_DM.data(), kin_[is]);
phi_op.phi_dot_phi_dm(dphi_y.data(), dphi_y_DM.data(), kin_[is]);
phi_op.phi_dot_phi_dm(dphi_z.data(), dphi_z_DM.data(), kin_[is]);
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions source/module_hamilt_lcao/module_gint/new_grid_tech/gint_vl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "module_base/array_pool.h"
#include "module_base/blas_connector.h"
#include "gint_common.h"
#include "gint_vl.h"
Expand Down Expand Up @@ -32,6 +31,8 @@ void Gint_vl::cal_hRGint_()
#pragma omp parallel
{
PhiOperator phi_op;
std::vector<double> phi;
std::vector<double> phi_vldr3;
HContainer<double> hRGint_local(*hRGint_);
#pragma omp for schedule(dynamic)
for(const auto& biggrid: gint_info_->get_biggrids())
Expand All @@ -41,11 +42,12 @@ void Gint_vl::cal_hRGint_()
continue;
}
phi_op.set_bgrid(biggrid);
ModuleBase::Array_Pool<double> phi(phi_op.get_rows(), phi_op.get_cols());
ModuleBase::Array_Pool<double> phi_vldr3(phi_op.get_rows(), phi_op.get_cols());
phi_op.set_phi(phi.get_ptr_1D());
phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.get_ptr_1D(), phi_vldr3.get_ptr_1D());
phi_op.phi_mul_phi_vldr3(phi.get_ptr_1D(), phi_vldr3.get_ptr_1D(), &hRGint_local);
const int phi_len = phi_op.get_rows() * phi_op.get_cols();
phi.resize(phi_len);
phi_vldr3.resize(phi_len);
phi_op.set_phi(phi.data());
phi_op.phi_mul_vldr3(vr_eff_, dr3_, phi.data(), phi_vldr3.data());
phi_op.phi_mul_phi_vldr3(phi.data(), phi_vldr3.data(), &hRGint_local);
}
#pragma omp critical
{
Expand Down
Loading

0 comments on commit 50b692e

Please sign in to comment.