From 27ff8e7bc4e3423374fb222327c3a2841633c79b Mon Sep 17 00:00:00 2001 From: maki49 <1579492865@qq.com> Date: Wed, 9 Mar 2022 16:48:00 +0800 Subject: [PATCH 1/3] remove redundant readin code and debug readin function --- source/src_io/wf_local.cpp | 22 +++++------ source/src_io/wf_local.h | 4 +- source/src_lcao/DM_k.cpp | 48 ------------------------ source/src_lcao/local_orbital_charge.cpp | 6 +-- source/src_lcao/local_orbital_charge.h | 3 -- source/src_lcao/local_orbital_wfc.cpp | 40 ++++++++++---------- 6 files changed, 35 insertions(+), 88 deletions(-) diff --git a/source/src_io/wf_local.cpp b/source/src_io/wf_local.cpp index dac5328f368..353e73d4334 100644 --- a/source/src_io/wf_local.cpp +++ b/source/src_io/wf_local.cpp @@ -54,14 +54,13 @@ inline int CTOT2q_c( } // be called in local_orbital_wfc::allocate_k -int WF_Local::read_lowf_complex(std::complex** c, const int& ik, +int WF_Local::read_lowf_complex(std::complex** ctot, const int& ik, Local_Orbital_wfc &lowf) { ModuleBase::TITLE("WF_Local","read_lowf_complex"); ModuleBase::timer::tick("WF_Local","read_lowf_complex"); - std::complex **ctot; - + lowf.wfc_k[ik].create(lowf.ParaV->ncol_bands, lowf.ParaV->nrow); std::stringstream ss; // read wave functions // write is in ../src_pdiag/pdiag_basic.cpp @@ -212,14 +211,12 @@ int WF_Local::read_lowf_complex(std::complex** c, const int& ik, return 0; } -int WF_Local::read_lowf(double** c, const int& is, +int WF_Local::read_lowf(double** ctot, const int& is, Local_Orbital_wfc &lowf) { ModuleBase::TITLE("WF_Local","read_lowf"); - ModuleBase::timer::tick("WF_Local","read_lowf"); - - double **ctot; - + ModuleBase::timer::tick("WF_Local", "read_lowf"); + std::stringstream ss; if(GlobalV::GAMMA_ONLY_LOCAL) { @@ -498,7 +495,7 @@ void WF_Local::distri_lowf_complex_new(std::complex** ctot, const int& i //1. alloc work array; set some parameters long maxnloc; // maximum number of elements in local matrix - MPI_Reduce(&lowf.ParaV->nloc, &maxnloc, 1, MPI_LONG, MPI_MAX, 0, lowf.ParaV->comm_2D); + MPI_Reduce(&lowf.ParaV->nloc_wfc, &maxnloc, 1, MPI_LONG, MPI_MAX, 0, lowf.ParaV->comm_2D); MPI_Bcast(&maxnloc, 1, MPI_LONG, 0, lowf.ParaV->comm_2D); //reduce and bcast could be replaced by allreduce @@ -533,7 +530,7 @@ void WF_Local::distri_lowf_complex_new(std::complex** ctot, const int& i if(myid==src_rank) { naroc[0]=lowf.ParaV->nrow; - naroc[1]=lowf.ParaV->ncol; + naroc[1]=lowf.ParaV->ncol_bands; } info=MPI_Bcast(naroc, 2, MPI_INT, src_rank, lowf.ParaV->comm_2D); @@ -547,10 +544,11 @@ void WF_Local::distri_lowf_complex_new(std::complex** ctot, const int& i //} //ofs_running << std::endl; //2.3 copy from work to wfc_k - const int inc=1; + std::cout << "2.2 ok" << std::endl; + const int inc = 1; if(myid==src_rank) { - BlasConnector::copy(lowf.ParaV->nloc, work, inc, lowf.wfc_k.at(ik).c, inc); + BlasConnector::copy(lowf.ParaV->nloc_wfc, work, inc, lowf.wfc_k.at(ik).c, inc); } }//loop ipcol }//loop iprow diff --git a/source/src_io/wf_local.h b/source/src_io/wf_local.h index 881f0cf11ad..cfab00001af 100644 --- a/source/src_io/wf_local.h +++ b/source/src_io/wf_local.h @@ -21,10 +21,10 @@ namespace WF_Local void distri_lowf_complex_new(std::complex** ctot, const int& ik, Local_Orbital_wfc &lowf); - int read_lowf(double** c, const int& is, + int read_lowf(double** ctot, const int& is, Local_Orbital_wfc &lowf); - int read_lowf_complex(std::complex** c, const int& ik, + int read_lowf_complex(std::complex** ctot, const int& ik, Local_Orbital_wfc &lowf); } diff --git a/source/src_lcao/DM_k.cpp b/source/src_lcao/DM_k.cpp index 93e3ec81186..64faaaf4d63 100644 --- a/source/src_lcao/DM_k.cpp +++ b/source/src_lcao/DM_k.cpp @@ -49,58 +49,10 @@ void Local_Orbital_Charge::allocate_DM_k(void) // Peize Lin test 2019-01-16 this->init_dm_2d(); - if(GlobalC::wf.start_wfc=="file") - { - this->kpt_file(GlobalC::GridT, *this->LOWF); - } return; } -void Local_Orbital_Charge::kpt_file(const Grid_Technique& gt, - Local_Orbital_wfc &lowf) -{ - ModuleBase::TITLE("Local_Orbital_Charge","kpt_file"); - - int error; - std::cout << " Read in wave functions files: " << GlobalC::kv.nkstot << std::endl; - - std::complex **ctot; - - for(int ik=0; ikParaV->ncol_bands, this->ParaV->nrow); - lowf.wfc_k[ik].zero_out(); - - GlobalV::ofs_running << " Read in wave functions " << ik + 1 << std::endl; - error = WF_Local::read_lowf_complex( ctot , ik, lowf); - -#ifdef __MPI - Parallel_Common::bcast_int(error); -#endif - GlobalV::ofs_running << " Error=" << error << std::endl; - if(error==1) - { - ModuleBase::WARNING_QUIT("Local_Orbital_wfc","Can't find the wave function file: LOWF.dat"); - } - else if(error==2) - { - ModuleBase::WARNING_QUIT("Local_Orbital_wfc","In wave function file, band number doesn't match"); - } - else if(error==3) - { - ModuleBase::WARNING_QUIT("Local_Orbital_wfc","In wave function file, nlocal doesn't match"); - } - else if(error==4) - { - ModuleBase::WARNING_QUIT("Local_Orbital_wfc","In k-dependent wave function file, k point is not correct"); - } - - }//loop ispin -} - - #include "record_adj.h" inline void cal_DM_ATOM( const Grid_Technique >, diff --git a/source/src_lcao/local_orbital_charge.cpp b/source/src_lcao/local_orbital_charge.cpp index e4b5cd66290..6d44b56936f 100644 --- a/source/src_lcao/local_orbital_charge.cpp +++ b/source/src_lcao/local_orbital_charge.cpp @@ -81,7 +81,9 @@ void Local_Orbital_Charge::allocate_dm_wfc(const Grid_Technique& gt, Local_Orbital_wfc &lowf) { ModuleBase::TITLE("Local_Orbital_Charge", "allocate_dm_wfc"); - if(GlobalV::GAMMA_ONLY_LOCAL) + + this->LOWF = &lowf; + if (GlobalV::GAMMA_ONLY_LOCAL) { // here we reset the density matrix dimension. this->allocate_gamma(gt); @@ -91,8 +93,6 @@ void Local_Orbital_Charge::allocate_dm_wfc(const Grid_Technique& gt, lowf.allocate_k(gt, lowf); this->allocate_DM_k(); } - - this->LOWF = &lowf; return; } diff --git a/source/src_lcao/local_orbital_charge.h b/source/src_lcao/local_orbital_charge.h index 2d7e24720cc..ba236000538 100644 --- a/source/src_lcao/local_orbital_charge.h +++ b/source/src_lcao/local_orbital_charge.h @@ -39,9 +39,6 @@ class Local_Orbital_Charge // in DM_k.cpp //----------------- void allocate_DM_k(void); - - void kpt_file(const Grid_Technique& gt, - Local_Orbital_wfc &lowf); // liaochen modify on 2010-3-23 // change its state from private to public diff --git a/source/src_lcao/local_orbital_wfc.cpp b/source/src_lcao/local_orbital_wfc.cpp index b2b2e96253a..c82cfa4e6a3 100644 --- a/source/src_lcao/local_orbital_wfc.cpp +++ b/source/src_lcao/local_orbital_wfc.cpp @@ -101,28 +101,28 @@ void Local_Orbital_wfc::allocate_k(const Grid_Technique& gt, for(int ik=0; ikwfc_k_grid[ik], ik, lowf); - } + error = WF_Local::read_lowf_complex(this->wfc_k_grid[ik], ik, lowf); #ifdef __MPI - Parallel_Common::bcast_int(error); + Parallel_Common::bcast_int(error); #endif - GlobalV::ofs_running << " Error=" << error << std::endl; - if(error==1) - { - ModuleBase::WARNING_QUIT("Local_Orbital_wfc","Can't find the wave function file: LOWF.dat"); - } - else if(error==2) - { - ModuleBase::WARNING_QUIT("Local_Orbital_wfc","In wave function file, band number doesn't match"); - } - else if(error==3) - { - ModuleBase::WARNING_QUIT("Local_Orbital_wfc","In wave function file, nlocal doesn't match"); - } - else if(error==4) - { - ModuleBase::WARNING_QUIT("Local_Orbital_wfc","In k-dependent wave function file, k point is not correct"); - } + GlobalV::ofs_running << " Error=" << error << std::endl; + if(error==1) + { + ModuleBase::WARNING_QUIT("Local_Orbital_wfc","Can't find the wave function file: LOWF.dat"); + } + else if(error==2) + { + ModuleBase::WARNING_QUIT("Local_Orbital_wfc","In wave function file, band number doesn't match"); + } + else if(error==3) + { + ModuleBase::WARNING_QUIT("Local_Orbital_wfc","In wave function file, nlocal doesn't match"); + } + else if(error==4) + { + ModuleBase::WARNING_QUIT("Local_Orbital_wfc","In k-dependent wave function file, k point is not correct"); + } + } } else { From 0ebe0129cfd4225a1df8f22543993b859428aa3e Mon Sep 17 00:00:00 2001 From: maki49 <1579492865@qq.com> Date: Wed, 9 Mar 2022 16:49:18 +0800 Subject: [PATCH 2/3] add 2d-to-grid function for ienvolope --- source/src_io/istate_envelope.cpp | 68 ++++++++++++++++++++++++--- source/src_io/istate_envelope.h | 4 +- source/src_lcao/LOOP_elec.cpp | 2 +- source/src_lcao/local_orbital_wfc.cpp | 29 ++++++++++++ source/src_lcao/local_orbital_wfc.h | 21 +++++++-- 5 files changed, 111 insertions(+), 13 deletions(-) diff --git a/source/src_io/istate_envelope.cpp b/source/src_io/istate_envelope.cpp index b0d82503d88..1043095f8fe 100644 --- a/source/src_io/istate_envelope.cpp +++ b/source/src_io/istate_envelope.cpp @@ -10,7 +10,7 @@ IState_Envelope::~IState_Envelope() {} -void IState_Envelope::begin(void) +void IState_Envelope::begin(Local_Orbital_wfc &lowf, Gint_Gamma &gg) { ModuleBase::TITLE("IState_Envelope","begin"); @@ -64,7 +64,30 @@ void IState_Envelope::begin(void) } } - for(int ib=0; ib wfc_gamma_grid(GlobalV::NSPIN); + for(int is=0; iscomm_2D, &nprocs); + MPI_Comm_rank(pv->comm_2D, &myid); + + long maxnloc; // maximum number of elements in local matrix + MPI_Reduce(&pv->nloc_wfc, &maxnloc, 1, MPI_LONG, MPI_MAX, 0, pv->comm_2D); + MPI_Bcast(&maxnloc, 1, MPI_LONG, 0, pv->comm_2D); + const int inc = 1; + int naroc[2]; // maximum number of row or column + double* work = new double[maxnloc]; // work/buffer matrix + + for (int ib = 0; ib < GlobalV::NBANDS; ib++) { if(bands_picked[ib]) { @@ -79,9 +102,33 @@ void IState_Envelope::begin(void) // we need to fix this function in near future. // -- mohan add 2021-02-09 //--------------------------------------------------------- - ModuleBase::WARNING_QUIT("IState_Charge::idmatrix","need to update LOWF.WFC_GAMMA"); - - //GlobalC::UHM.GG.cal_env( GlobalC::LOWF.WFC_GAMMA[is][ib], GlobalC::CHR.rho[is] ); + //ModuleBase::WARNING_QUIT("IState_Charge::idmatrix","need to update LOWF.WFC_GAMMA"); + + //convert 2d `wfc_gamma` to grid `wfc_gamma_grid` + int info; + for(int iprow=0; iprowdim0; ++iprow) + { + for(int ipcol=0; ipcoldim1; ++ipcol) + { + const int coord[2]={iprow, ipcol}; + int src_rank; + MPI_Cart_rank(pv->comm_2D, coord, &src_rank); + if(myid==src_rank) + { + BlasConnector::copy(pv->nloc_wfc, lowf.wfc_gamma[is].c, inc, work, inc); + naroc[0]=pv->nrow; + naroc[1]=pv->ncol_bands; + } + info=MPI_Bcast(naroc, 2, MPI_INT, src_rank, pv->comm_2D); + info=MPI_Bcast(work, maxnloc, MPI_DOUBLE, src_rank, pv->comm_2D); + + info=lowf.q2WFC(myid, naroc, pv->nb, + pv->dim0, pv->dim1, iprow, ipcol, pv->loc_size, + work, wfc_gamma_grid[is]); + }//loop ipcol + }//loop iprow + + gg.cal_env( wfc_gamma_grid[is][ib], GlobalC::CHR.rho[is] ); GlobalC::CHR.save_rho_before_sum_band(); //xiaohui add 2014-12-09 @@ -94,8 +141,15 @@ void IState_Envelope::begin(void) } } - delete[] bands_picked; - return; + delete[] work; + delete[] bands_picked; + for(int is=0; isUHM->GG); } else { diff --git a/source/src_lcao/local_orbital_wfc.cpp b/source/src_lcao/local_orbital_wfc.cpp index c82cfa4e6a3..5776f6c7fa1 100644 --- a/source/src_lcao/local_orbital_wfc.cpp +++ b/source/src_lcao/local_orbital_wfc.cpp @@ -172,6 +172,35 @@ int Local_Orbital_wfc::q2CTOT( return 0; } +int Local_Orbital_wfc::q2WFC( + int myid, + int naroc[2], + int nb, + int dim0, + int dim1, + int iprow, + int ipcol, + int loc_size, + double* work, + double** WFC) +{ + ModuleBase::TITLE(" Local_Orbital_wfc","q2WFC"); + for (int j = 0; j < naroc[1]; ++j) + { + int igcol=globalIndex(j, nb, dim1, ipcol); + if(igcol>=GlobalV::NBANDS) continue; + for(int i=0; i= 0 ) + { + WFC[igcol][mu_local]=work[j*naroc[0]+i]; + } + } + } + return 0; +} int Local_Orbital_wfc::q2WFC_complex( int naroc[2], diff --git a/source/src_lcao/local_orbital_wfc.h b/source/src_lcao/local_orbital_wfc.h index d5455d64c8d..8afffe7c9a0 100644 --- a/source/src_lcao/local_orbital_wfc.h +++ b/source/src_lcao/local_orbital_wfc.h @@ -58,7 +58,7 @@ class Local_Orbital_wfc ///========================================= //name will be changed - ///for gamma_only, with output + ///for gamma_only, output total wfc int q2CTOT( int myid, int naroc[2], @@ -70,8 +70,21 @@ class Local_Orbital_wfc int loc_size, double* work, double** CTOT); - - ///for multi-k, no output + + //for gamma_only, 2d-to-grid without output + int q2WFC( + int myid, + int naroc[2], + int nb, + int dim0, + int dim1, + int iprow, + int ipcol, + int loc_size, + double* work, + double** WFC); + + ///for multi-k, 2d-to-grid without output int q2WFC_complex( int naroc[2], int nb, @@ -82,7 +95,7 @@ class Local_Orbital_wfc std::complex* work, std::complex** WFC); - ///for multi-k, with output + ///for multi-k, 2d-to-grid with output int q2WFC_CTOT_complex( int myid, int naroc[2], From bf5e993e44aa16ee858035ce3d8a8cbc94949ff3 Mon Sep 17 00:00:00 2001 From: maki49 <1579492865@qq.com> Date: Wed, 9 Mar 2022 21:17:31 +0800 Subject: [PATCH 3/3] delete useless cout --- source/src_io/wf_local.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/source/src_io/wf_local.cpp b/source/src_io/wf_local.cpp index 353e73d4334..d3e146f78e6 100644 --- a/source/src_io/wf_local.cpp +++ b/source/src_io/wf_local.cpp @@ -544,7 +544,6 @@ void WF_Local::distri_lowf_complex_new(std::complex** ctot, const int& i //} //ofs_running << std::endl; //2.3 copy from work to wfc_k - std::cout << "2.2 ok" << std::endl; const int inc = 1; if(myid==src_rank) {