diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_gen_fixedH.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_gen_fixedH.cpp index 85234f28eea..f349d9bf22b 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_gen_fixedH.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_gen_fixedH.cpp @@ -162,7 +162,7 @@ void LCAO_gen_fixedH::build_ST_new(const char& dtype, const bool& calc_deri, con // according to global2local_row and global2local_col // the last paramete: 1 for Sloc, 2 for Hloc // and 3 for Hloc_fixed. - this->LM->set_HSgamma(iw1_all, iw2_all, olm[0], dtype, HSloc); + this->LM->set_HSgamma(iw1_all, iw2_all, olm[0], HSloc); } else // k point algorithm { @@ -642,7 +642,7 @@ void LCAO_gen_fixedH::build_Nonlocal_mu_new(double* NLloc, const bool &calc_deri // mohan add 2010-12-20 if( nlm_tmp!=0.0 ) { - this->LM->set_HSgamma(iw1_all,iw2_all,nlm_tmp,'N', NLloc);//N stands for nonlocal. + this->LM->set_HSgamma(iw1_all, iw2_all, nlm_tmp, NLloc);//N stands for nonlocal. } } else diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp index 06dec457862..2cfa7d80ef5 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp @@ -141,8 +141,7 @@ void LCAO_Matrix::allocate_HS_R(const int &nnR) void LCAO_Matrix::set_HSgamma( const int &iw1_all, // index i for atomic orbital (row) const int &iw2_all, // index j for atomic orbital (column) - const double &v, // value for matrix element (i,j) - const char &dtype, // type of the matrix + const double& v, // value for matrix element (i,j) double* HSloc) //input pointer for store the matrix { // use iw1_all and iw2_all to set Hloc diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h index 3d5ec657830..ebe09667d49 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h @@ -190,7 +190,7 @@ class LCAO_Matrix double* DHloc_fixed_33; - void set_HSgamma(const int &iw1_all, const int &iw2_all, const double &v, const char &dtype, double* HSloc); + void set_HSgamma(const int& iw1_all, const int& iw2_all, const double& v, double* HSloc); void set_HSk(const int &iw1_all, const int &iw2_all, const std::complex &v, const char &dtype, const int spin = 0); void set_force (const int& iw1_all, const int& iw2_all, const double& vx, const double& vy, diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp index d08ed784d2d..c7cada84bd8 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp @@ -59,13 +59,13 @@ void Veff>::contributeHk(int ik) if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5) { - Gint_inout inout(vr_eff1, vofk_eff1, this->LM, Gint_Tools::job_type::vlocal_meta); - this->GG->cal_vlocal(&inout, new_e_iteration); + Gint_inout inout(vr_eff1, vofk_eff1, Gint_Tools::job_type::vlocal_meta); + this->GG->cal_vlocal(&inout, this->LM, new_e_iteration); } else { - Gint_inout inout(vr_eff1, this->LM, Gint_Tools::job_type::vlocal); - this->GG->cal_vlocal(&inout, new_e_iteration); + Gint_inout inout(vr_eff1, Gint_Tools::job_type::vlocal); + this->GG->cal_vlocal(&inout, this->LM, new_e_iteration); } this->new_e_iteration = false; diff --git a/source/module_hamilt_lcao/module_gint/gint_gamma.h b/source/module_hamilt_lcao/module_gint/gint_gamma.h index 96e2eaec6dd..ad76ac2c923 100644 --- a/source/module_hamilt_lcao/module_gint/gint_gamma.h +++ b/source/module_hamilt_lcao/module_gint/gint_gamma.h @@ -33,7 +33,7 @@ class Gint_Gamma : public Gint // there is an additional step in calculating vlocal for gamma point // namely the redistribution of Hamiltonian from grid to 2D block format // hence we have an additional layer outside the unified interface - void cal_vlocal(Gint_inout *inout, const bool new_e_iteration); + void cal_vlocal(Gint_inout* inout, LCAO_Matrix* lm, const bool new_e_iteration); //------------------------------------------------------ // in gint_gamma_env.cpp @@ -45,12 +45,18 @@ class Gint_Gamma : public Gint double*** DM; //pointer to LOC.DM - //------------------------------------------------------ - // in gint_gamma_vl.cpp - //------------------------------------------------------ - // method for redistributing the Hamiltonian - // from grid to 2D format - void vl_grid_to_2D(const int lgd, LCAO_Matrix& lm, const bool new_e_iteration); + ///------------------------------------------------------ + /// in gint_gamma_vl.cpp + ///------------------------------------------------------ + /// method for redistributing the Hamiltonian + /// from grid to 2D format + /// pass a setter function to customize row/col major and outputs + void vl_grid_to_2D(const double* vl_grid, + const Parallel_2D& p2d, + const int loc_grid_dim, + const bool new_e_iteration, + double* vl_2d, + std::function setfunc); ///=============================== /// Use MPI_Alltoallv to convert a grid distributed matrix diff --git a/source/module_hamilt_lcao/module_gint/gint_gamma_vl.cpp b/source/module_hamilt_lcao/module_gint/gint_gamma_vl.cpp index 099b66ee1c4..fea8dc4272a 100644 --- a/source/module_hamilt_lcao/module_gint/gint_gamma_vl.cpp +++ b/source/module_hamilt_lcao/module_gint/gint_gamma_vl.cpp @@ -26,7 +26,7 @@ extern "C" void Cblacs_pcoord(int icontxt, int pnum, int *prow, int *pcol); } -void Gint_Gamma::cal_vlocal(Gint_inout *inout, const bool new_e_iteration) +void Gint_Gamma::cal_vlocal(Gint_inout* inout, LCAO_Matrix* lm, bool new_e_iteration) { const int max_size = this->gridt->max_atom; const int lgd = this->gridt->lgd; @@ -40,10 +40,10 @@ void Gint_Gamma::cal_vlocal(Gint_inout *inout, const bool new_e_iteration) } this->cal_gint(inout); + this->vl_grid_to_2D(pvpR_grid, *lm->ParaV, lgd, new_e_iteration, lm->Hloc.data(), + std::bind(&LCAO_Matrix::set_HSgamma, lm, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); - this->vl_grid_to_2D(lgd,inout->lm[0], new_e_iteration); - - if (max_size >0 && lgd > 0) delete[] pvpR_grid; + if (max_size > 0 && lgd > 0) delete[] pvpR_grid; } } @@ -192,7 +192,8 @@ inline int setBufferParameter( } #endif -void Gint_Gamma::vl_grid_to_2D(const int lgd_now, LCAO_Matrix &lm, const bool new_e_iteration) +void Gint_Gamma::vl_grid_to_2D(const double* vl_grid, const Parallel_2D& p2d, const int loc_grid_dim, const bool new_e_iteration, double* vl_2d, + std::function setfunc) { ModuleBase::timer::tick("Gint_Gamma","distri_vl"); // setup send buffer and receive buffer size @@ -201,7 +202,7 @@ void Gint_Gamma::vl_grid_to_2D(const int lgd_now, LCAO_Matrix &lm, const bool ne { ModuleBase::timer::tick("Gint_Gamma","distri_vl_index"); #ifdef __MPI - setBufferParameter(*this->gridt, lm.ParaV->comm_2D, lm.ParaV->blacs_ctxt, lm.ParaV->nb, + setBufferParameter(*this->gridt, p2d.comm_2D, p2d.blacs_ctxt, p2d.nb, this->sender_index_size, this->sender_local_index, this->sender_size_process, this->sender_displacement_process, this->sender_size, this->sender_buffer, @@ -226,11 +227,11 @@ void Gint_Gamma::vl_grid_to_2D(const int lgd_now, LCAO_Matrix &lm, const bool ne const int icol=this->sender_local_index[i+1]; if(irow<=icol) { - this->sender_buffer[i/2]=pvpR_grid[irow*lgd_now+icol]; + this->sender_buffer[i / 2] = vl_grid[irow * loc_grid_dim + icol]; } else { - this->sender_buffer[i/2]=pvpR_grid[icol*lgd_now+irow]; + this->sender_buffer[i / 2] = vl_grid[icol * loc_grid_dim + irow]; } } @@ -242,7 +243,7 @@ void Gint_Gamma::vl_grid_to_2D(const int lgd_now, LCAO_Matrix &lm, const bool ne #ifdef __MPI MPI_Alltoallv(this->sender_buffer, this->sender_size_process, this->sender_displacement_process, MPI_DOUBLE, this->receiver_buffer, this->receiver_size_process, - this->receiver_displacement_process, MPI_DOUBLE, lm.ParaV->comm_2D); + this->receiver_displacement_process, MPI_DOUBLE, p2d.comm_2D); #endif #ifdef __DEBUG @@ -252,9 +253,9 @@ void Gint_Gamma::vl_grid_to_2D(const int lgd_now, LCAO_Matrix &lm, const bool ne // put local data to H matrix for(int i=0; ireceiver_index_size; i+=2) { - const int g_row=this->receiver_global_index[i]; - const int g_col=this->receiver_global_index[i+1]; - lm.set_HSgamma(g_row,g_col,this->receiver_buffer[i/2],'L', lm.Hloc.data()); + const int g_row = this->receiver_global_index[i]; + const int g_col = this->receiver_global_index[i + 1]; + setfunc(g_row, g_col, this->receiver_buffer[i / 2], vl_2d); } ModuleBase::timer::tick("Gint_Gamma","distri_vl_value"); diff --git a/source/module_hamilt_lcao/module_gint/gint_tools.h b/source/module_hamilt_lcao/module_gint/gint_tools.h index 5743371d1f1..fe3a7aef4ba 100644 --- a/source/module_hamilt_lcao/module_gint/gint_tools.h +++ b/source/module_hamilt_lcao/module_gint/gint_tools.h @@ -6,7 +6,6 @@ #include "grid_technique.h" #include #include "module_elecstate/module_charge/charge.h" -#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h" namespace Gint_Tools { @@ -28,7 +27,6 @@ class Gint_inout bool isforce; bool isstress; int ispin; - LCAO_Matrix *lm; //output double** rho; @@ -129,19 +127,17 @@ class Gint_inout } // vlocal, gamma point - Gint_inout(const double* vl_in, LCAO_Matrix *lm_in, Gint_Tools::job_type job_in) + Gint_inout(const double* vl_in, Gint_Tools::job_type job_in) { vl = vl_in; - lm = lm_in; job = job_in; } // mGGA vlocal, gamma point - Gint_inout(const double* vl_in, const double* vofk_in, LCAO_Matrix *lm_in, Gint_Tools::job_type job_in) + Gint_inout(const double* vl_in, const double* vofk_in, Gint_Tools::job_type job_in) { vl = vl_in; - vofk = vofk_in; - lm = lm_in; + vofk = vofk_in; job = job_in; } }; diff --git a/source/module_ri/RI_2D_Comm.hpp b/source/module_ri/RI_2D_Comm.hpp index 4a5746272d7..081f1fad9a5 100644 --- a/source/module_ri/RI_2D_Comm.hpp +++ b/source/module_ri/RI_2D_Comm.hpp @@ -122,7 +122,7 @@ void RI_2D_Comm::add_Hexx( if(GlobalV::GAMMA_ONLY_LOCAL) lm.set_HSgamma(iwt0, iwt1, RI::Global_Func::convert(H(iw0_b, iw1_b)) * RI::Global_Func::convert(frac), - 'L', lm.Hloc.data()); + lm.Hloc.data()); else lm.set_HSk(iwt0, iwt1, RI::Global_Func::convert>(H(iw0_b, iw1_b)) * frac,