Skip to content

Commit

Permalink
Refactor:Use pointers instead of function calls in OpenMP (#4827)
Browse files Browse the repository at this point in the history
* change omp parallel

* delete gint_kernel_vlocal

* gint vlocal without openmp

* fix gint_kernel_vlcoal

* Revert "fix gint_kernel_vlcoal"

This reverts commit 248182a.

* fix openmp in gint kernel

* without openmp in gint

* use without opemp

* adjust comment

* fix without openmp in multi-k bug

* fix gint vlocal

* fix dvlocal

* fix dvlocal openmp

* stabale function

* stable function in vlocal openmp and none openmp

* fix dvlocal openmp

* fix openmp vlocal_meta

* fix rho and tau in openmp

* fix openmp without force

* fix bug in force openmp

* fix openmp force bug

* fix meta-force openmp bug

* fix bug of openmp force

* fix bug in force openmp meta

* change cal_gint_vlocal_kernel

* change cal_gint_rho_tau_kernel

* change cal_gint_force_kernel

* stable pointer init vlocal openmp version

* use static memory instead of dynamic memory

* change dvlocal memory

* change vlocal-meta memory

* stable change rho memory

* stable change rho memory

* stable change tau memory

* change force memory

* change force-meta memory

* adjust function

* fix function name

* use vector instead of staic memory in force

* Revert "use vector instead of staic memory in force"

This reverts commit ef947fd.

* use vector instead of staic memory in force

* use vector instead of staic memory in rho

* use vector instead of staic memory in vlocal

* change function

* change LD_pool

* change vindex

* change get_vldr3 and vindex

* add comments in doxygen format

* [pre-commit.ci lite] apply automatic fixes

* fix bug in k_gamma env

* fix openmp ifdef in vlocal

* fix openmp ifdef in rho

* fix openmp ifdef in force

* fix vector in openmp

* fix vector in openmp

* fix openmp in cal_env

* fix bug and delete private

* fix a timer error

* add const to LD_pool

* modify LD_pool

* remove some unreferenced variable

* remove some unused variables

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: dzzz2001 <[email protected]>
  • Loading branch information
3 people authored Aug 2, 2024
1 parent a83a3b6 commit 5689e8c
Show file tree
Hide file tree
Showing 17 changed files with 879 additions and 1,283 deletions.
1 change: 1 addition & 0 deletions source/module_elecstate/elecstate_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void ElecStateLCAO<double>::psiToRho(const psi::Psi<double>& psi)
psi,
*(this->DM));
this->DM->cal_DMR();
ModuleBase::timer::tick("ElecStateLCAO", "cal_dm_2d");
}

for (int is = 0; is < GlobalV::NSPIN; is++)
Expand Down
30 changes: 8 additions & 22 deletions source/module_hamilt_lcao/module_gint/gint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ Gint::~Gint() {

void Gint::cal_gint(Gint_inout* inout) {
ModuleBase::timer::tick("Gint_interface", "cal_gint");
const UnitCell& ucell = *this->ucell;
const int max_size = this->gridt->max_atom;
const int LD_pool = max_size * ucell.nwmax;
const int lgd = this->gridt->lgd;
// In multi-process environments,
// some processes may not be allocated any data.
if (this->gridt->get_init_malloced() == false) {
ModuleBase::WARNING_QUIT("Gint_interface::cal_gint",
"gridt has not been allocated yet!");
}
if (max_size > 0) {
if (this->gridt->max_atom > 0) {
#ifdef __CUDA
if (GlobalV::device_flag == "gpu"
&& (inout->job == Gint_Tools::job_type::vlocal
Expand All @@ -64,34 +60,24 @@ void Gint::cal_gint(Gint_inout* inout) {
mkl_set_num_threads(mkl_threads);
#endif
{
// Here we write omp parallel, each job in this parallel region, uses omp for,
// which conforms to the running rules of OpenMP.
#ifdef _OPENMP
#pragma omp parallel
{
#endif
if (inout->job == Gint_Tools::job_type::vlocal) {
cpu_vlocal_interface(inout);
gint_kernel_vlocal(inout);
} else if (inout->job == Gint_Tools::job_type::dvlocal) {
cpu_dvlocal_interface(inout);
gint_kernel_dvlocal(inout);
} else if (inout->job == Gint_Tools::job_type::vlocal_meta) {
cpu_vlocal_meta_interface(inout);
gint_kernel_vlocal_meta(inout);
} else if (inout->job == Gint_Tools::job_type::rho) {
cpu_rho_interface(inout);
gint_kernel_rho(inout);
} else if (inout->job == Gint_Tools::job_type::tau) {
cpu_tau_interface(inout);
gint_kernel_tau(inout);
} else if (inout->job == Gint_Tools::job_type::force) {
cpu_force_interface(inout);
gint_kernel_force(inout);
} else if (inout->job == Gint_Tools::job_type::force_meta) {
cpu_force_meta_interface(inout);
gint_kernel_force_meta(inout);
}
#ifdef _OPENMP
}
#endif
}
}
ModuleBase::timer::tick("Gint_interface", "cal_gint");

return;
}
}
Expand Down
32 changes: 16 additions & 16 deletions source/module_hamilt_lcao/module_gint/gint.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,34 +79,34 @@ class Gint {

// in cal_gint_cpu.cpp

void cpu_vlocal_interface(Gint_inout* inout);
void gint_kernel_vlocal(Gint_inout* inout);

void cpu_dvlocal_interface(Gint_inout* inout);
void gint_kernel_dvlocal(Gint_inout* inout);

void cpu_vlocal_meta_interface(Gint_inout* inout);
void gint_kernel_vlocal_meta(Gint_inout* inout);

void cpu_rho_interface(Gint_inout* inout);
void gint_kernel_rho(Gint_inout* inout);

void cpu_tau_interface(Gint_inout* inout);
void gint_kernel_tau(Gint_inout* inout);

void cpu_force_interface(Gint_inout* inout);
void gint_kernel_force(Gint_inout* inout);

void cpu_force_meta_interface(Gint_inout* inout);
void gint_kernel_force_meta(Gint_inout* inout);

//------------------------------------------------------
// in gint_vl.cpp
//------------------------------------------------------
// calculate the matrix elements of Hamiltonian matrix,
// < phi_0 | Vl + Vh + Vxc | phi_R> or if the Vna is used,
// < phi_0 | delta_Vh + Vxc | phi_R>.
void gint_kernel_vlocal(const int na_grid,
const int grid_index,
const double delta_r,
double* vldr3,
const int LD_pool,
double* pvpR_reduced,
const UnitCell& ucell,
hamilt::HContainer<double>* hR = nullptr);
// void gint_kernel_vlocal(const int na_grid,
// const int grid_index,
// const double delta_r,
// double* vldr3,
// const int LD_pool,
// double* pvpR_reduced,
// const UnitCell& ucell,
// hamilt::HContainer<double>* hR = nullptr);

// calculate < phi_0 | vlocal | dphi_R >
void gint_kernel_dvlocal(const int na_grid,
Expand Down Expand Up @@ -148,7 +148,7 @@ class Gint {
// V | phi_R> matrix element.

void cal_meshball_vlocal_k(int na_grid,
int LD_pool,
const int LD_pool,
int grid_index,
int* block_size,
int* block_index,
Expand Down
Loading

0 comments on commit 5689e8c

Please sign in to comment.