From 66c4e58318b3cbb73438a90cbca928760dc06b2a Mon Sep 17 00:00:00 2001 From: liiutao <74701833+A-006@users.noreply.github.com> Date: Thu, 10 Oct 2024 12:49:55 +0800 Subject: [PATCH] Refatcor:Use PARAM instead of GlobalV::NBAND,NLocal (#5193) * Modify param nlocal in the hsolver * Modify param nlocal in the io * fix param nlocal bug in the io * fix param nlocal in the ri * fix param nlocal * fix param nlocal in the test file * fix param nbands in the elecstate * fix param nbands in the module_esolver * fix param nbands in the module_hamilt * fix param nbands in the module_hsolver * fix param nbands in the module_io * fix param nbands in the module_ri * fix param nbands * fix param nbands in test file * change the variable file * fix compile error * fix input_conv.cpp compile bug * fix bug in test hasSubstr * fix para in cal_atoms * change device in cpp file * change device in test file * change param.globalv.device_flag * change param.sys.device_flag --- source/module_base/global_variable.cpp | 30 +--- source/module_base/global_variable.h | 44 ------ source/module_base/module_device/device.cpp | 3 +- source/module_base/module_device/device.h | 3 +- source/module_cell/cal_atoms_info.h | 21 ++- .../module_cell/test/unitcell_test_readpp.cpp | 98 +++++++------- source/module_cell/unitcell.cpp | 14 +- source/module_elecstate/elecstate.cpp | 13 +- source/module_elecstate/elecstate_energy.cpp | 4 +- .../module_elecstate/elecstate_lcao_tddft.cpp | 8 +- source/module_elecstate/elecstate_print.cpp | 4 +- source/module_elecstate/elecstate_pw.cpp | 6 +- .../module_elecstate/elecstate_pw_cal_tau.cpp | 2 +- source/module_elecstate/magnetism.cpp | 4 +- .../module_elecstate/module_charge/charge.cpp | 14 +- source/module_elecstate/occupy.cpp | 2 +- source/module_elecstate/potentials/efield.cpp | 2 +- .../module_elecstate/potentials/gatefield.cpp | 4 +- .../potentials/potential_new.cpp | 6 +- source/module_elecstate/test/charge_test.cpp | 8 +- .../test/elecstate_base_test.cpp | 100 +++++++------- .../test/elecstate_energy_test.cpp | 16 +-- .../test/elecstate_magnetism_test.cpp | 2 +- .../test/elecstate_print_test.cpp | 2 +- .../test/elecstate_pw_test.cpp | 12 +- .../test/potential_new_test.cpp | 6 +- source/module_esolver/cal_edm_tddft.cpp | 2 +- source/module_esolver/esolver.cpp | 8 +- source/module_esolver/esolver_fp.cpp | 4 +- source/module_esolver/esolver_ks.cpp | 18 +-- source/module_esolver/esolver_ks_lcao.cpp | 18 +-- .../module_esolver/esolver_ks_lcao_tddft.cpp | 20 +-- source/module_esolver/esolver_ks_lcaopw.cpp | 2 +- source/module_esolver/esolver_ks_pw.cpp | 8 +- source/module_esolver/esolver_of.cpp | 2 +- source/module_esolver/esolver_sdft_pw.cpp | 8 +- source/module_esolver/io_npz.cpp | 5 +- source/module_esolver/lcao_before_scf.cpp | 2 +- source/module_esolver/lcao_nscf.cpp | 2 +- source/module_esolver/lcao_others.cpp | 24 ++-- source/module_esolver/pw_fun.cpp | 2 +- source/module_esolver/pw_init_globalc.cpp | 2 +- source/module_esolver/pw_nscf.cpp | 4 +- .../hamilt_lcaodft/FORCE_gamma.cpp | 10 +- .../hamilt_lcaodft/FORCE_k.cpp | 14 +- .../hamilt_lcaodft/LCAO_init_basis.cpp | 10 +- .../hamilt_lcaodft/fedm_gamma.cpp | 4 +- .../hamilt_lcaodft/fedm_k.cpp | 2 +- .../hamilt_lcaodft/ftvnl_dphi_gamma.cpp | 2 +- .../operator_lcao/op_exx_lcao.hpp | 8 +- .../hamilt_lcaodft/spar_u.cpp | 8 +- .../hamilt_lcaodft/wavefunc_in_pw.cpp | 2 +- .../module_deepks/LCAO_deepks_interface.cpp | 10 +- .../module_deepks/LCAO_deepks_odelta.cpp | 8 +- .../module_deepks/LCAO_deepks_vdelta.cpp | 8 +- .../module_deepks/test/LCAO_deepks_test.cpp | 12 +- .../test/LCAO_deepks_test_prep.cpp | 2 +- .../module_hamilt_lcao/module_dftu/dftu.cpp | 2 +- .../module_dftu/dftu_force.cpp | 30 ++-- .../module_dftu/dftu_hamilt.cpp | 17 +-- .../module_dftu/dftu_occup.cpp | 12 +- .../module_hamilt_lcao/module_gint/gint.cpp | 2 +- .../module_gint/gint_k_sparse1.cpp | 20 +-- .../module_gint/grid_technique.cpp | 12 +- .../hamilt_pwdft/VNL_in_pw.cpp | 16 +-- .../module_hamilt_pw/hamilt_pwdft/elecond.cpp | 2 +- .../module_hamilt_pw/hamilt_pwdft/forces.cpp | 10 +- .../hamilt_pwdft/fs_nonlocal_tools.cpp | 2 +- .../hamilt_pwdft/hamilt_pw.cpp | 2 +- .../hamilt_pwdft/kernels/force_op.h | 5 +- .../hamilt_pwdft/kernels/stress_op.h | 5 +- .../hamilt_pwdft/stress_func_kin.cpp | 3 +- .../hamilt_pwdft/stress_func_mgga.cpp | 11 +- .../hamilt_pwdft/stress_pw.cpp | 2 +- .../hamilt_pwdft/structure_factor.cpp | 4 +- .../hamilt_pwdft/wavefunc.cpp | 32 ++--- .../hamilt_stodft/sto_dos.cpp | 6 +- .../hamilt_stodft/sto_iter.cpp | 43 +++--- .../hamilt_stodft/sto_tool.cpp | 6 +- source/module_hsolver/diago_cusolver.cpp | 7 +- source/module_hsolver/diago_cusolvermp.cpp | 5 +- source/module_hsolver/diago_elpa.cpp | 29 ++-- source/module_hsolver/diago_elpa_native.cpp | 8 +- source/module_hsolver/diago_lapack.cpp | 37 ++--- source/module_hsolver/diago_pexsi.cpp | 2 +- source/module_hsolver/diago_scalapack.cpp | 37 ++--- source/module_hsolver/hsolver.cpp | 3 +- source/module_hsolver/hsolver_pw.cpp | 2 +- .../module_pexsi/pexsi_solver.cpp | 5 +- .../module_hsolver/test/diago_lapack_test.cpp | 7 +- .../test/diago_lcao_cusolver_test.cpp | 7 +- .../module_hsolver/test/diago_lcao_test.cpp | 7 +- .../module_hsolver/test/diago_pexsi_test.cpp | 6 +- .../module_hsolver/test/test_hsolver_pw.cpp | 8 +- .../module_hsolver/test/test_hsolver_sdft.cpp | 6 +- source/module_io/berryphase.cpp | 4 +- source/module_io/cal_r_overlap_R.cpp | 28 ++-- source/module_io/cal_test.cpp | 23 ++-- source/module_io/get_wf_lcao.cpp | 3 +- source/module_io/input_conv.cpp | 16 +-- source/module_io/json_output/init_info.cpp | 5 +- .../json_output/test/para_json_test.cpp | 2 +- source/module_io/nscf_fermi_surf.cpp | 3 +- source/module_io/numerical_basis.cpp | 18 +-- source/module_io/numerical_descriptor.cpp | 7 +- source/module_io/print_info.cpp | 2 +- source/module_io/read_input_item_system.cpp | 5 + source/module_io/read_set_globalv.cpp | 24 +--- source/module_io/read_wfc_pw.cpp | 6 +- source/module_io/read_wfc_to_rho.cpp | 2 +- source/module_io/single_R_io.cpp | 13 +- source/module_io/test/read_wfc_pw_test.cpp | 27 ++-- .../module_io/test/read_wfc_to_rho_test.cpp | 4 +- source/module_io/test/single_R_io_test.cpp | 7 +- source/module_io/test/write_dos_pw_test.cpp | 4 +- .../module_io/test/write_istate_info_test.cpp | 12 +- source/module_io/test/write_orb_info_test.cpp | 2 +- source/module_io/test/write_wfc_nao_test.cpp | 24 ++-- source/module_io/test_serial/CMakeLists.txt | 4 +- source/module_io/to_wannier90.cpp | 14 +- source/module_io/to_wannier90_lcao.cpp | 24 ++-- source/module_io/to_wannier90_lcao_in_pw.cpp | 14 +- source/module_io/unk_overlap_lcao.cpp | 44 +++--- source/module_io/winput.cpp | 4 +- source/module_io/write_HS.hpp | 10 +- source/module_io/write_HS_sparse.cpp | 31 +++-- source/module_io/write_dos_lcao.cpp | 60 ++++---- source/module_io/write_dos_pw.cpp | 4 +- source/module_io/write_istate_info.cpp | 4 +- source/module_io/write_proj_band_lcao.cpp | 66 ++++----- source/module_io/write_wfc_pw.cpp | 6 +- source/module_lr/esolver_lrtd_lcao.cpp | 6 +- source/module_lr/hsolver_lrtd.cpp | 2 +- source/module_parameter/input_parameter.h | 2 +- source/module_parameter/system_parameter.h | 4 +- source/module_psi/psi_initializer.cpp | 18 +-- .../test/psi_initializer_unit_test.cpp | 2 +- source/module_ri/RPA_LRI.hpp | 20 +-- source/module_ri/exx_lip.cpp | 128 +++++++++--------- .../module_exx_symmetry/symmetry_rotation.cpp | 2 +- 140 files changed, 867 insertions(+), 922 deletions(-) diff --git a/source/module_base/global_variable.cpp b/source/module_base/global_variable.cpp index 4d8301f2a1..616e8c3656 100644 --- a/source/module_base/global_variable.cpp +++ b/source/module_base/global_variable.cpp @@ -12,24 +12,6 @@ #include namespace GlobalV { - -//---------------------------------------------------------- -// EXPLAIN : Basic Global Variables -// In practice calculation, these values are set in -// input.cpp. -//---------------------------------------------------------- -int NBANDS = 0; -int NLOCAL = 0; // total number of local basis. - -double nupdown = 0.0; - -bool use_uspp = false; -std::string KS_SOLVER = "cg"; // xiaohui add 2013-09-01 -double SEARCH_RADIUS = -1.0; - -int NB2D = 1; - - //---------------------------------------------------------- // EXPLAIN : Parallel information //---------------------------------------------------------- @@ -52,21 +34,11 @@ int GRANK = MY_RANK; int GSIZE = DSIZE; //---------------------------------------------------------- -// EXPLAIN : The input file name and directory +// EXPLAIN : ofstream for output //---------------------------------------------------------- std::ofstream ofs_running; std::ofstream ofs_warning; std::ofstream ofs_info; // output math lib info std::ofstream ofs_device; // output device info - -//========================================================== -// device flags added by denghui -//========================================================== -std::string device_flag = "unknown"; - -double nelec = 0; - - -// on-site orbitals } // namespace GlobalV diff --git a/source/module_base/global_variable.h b/source/module_base/global_variable.h index 2405e81ab3..9063298947 100644 --- a/source/module_base/global_variable.h +++ b/source/module_base/global_variable.h @@ -13,25 +13,6 @@ namespace GlobalV { -//========================================================== -// EXPLAIN : Basic Global Variables -//========================================================== - -extern int NBANDS; -extern int NLOCAL; // 1.1 // mohan add 2009-05-29 - -extern double nupdown; -extern bool use_uspp; - -extern std::string KS_SOLVER; // xiaohui add 2013-09-01 -extern double SEARCH_RADIUS; // 11.1 // mohan add 2011-03-10 - - -extern int NB2D; // 16.5 dividsion of 2D_matrix. - - // pw, 2: real drho for lcao - - //======================================================================== // EXPLAIN : Parallel information // GLOBAL VARIABLES : @@ -84,30 +65,5 @@ extern std::ofstream ofs_running; extern std::ofstream ofs_warning; extern std::ofstream ofs_info; extern std::ofstream ofs_device; - - -// mixing parameters - -//========================================================== -// device flags added by denghui -//========================================================== -extern std::string device_flag; -//========================================================== -// precision flags added by denghui -//========================================================== - - // "out_chg" elec step. -/// @brief method to initialize wavefunction -/// @author kirk0830, 20230920 -/// @brief whether use the new psi initializer to initialize psi -/// @author ykhuang, 20230920 - -extern double nelec; - -// Deltaspin related - -// Quasiatomic orbital related - -// radius of on-site orbitals } // namespace GlobalV #endif diff --git a/source/module_base/module_device/device.cpp b/source/module_base/module_device/device.cpp index 4b739fd7a3..4897ef1e8a 100644 --- a/source/module_base/module_device/device.cpp +++ b/source/module_base/module_device/device.cpp @@ -148,13 +148,12 @@ int set_device_by_rank(const MPI_Comm mpi_comm) { #endif std::string get_device_flag(const std::string &device, - const std::string &ks_solver, const std::string &basis_type) { if (device == "cpu") { return "cpu"; // no extra checks required } std::string error_message; -if (device != "" and device != "gpu") +if (device != "auto" and device != "gpu") { error_message += "Parameter \"device\" can only be set to \"cpu\" or \"gpu\"!"; ModuleBase::WARNING_QUIT("device", error_message); diff --git a/source/module_base/module_device/device.h b/source/module_base/module_device/device.h index d0ed332555..6be4952f14 100644 --- a/source/module_base/module_device/device.h +++ b/source/module_base/module_device/device.h @@ -44,10 +44,9 @@ int get_device_kpar(const int& kpar); /** * @brief Get the device flag object - * for module_io PARAM.globalv.device_flag + * for module_io PARAM.inp.device */ std::string get_device_flag(const std::string& device, - const std::string& ks_solver, const std::string& basis_type); #if __MPI diff --git a/source/module_cell/cal_atoms_info.h b/source/module_cell/cal_atoms_info.h index 92789eb1ee..c4aa70fb3a 100644 --- a/source/module_cell/cal_atoms_info.h +++ b/source/module_cell/cal_atoms_info.h @@ -24,10 +24,10 @@ class CalAtomsInfo { for (int ia = 0; ia < atoms[it].na; ++ia) { - GlobalV::nupdown += atoms[it].mag[ia]; + para.input.nupdown += atoms[it].mag[ia]; } } - GlobalV::ofs_running << " The readin total magnetization is " << GlobalV::nupdown << std::endl; + GlobalV::ofs_running << " The readin total magnetization is " << para.inp.nupdown << std::endl; } if (!para.inp.use_paw) @@ -37,38 +37,37 @@ class CalAtomsInfo { if (atoms[it].ncpp.tvanp) { - GlobalV::use_uspp = true; + para.sys.use_uspp = true; } } // calculate the total number of local basis - GlobalV::NLOCAL = 0; + para.sys.nlocal = 0; for (int it = 0; it < ntype; ++it) { const int nlocal_it = atoms[it].nw * atoms[it].na; if (para.inp.nspin != 4) { - GlobalV::NLOCAL += nlocal_it; + para.sys.nlocal += nlocal_it; } else { - GlobalV::NLOCAL += nlocal_it * 2; // zhengdy-soc + para.sys.nlocal += nlocal_it * 2; // zhengdy-soc } } } // calculate the total number of electrons - cal_nelec(atoms, ntype, GlobalV::nelec); + cal_nelec(atoms, ntype, para.input.nelec); // autoset and check GlobalV::NBANDS std::vector nelec_spin(2, 0.0); if (para.inp.nspin == 2) { - nelec_spin[0] = (GlobalV::nelec + GlobalV::nupdown) / 2.0; - nelec_spin[1] = (GlobalV::nelec - GlobalV::nupdown) / 2.0; + nelec_spin[0] = (para.inp.nelec + para.inp.nupdown ) / 2.0; + nelec_spin[1] = (para.inp.nelec - para.inp.nupdown ) / 2.0; } - cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS); - + cal_nbands(para.inp.nelec, para.sys.nlocal, nelec_spin, para.input.nbands); return; } }; diff --git a/source/module_cell/test/unitcell_test_readpp.cpp b/source/module_cell/test/unitcell_test_readpp.cpp index f643db848b..34e5c71b3b 100644 --- a/source/module_cell/test/unitcell_test_readpp.cpp +++ b/source/module_cell/test/unitcell_test_readpp.cpp @@ -71,7 +71,7 @@ Magnetism::~Magnetism() { delete[] this->start_magnetization; } * - cal_nwfc(): calcuate the total number of local basis: NSPIN != 4 * - this corresponds to number_of_proj, PP_BETA in pp file, and * atoms[it].l_nchi[nw], nw from orb file - * - setup GlobalV::NLOCAL + * - setup PARAM.sys.nlocal * - interfaces initialed in this function: * - itia2iat * - iat2iwt @@ -120,11 +120,11 @@ class UcellTest : public ::testing::Test { PARAM.input.test_pseudo_cell = true; PARAM.input.nspin = 1; PARAM.input.basis_type = "pw"; - GlobalV::nelec = 10.0; - GlobalV::nupdown = 0.0; + PARAM.input.nelec = 10.0; + PARAM.input.nupdown = 0.0; PARAM.sys.two_fermi = false; - GlobalV::NBANDS = 6; - GlobalV::NLOCAL = 6; + PARAM.input.nbands = 6; + PARAM.sys.nlocal = 6; PARAM.input.lspinorb = false; } void TearDown() { ofs.close(); } @@ -265,7 +265,7 @@ TEST_F(UcellTest, CalNwfc1) { ucell->read_cell_pseudopots(pp_dir, ofs); EXPECT_FALSE(ucell->atoms[0].ncpp.has_so); EXPECT_FALSE(ucell->atoms[1].ncpp.has_so); - GlobalV::NLOCAL = 3 * 9; + PARAM.sys.nlocal = 3 * 9; ucell->cal_nwfc(ofs); EXPECT_EQ(ucell->atoms[0].iw2l[8], 2); EXPECT_EQ(ucell->atoms[0].iw2n[8], 0); @@ -331,7 +331,7 @@ TEST_F(UcellTest, CalNwfc2) { ucell->read_cell_pseudopots(pp_dir, ofs); EXPECT_FALSE(ucell->atoms[0].ncpp.has_so); EXPECT_FALSE(ucell->atoms[1].ncpp.has_so); - GlobalV::NLOCAL = 3 * 9 * 2; + PARAM.sys.nlocal = 3 * 9 * 2; EXPECT_NO_THROW(ucell->cal_nwfc(ofs)); } @@ -412,58 +412,58 @@ TEST_F(UcellTest, CalNelec) { TEST_F(UcellTest, CalNbands) { std::vector nelec_spin(2, 5.0); - cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS); - EXPECT_EQ(GlobalV::NBANDS, 6); + cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands); + EXPECT_EQ(PARAM.input.nbands, 6); } TEST_F(UcellTest, CalNbandsFractionElec) { - GlobalV::nelec = 9.5; + PARAM.input.nelec = 9.5; std::vector nelec_spin(2, 5.0); - cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS); - EXPECT_EQ(GlobalV::NBANDS, 6); + cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands); + EXPECT_EQ(PARAM.input.nbands, 6); } TEST_F(UcellTest, CalNbandsSOC) { PARAM.input.lspinorb = true; - GlobalV::NBANDS = 0; + PARAM.input.nbands = 0; std::vector nelec_spin(2, 5.0); - cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS); - EXPECT_EQ(GlobalV::NBANDS, 20); + cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands); + EXPECT_EQ(PARAM.input.nbands, 20); } TEST_F(UcellTest, CalNbandsSDFT) { PARAM.input.esolver_type = "sdft"; std::vector nelec_spin(2, 5.0); - EXPECT_NO_THROW(cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS)); + EXPECT_NO_THROW(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands)); } TEST_F(UcellTest, CalNbandsLCAO) { PARAM.input.basis_type = "lcao"; std::vector nelec_spin(2, 5.0); - EXPECT_NO_THROW(cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS)); + EXPECT_NO_THROW(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands)); } TEST_F(UcellTest, CalNbandsLCAOINPW) { PARAM.input.basis_type = "lcao_in_pw"; - GlobalV::NLOCAL = GlobalV::NBANDS - 1; + PARAM.sys.nlocal = PARAM.input.nbands - 1; std::vector nelec_spin(2, 5.0); testing::internal::CaptureStdout(); - EXPECT_EXIT(cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS), ::testing::ExitedWithCode(0), ""); + EXPECT_EXIT(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(0), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("NLOCAL < NBANDS")); } TEST_F(UcellTest, CalNbandsWarning1) { - GlobalV::NBANDS = GlobalV::nelec / 2 - 1; + PARAM.input.nbands = PARAM.input.nelec / 2 - 1; std::vector nelec_spin(2, 5.0); testing::internal::CaptureStdout(); - EXPECT_EXIT(cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS), ::testing::ExitedWithCode(0), ""); + EXPECT_EXIT(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(0), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("Too few bands!")); } @@ -471,12 +471,12 @@ TEST_F(UcellTest, CalNbandsWarning1) TEST_F(UcellTest, CalNbandsWarning2) { PARAM.input.nspin = 2; - GlobalV::nupdown = 4.0; + PARAM.input.nupdown = 4.0; std::vector nelec_spin(2); - nelec_spin[0] = (GlobalV::nelec + GlobalV::nupdown) / 2.0; - nelec_spin[1] = (GlobalV::nelec - GlobalV::nupdown) / 2.0; + nelec_spin[0] = (PARAM.input.nelec + PARAM.input.nupdown ) / 2.0; + nelec_spin[1] = (PARAM.input.nelec - PARAM.input.nupdown ) / 2.0; testing::internal::CaptureStdout(); - EXPECT_EXIT(cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS), ::testing::ExitedWithCode(0), ""); + EXPECT_EXIT(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(0), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("Too few spin up bands!")); } @@ -484,12 +484,12 @@ TEST_F(UcellTest, CalNbandsWarning2) TEST_F(UcellTest, CalNbandsWarning3) { PARAM.input.nspin = 2; - GlobalV::nupdown = -4.0; + PARAM.input.nupdown = -4.0; std::vector nelec_spin(2); - nelec_spin[0] = (GlobalV::nelec + GlobalV::nupdown) / 2.0; - nelec_spin[1] = (GlobalV::nelec - GlobalV::nupdown) / 2.0; + nelec_spin[0] = (PARAM.input.nelec + PARAM.input.nupdown ) / 2.0; + nelec_spin[1] = (PARAM.input.nelec - PARAM.input.nupdown ) / 2.0; testing::internal::CaptureStdout(); - EXPECT_EXIT(cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS), ::testing::ExitedWithCode(0), ""); + EXPECT_EXIT(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(0), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("Too few spin down bands!")); } @@ -497,67 +497,67 @@ TEST_F(UcellTest, CalNbandsWarning3) TEST_F(UcellTest, CalNbandsSpin1) { PARAM.input.nspin = 1; - GlobalV::NBANDS = 0; + PARAM.input.nbands = 0; std::vector nelec_spin(2, 5.0); - cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS); - EXPECT_EQ(GlobalV::NBANDS, 15); + cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands); + EXPECT_EQ(PARAM.input.nbands, 15); } TEST_F(UcellTest, CalNbandsSpin1LCAO) { PARAM.input.nspin = 1; - GlobalV::NBANDS = 0; + PARAM.input.nbands = 0; PARAM.input.basis_type = "lcao"; std::vector nelec_spin(2, 5.0); - cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS); - EXPECT_EQ(GlobalV::NBANDS, 6); + cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands); + EXPECT_EQ(PARAM.input.nbands, 6); } TEST_F(UcellTest, CalNbandsSpin4) { PARAM.input.nspin = 4; - GlobalV::NBANDS = 0; + PARAM.input.nbands = 0; std::vector nelec_spin(2, 5.0); - cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS); - EXPECT_EQ(GlobalV::NBANDS, 30); + cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands); + EXPECT_EQ(PARAM.input.nbands, 30); } TEST_F(UcellTest, CalNbandsSpin4LCAO) { PARAM.input.nspin = 4; - GlobalV::NBANDS = 0; + PARAM.input.nbands = 0; PARAM.input.basis_type = "lcao"; std::vector nelec_spin(2, 5.0); - cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS); - EXPECT_EQ(GlobalV::NBANDS, 6); + cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands); + EXPECT_EQ(PARAM.input.nbands, 6); } TEST_F(UcellTest, CalNbandsSpin2) { PARAM.input.nspin = 2; - GlobalV::NBANDS = 0; + PARAM.input.nbands = 0; std::vector nelec_spin(2, 5.0); - cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS); - EXPECT_EQ(GlobalV::NBANDS, 16); + cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands); + EXPECT_EQ(PARAM.input.nbands, 16); } TEST_F(UcellTest, CalNbandsSpin2LCAO) { PARAM.input.nspin = 2; - GlobalV::NBANDS = 0; + PARAM.input.nbands = 0; PARAM.input.basis_type = "lcao"; std::vector nelec_spin(2, 5.0); - cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS); - EXPECT_EQ(GlobalV::NBANDS, 6); + cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands); + EXPECT_EQ(PARAM.input.nbands, 6); } TEST_F(UcellTest, CalNbandsGaussWarning) { - GlobalV::NBANDS = 5; + PARAM.input.nbands = 5; std::vector nelec_spin(2, 5.0); PARAM.input.smearing_method = "gaussian"; testing::internal::CaptureStdout(); - EXPECT_EXIT(cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS), ::testing::ExitedWithCode(0), ""); + EXPECT_EXIT(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(0), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("for smearing, num. of bands > num. of occupied bands")); } diff --git a/source/module_cell/unitcell.cpp b/source/module_cell/unitcell.cpp index 4b90c06d9c..c68ab86009 100755 --- a/source/module_cell/unitcell.cpp +++ b/source/module_cell/unitcell.cpp @@ -830,7 +830,7 @@ void UnitCell::read_pseudo(std::ofstream& ofs) { CalAtomsInfo ca; ca.cal_atoms_info(this->atoms, this->ntype, PARAM); - // setup GlobalV::NLOCAL + // setup PARAM.globalv.nlocal cal_nwfc(ofs); // Check whether the number of valence is minimum @@ -910,7 +910,7 @@ void UnitCell::read_pseudo(std::ofstream& ofs) { // calculate the total number of local basis // Target : nwfc, lmax, // atoms[].stapos_wf -// GlobalV::NBANDS +// PARAM.inp.nbands //=========================================== void UnitCell::cal_nwfc(std::ofstream& log) { ModuleBase::TITLE("UnitCell", "cal_nwfc"); @@ -957,7 +957,7 @@ void UnitCell::cal_nwfc(std::ofstream& log) { //orbitals",atoms[it].stapos_wf); } - // OUT(GlobalV::ofs_running,"NLOCAL",GlobalV::NLOCAL); + // OUT(GlobalV::ofs_running,"NLOCAL",PARAM.globalv.nlocal); log << " " << std::setw(40) << "NLOCAL" << " = " << nlocal_tmp << std::endl; //======================================================== @@ -966,7 +966,7 @@ void UnitCell::cal_nwfc(std::ofstream& log) { // mohan add 2010-09-26 assert(nlocal_tmp > 0); - assert(nlocal_tmp == GlobalV::NLOCAL); + assert(nlocal_tmp == PARAM.globalv.nlocal); delete[] iwt2iat; delete[] iwt2iw; this->iwt2iat = new int[nlocal_tmp]; @@ -1042,14 +1042,14 @@ void UnitCell::cal_nwfc(std::ofstream& log) { && (PARAM.inp.init_wfc.substr(0, 3) == "nao") && (PARAM.inp.esolver_type == "ksdft"))) // xiaohui add 2013-09-02 { - ModuleBase::GlobalFunc::AUTO_SET("NBANDS", GlobalV::NBANDS); + ModuleBase::GlobalFunc::AUTO_SET("NBANDS", PARAM.inp.nbands); } else // plane wave basis { // if(winput::after_iter && winput::sph_proj) //{ - // if(GlobalV::NBANDS < GlobalV::NLOCAL) + // if(PARAM.inp.nbands < PARAM.globalv.nlocal) // { - // ModuleBase::WARNING_QUIT("cal_nwfc","NBANDS must > GlobalV::NLOCAL + // ModuleBase::WARNING_QUIT("cal_nwfc","NBANDS must > PARAM.globalv.nlocal //!"); // } // } diff --git a/source/module_elecstate/elecstate.cpp b/source/module_elecstate/elecstate.cpp index 6d77e815a6..8b0eac8afd 100644 --- a/source/module_elecstate/elecstate.cpp +++ b/source/module_elecstate/elecstate.cpp @@ -61,9 +61,8 @@ void ElecState::init_nelec_spin() this->nelec_spin.resize(PARAM.inp.nspin); if (PARAM.inp.nspin == 2) { - // in fact, when TWO_EFERMI(nupdown in INPUT is not 0.0), nelec_spin will be fixed. - this->nelec_spin[0] = (GlobalV::nelec + GlobalV::nupdown) / 2.0; - this->nelec_spin[1] = (GlobalV::nelec - GlobalV::nupdown) / 2.0; + this->nelec_spin[0] = (PARAM.inp.nelec + PARAM.inp.nupdown) / 2.0; + this->nelec_spin[1] = (PARAM.inp.nelec - PARAM.inp.nupdown) / 2.0; } } @@ -108,7 +107,7 @@ void ElecState::calculate_weights() Occupy::iweights(nks, this->klist->wk, nbands, - GlobalV::nelec, + PARAM.inp.nelec, this->ekb, this->eferm.ef, this->wg, @@ -154,7 +153,7 @@ void ElecState::calculate_weights() Occupy::gweights(nks, this->klist->wk, nbands, - GlobalV::nelec, + PARAM.inp.nelec, Occupy::gaussian_parameter, Occupy::gaussian_type, this->ekb, @@ -249,8 +248,8 @@ void ElecState::init_ks(Charge* chg_in, // pointer for class Charge // init nelec_spin with nelec and nupdown this->init_nelec_spin(); // initialize ekb and wg - this->ekb.create(nk_in, GlobalV::NBANDS); - this->wg.create(nk_in, GlobalV::NBANDS); + this->ekb.create(nk_in, PARAM.inp.nbands); + this->wg.create(nk_in, PARAM.inp.nbands); } void set_is_occupied(std::vector& is_occupied, diff --git a/source/module_elecstate/elecstate_energy.cpp b/source/module_elecstate/elecstate_energy.cpp index f29e986822..86a02d7364 100644 --- a/source/module_elecstate/elecstate_energy.cpp +++ b/source/module_elecstate/elecstate_energy.cpp @@ -20,7 +20,7 @@ void ElecState::cal_bandgap() this->bandgap = 0.0; return; } - int nbands = GlobalV::NBANDS; + int nbands = PARAM.inp.nbands; int nks = this->klist->get_nks(); double homo = this->ekb(0, 0); double lumo = this->ekb(0, nbands - 1); @@ -51,7 +51,7 @@ void ElecState::cal_bandgap_updw() this->bandgap_dw = 0.0; return; } - int nbands = GlobalV::NBANDS; + int nbands = PARAM.inp.nbands; int nks = this->klist->get_nks(); double homo_up = this->ekb(0, 0); double lumo_up = this->ekb(0, nbands - 1); diff --git a/source/module_elecstate/elecstate_lcao_tddft.cpp b/source/module_elecstate/elecstate_lcao_tddft.cpp index 48ce026e1f..af79ad6793 100644 --- a/source/module_elecstate/elecstate_lcao_tddft.cpp +++ b/source/module_elecstate/elecstate_lcao_tddft.cpp @@ -57,7 +57,7 @@ void ElecStateLCAO_TDDFT::calculate_weights_td() if (PARAM.inp.ocp == 1) { int num = 0; - num = this->klist->get_nks() * GlobalV::NBANDS; + num = this->klist->get_nks() * PARAM.inp.nbands; if (num != PARAM.inp.ocp_kb.size()) { ModuleBase::WARNING_QUIT("ElecStateLCAO_TDDFT::calculate_weights_td", @@ -69,7 +69,7 @@ void ElecStateLCAO_TDDFT::calculate_weights_td() { num_elec += PARAM.inp.ocp_kb[i]; } - if (std::abs(num_elec - GlobalV::nelec) > 1.0e-5) + if (std::abs(num_elec - PARAM.inp.nelec) > 1.0e-5) { ModuleBase::WARNING_QUIT("ElecStateLCAO_TDDFT::calculate_weights_td", "total number of occupations is wrong , please check ocp_set"); @@ -77,9 +77,9 @@ void ElecStateLCAO_TDDFT::calculate_weights_td() for (int ik = 0; ik < this->klist->get_nks(); ik++) { - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { - this->wg(ik, ib) = PARAM.inp.ocp_kb[ik * GlobalV::NBANDS + ib]; + this->wg(ik, ib) = PARAM.inp.ocp_kb[ik * PARAM.inp.nbands + ib]; } } } diff --git a/source/module_elecstate/elecstate_print.cpp b/source/module_elecstate/elecstate_print.cpp index ab4fa47c4d..2d738345b3 100644 --- a/source/module_elecstate/elecstate_print.cpp +++ b/source/module_elecstate/elecstate_print.cpp @@ -245,7 +245,7 @@ void ElecState::print_band(const int& ik, const int& printe, const int& iter) { // check the band energy. bool wrong = false; - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) + for (int ib = 0; ib < PARAM.inp.nbands; ++ib) { if (std::abs(this->ekb(ik, ib)) > 1.0e10) { @@ -267,7 +267,7 @@ void ElecState::print_band(const int& ik, const int& printe, const int& iter) GlobalV::ofs_running << " Energy (eV) & Occupations for spin=" << this->klist->isk[ik] + 1 << " K-point=" << ik + 1 << std::endl; GlobalV::ofs_running << std::setiosflags(std::ios::showpoint); - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { GlobalV::ofs_running << " " << std::setw(6) << ib + 1 << std::setw(15) << this->ekb(ik, ib) * ModuleBase::Ry_to_eV; diff --git a/source/module_elecstate/elecstate_pw.cpp b/source/module_elecstate/elecstate_pw.cpp index 24d87f5a8f..aebde68a08 100644 --- a/source/module_elecstate/elecstate_pw.cpp +++ b/source/module_elecstate/elecstate_pw.cpp @@ -47,7 +47,7 @@ ElecStatePW::~ElecStatePW() template void ElecStatePW::init_rho_data() { - if (PARAM.globalv.device_flag == "gpu" || PARAM.inp.precision == "single") { + if (PARAM.inp.device == "gpu" || PARAM.inp.precision == "single") { this->rho = new Real*[this->charge->nspin]; resmem_var_op()(this->ctx, this->rho_data, this->charge->nspin * this->charge->nrxx); for (int ii = 0; ii < this->charge->nspin; ii++) { @@ -104,11 +104,11 @@ void ElecStatePW::psiToRho(const psi::Psi& psi) psi.fix_k(ik); this->updateRhoK(psi); } - if (GlobalV::use_uspp) + if (PARAM.globalv.use_uspp) { this->add_usrho(psi); } - if (PARAM.globalv.device_flag == "gpu" || PARAM.inp.precision == "single") { + if (PARAM.inp.device == "gpu" || PARAM.inp.precision == "single") { for (int ii = 0; ii < PARAM.inp.nspin; ii++) { castmem_var_d2h_op()(cpu_ctx, this->ctx, this->charge->rho[ii], this->rho[ii], this->charge->nrxx); if (get_xc_func_type() == 3) diff --git a/source/module_elecstate/elecstate_pw_cal_tau.cpp b/source/module_elecstate/elecstate_pw_cal_tau.cpp index a354fda48b..0662bb4425 100644 --- a/source/module_elecstate/elecstate_pw_cal_tau.cpp +++ b/source/module_elecstate/elecstate_pw_cal_tau.cpp @@ -50,7 +50,7 @@ void ElecStatePW::cal_tau(const psi::Psi& psi) } } } - if (GlobalV::device_flag == "gpu" || PARAM.inp.precision == "single") { + if (PARAM.inp.device == "gpu" || PARAM.inp.precision == "single") { for (int ii = 0; ii < PARAM.inp.nspin; ii++) { castmem_var_d2h_op()(cpu_ctx, this->ctx, this->charge->kin_r[ii], this->kin_r[ii], this->charge->nrxx); } diff --git a/source/module_elecstate/magnetism.cpp b/source/module_elecstate/magnetism.cpp index ee574de604..89bf71eb38 100644 --- a/source/module_elecstate/magnetism.cpp +++ b/source/module_elecstate/magnetism.cpp @@ -42,8 +42,8 @@ void Magnetism::compute_magnetization(const int& nrxx, const int& nxyz, const do //if TWO_EFERMI, no need to update if(!PARAM.globalv.two_fermi) { - nelec_spin[0] = (GlobalV::nelec + this->tot_magnetization) / 2; - nelec_spin[1] = (GlobalV::nelec - this->tot_magnetization) / 2; + nelec_spin[0] = (PARAM.inp.nelec + this->tot_magnetization) / 2; + nelec_spin[1] = (PARAM.inp.nelec - this->tot_magnetization) / 2; ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"nelec for spin up", nelec_spin[0]); ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"nelec for spin down", nelec_spin[1]); } diff --git a/source/module_elecstate/module_charge/charge.cpp b/source/module_elecstate/module_charge/charge.cpp index 51c60b8ca7..9003844ca1 100644 --- a/source/module_elecstate/module_charge/charge.cpp +++ b/source/module_elecstate/module_charge/charge.cpp @@ -242,7 +242,7 @@ void Charge::renormalize_rho() const double sr = this->sum_rho(); GlobalV::ofs_warning << std::setprecision(15); ModuleBase::GlobalFunc::OUT(GlobalV::ofs_warning, "charge before normalized", sr); - const double normalize_factor = GlobalV::nelec / sr; + const double normalize_factor = PARAM.inp.nelec / sr; for (int is = 0; is < nspin; is++) { @@ -299,10 +299,10 @@ void Charge::atomic_rho(const int spin_number_need, ne_tot += ne[is]; } ModuleBase::GlobalFunc::OUT(GlobalV::ofs_warning, "total electron number from rho", ne_tot); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_warning, "should be", GlobalV::nelec); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_warning, "should be", PARAM.inp.nelec); for (int is = 0; is < spin_number_need; ++is) { for (int ir = 0; ir < this->rhopw->nrxx; ++ir) { - rho_in[is][ir] = rho_in[is][ir] / ne_tot * GlobalV::nelec; + rho_in[is][ir] = rho_in[is][ir] / ne_tot * PARAM.inp.nelec; } } @@ -683,10 +683,10 @@ void Charge::atomic_rho(const int spin_number_need, ne_tot += ne[is]; } ModuleBase::GlobalFunc::OUT(GlobalV::ofs_warning, "total electron number from rho", ne_tot); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_warning, "should be", GlobalV::nelec); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_warning, "should be", PARAM.inp.nelec); for (int is = 0; is < spin_number_need; ++is) { for (int ir = 0; ir < this->rhopw->nrxx; ++ir) { - rho_in[is][ir] = rho_in[is][ir] / ne_tot * GlobalV::nelec; + rho_in[is][ir] = rho_in[is][ir] / ne_tot * PARAM.inp.nelec; } } } @@ -733,7 +733,7 @@ void Charge::check_rho() { double ne = 0.0; ne = this->cal_rho2ne(rho[0]); - if (std::abs(ne - GlobalV::nelec) > 1.0e-6) + if (std::abs(ne - PARAM.inp.nelec) > 1.0e-6) { ModuleBase::WARNING("Charge", "Charge is not equal to the number of electrons!"); } @@ -755,7 +755,7 @@ void Charge::check_rho() ModuleBase::WARNING_QUIT("Charge", "Number of spin-up electrons set in starting magnetization exceeds all available."); } // for total charge - if (std::abs(ne_up + ne_dn - GlobalV::nelec) > 1.0e-6) + if (std::abs(ne_up + ne_dn - PARAM.inp.nelec) > 1.0e-6) { ModuleBase::WARNING("Charge", "Charge is not equal to the number of electrons!"); } diff --git a/source/module_elecstate/occupy.cpp b/source/module_elecstate/occupy.cpp index 508b72f261..c4cc61213d 100644 --- a/source/module_elecstate/occupy.cpp +++ b/source/module_elecstate/occupy.cpp @@ -228,7 +228,7 @@ void Occupy::gweights(const int nks, if (is != -1 && is != isk[ik]) continue; - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { //================================ // Calculate the gaussian weights diff --git a/source/module_elecstate/potentials/efield.cpp b/source/module_elecstate/potentials/efield.cpp index d45cca67ce..0297015095 100644 --- a/source/module_elecstate/potentials/efield.cpp +++ b/source/module_elecstate/potentials/efield.cpp @@ -159,7 +159,7 @@ double Efield::cal_ion_dipole(const UnitCell &cell, const double &bmod) { ion_charge += cell.atoms[it].na * cell.atoms[it].ncpp.zv; } - ion_dipole += (GlobalV::nelec - ion_charge) * saw_function(efield_pos_max, efield_pos_dec, Gatefield::zgate); + ion_dipole += (PARAM.inp.nelec - ion_charge) * saw_function(efield_pos_max, efield_pos_dec, Gatefield::zgate); } ion_dipole *= cell.lat0 / bmod * ModuleBase::FOUR_PI / cell.omega; diff --git a/source/module_elecstate/potentials/gatefield.cpp b/source/module_elecstate/potentials/gatefield.cpp index 3dd6eaa012..3a59f54632 100644 --- a/source/module_elecstate/potentials/gatefield.cpp +++ b/source/module_elecstate/potentials/gatefield.cpp @@ -37,7 +37,7 @@ void Gatefield::add_gatefield(double *vltot, { ion_charge += cell.atoms[it].na * cell.atoms[it].ncpp.zv; } - rho_surface = -(GlobalV::nelec - ion_charge) / area * ModuleBase::TWO_PI; + rho_surface = -(PARAM.inp.nelec - ion_charge) / area * ModuleBase::TWO_PI; double block_size = block_up - block_down; @@ -56,7 +56,7 @@ void Gatefield::add_gatefield(double *vltot, } } etotgatefield - = -ModuleBase::e2 * rho_surface * cell.lat0 / Efield::bmod * (factor + (GlobalV::nelec - ion_charge) / 12.0); + = -ModuleBase::e2 * rho_surface * cell.lat0 / Efield::bmod * (factor + (PARAM.inp.nelec - ion_charge) / 12.0); GlobalV::ofs_running << "\n\n Adding charged plate to compensate the charge of the system" << std::endl; ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "prefactor of the potential (Ry a.u.)", rho_surface); diff --git a/source/module_elecstate/potentials/potential_new.cpp b/source/module_elecstate/potentials/potential_new.cpp index acf402425f..e90d080fd4 100644 --- a/source/module_elecstate/potentials/potential_new.cpp +++ b/source/module_elecstate/potentials/potential_new.cpp @@ -46,7 +46,7 @@ Potential::~Potential() } this->components.clear(); } - if (PARAM.globalv.device_flag == "gpu") { + if (PARAM.inp.device == "gpu") { if (PARAM.inp.precision == "single") { delmem_sd_op()(gpu_ctx, s_veff_smooth); delmem_sd_op()(gpu_ctx, s_vofk_smooth); @@ -129,7 +129,7 @@ void Potential::allocate() this->vofk_smooth.create(PARAM.inp.nspin, nrxx_smooth); ModuleBase::Memory::record("Pot::vofk_smooth", sizeof(double) * PARAM.inp.nspin * nrxx_smooth); } - if (PARAM.globalv.device_flag == "gpu") { + if (PARAM.inp.device == "gpu") { if (PARAM.inp.precision == "single") { resmem_sd_op()(gpu_ctx, s_veff_smooth, PARAM.inp.nspin * nrxx_smooth); resmem_sd_op()(gpu_ctx, s_vofk_smooth, PARAM.inp.nspin * nrxx_smooth); @@ -177,7 +177,7 @@ void Potential::update_from_charge(const Charge*const chg, const UnitCell*const } #endif - if (PARAM.globalv.device_flag == "gpu") { + if (PARAM.inp.device == "gpu") { if (PARAM.inp.precision == "single") { castmem_d2s_h2d_op()(gpu_ctx, cpu_ctx, diff --git a/source/module_elecstate/test/charge_test.cpp b/source/module_elecstate/test/charge_test.cpp index 91a071b370..f780285427 100644 --- a/source/module_elecstate/test/charge_test.cpp +++ b/source/module_elecstate/test/charge_test.cpp @@ -48,7 +48,7 @@ void Set_GlobalV_Default() { PARAM.input.nspin = 1; PARAM.input.test_charge = 0; - GlobalV::nelec = 8; + PARAM.input.nelec = 8; } } // namespace elecstate @@ -164,7 +164,7 @@ TEST_F(ChargeTest, RenormalizeRho) charge->rho[is][ir] = 0.1; } } - EXPECT_EQ(GlobalV::nelec, 8); + EXPECT_EQ(PARAM.input.nelec, 8); elecstate::tmp_ucell_omega = ucell->omega; charge->renormalize_rho(); EXPECT_NEAR(charge->sum_rho(), 8.0, 1e-10); @@ -184,7 +184,7 @@ TEST_F(ChargeTest, CheckNe) charge->rho[is][ir] = 0.1; } } - EXPECT_EQ(GlobalV::nelec, 8); + EXPECT_EQ(PARAM.input.nelec, 8); elecstate::tmp_ucell_omega = ucell->omega; charge->renormalize_rho(); EXPECT_NEAR(charge->sum_rho(), 8.0, 1e-10); @@ -205,7 +205,7 @@ TEST_F(ChargeTest, SaveRhoBeforeSumBand) charge->rho[is][ir] = 0.1; } } - EXPECT_EQ(GlobalV::nelec, 8); + EXPECT_EQ(PARAM.input.nelec, 8); elecstate::tmp_xc_func_type = 3; elecstate::tmp_ucell_omega = ucell->omega; charge->renormalize_rho(); diff --git a/source/module_elecstate/test/elecstate_base_test.cpp b/source/module_elecstate/test/elecstate_base_test.cpp index 54a5839f4c..4a0950fb30 100644 --- a/source/module_elecstate/test/elecstate_base_test.cpp +++ b/source/module_elecstate/test/elecstate_base_test.cpp @@ -126,11 +126,11 @@ class MockElecState : public ElecState void Set_GlobalV_Default() { PARAM.input.nspin = 1; - GlobalV::nelec = 10.0; - GlobalV::nupdown = 0.0; + PARAM.input.nelec = 10.0; + PARAM.input.nupdown = 0.0; PARAM.sys.two_fermi = false; - GlobalV::NBANDS = 6; - GlobalV::NLOCAL = 6; + PARAM.input.nbands = 6; + PARAM.sys.nlocal = 6; PARAM.input.esolver_type = "ksdft"; PARAM.input.lspinorb = false; PARAM.input.basis_type = "pw"; @@ -193,9 +193,9 @@ TEST_F(ElecStateTest, InitKS) EXPECT_EQ(elecstate->bigpw, bigpw); EXPECT_EQ(elecstate->klist, klist); EXPECT_EQ(elecstate->ekb.nr, nk); - EXPECT_EQ(elecstate->ekb.nc, GlobalV::NBANDS); + EXPECT_EQ(elecstate->ekb.nc, PARAM.input.nbands); EXPECT_EQ(elecstate->wg.nr, nk); - EXPECT_EQ(elecstate->wg.nc, GlobalV::NBANDS); + EXPECT_EQ(elecstate->wg.nc, PARAM.input.nbands); delete klist; delete bigpw; delete rhopw; @@ -261,73 +261,73 @@ TEST_F(ElecStateTest, InitSCF) TEST_F(ElecStateTest,FixedWeights) { - EXPECT_EQ(GlobalV::NBANDS, 6); - GlobalV::nelec = 30; + EXPECT_EQ(PARAM.input.nbands, 6); + PARAM.input.nelec = 30; K_Vectors* klist = new K_Vectors; klist->set_nks(5); elecstate->klist = klist; - elecstate->wg.create(klist->get_nks(), GlobalV::NBANDS); + elecstate->wg.create(klist->get_nks(), PARAM.input.nbands); std::vector ocp_kb; - ocp_kb.resize(GlobalV::NBANDS*elecstate->klist->get_nks()); + ocp_kb.resize(PARAM.input.nbands*elecstate->klist->get_nks()); for (int i = 0; i < ocp_kb.size(); ++i) { ocp_kb[i] = 1.0; } - elecstate->fixed_weights(ocp_kb, GlobalV::NBANDS, GlobalV::nelec); + elecstate->fixed_weights(ocp_kb, PARAM.input.nbands, PARAM.input.nelec); EXPECT_EQ(elecstate->wg(0, 0), 1.0); - EXPECT_EQ(elecstate->wg(klist->get_nks()-1, GlobalV::NBANDS-1), 1.0); + EXPECT_EQ(elecstate->wg(klist->get_nks()-1, PARAM.input.nbands-1), 1.0); EXPECT_TRUE(elecstate->skip_weights); } TEST_F(ElecStateDeathTest,FixedWeightsWarning1) { - EXPECT_EQ(GlobalV::NBANDS, 6); - GlobalV::nelec = 30; + EXPECT_EQ(PARAM.input.nbands, 6); + PARAM.input.nelec = 30; K_Vectors* klist = new K_Vectors; klist->set_nks(5); elecstate->klist = klist; - elecstate->wg.create(klist->get_nks(), GlobalV::NBANDS); + elecstate->wg.create(klist->get_nks(), PARAM.input.nbands); std::vector ocp_kb; - ocp_kb.resize(GlobalV::NBANDS*elecstate->klist->get_nks()-1); + ocp_kb.resize(PARAM.input.nbands*elecstate->klist->get_nks()-1); for (int i = 0; i < ocp_kb.size(); ++i) { ocp_kb[i] = 1.0; } testing::internal::CaptureStdout(); - EXPECT_EXIT(elecstate->fixed_weights(ocp_kb, GlobalV::NBANDS, GlobalV::nelec), ::testing::ExitedWithCode(0), ""); + EXPECT_EXIT(elecstate->fixed_weights(ocp_kb, PARAM.input.nbands, PARAM.input.nelec), ::testing::ExitedWithCode(0), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("size of occupation array is wrong , please check ocp_set")); } TEST_F(ElecStateDeathTest,FixedWeightsWarning2) { - EXPECT_EQ(GlobalV::NBANDS, 6); - GlobalV::nelec = 29; + EXPECT_EQ(PARAM.input.nbands, 6); + PARAM.input.nelec = 29; K_Vectors* klist = new K_Vectors; klist->set_nks(5); elecstate->klist = klist; - elecstate->wg.create(klist->get_nks(), GlobalV::NBANDS); + elecstate->wg.create(klist->get_nks(), PARAM.input.nbands); std::vector ocp_kb; - ocp_kb.resize(GlobalV::NBANDS*elecstate->klist->get_nks()); + ocp_kb.resize(PARAM.input.nbands*elecstate->klist->get_nks()); for (int i = 0; i < ocp_kb.size(); ++i) { ocp_kb[i] = 1.0; } testing::internal::CaptureStdout(); - EXPECT_EXIT(elecstate->fixed_weights(ocp_kb, GlobalV::NBANDS, GlobalV::nelec), ::testing::ExitedWithCode(0), ""); + EXPECT_EXIT(elecstate->fixed_weights(ocp_kb, PARAM.input.nbands, PARAM.input.nelec), ::testing::ExitedWithCode(0), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("total number of occupations is wrong , please check ocp_set")); } TEST_F(ElecStateTest, CalEBand) { - EXPECT_EQ(GlobalV::NBANDS, 6); + EXPECT_EQ(PARAM.input.nbands, 6); int nks = 5; - elecstate->wg.create(nks, GlobalV::NBANDS); - elecstate->ekb.create(nks, GlobalV::NBANDS); + elecstate->wg.create(nks, PARAM.input.nbands); + elecstate->ekb.create(nks, PARAM.input.nbands); for (int ik = 0; ik < nks; ++ik) { - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) + for (int ib = 0; ib < PARAM.input.nbands; ++ib) { elecstate->ekb(ik, ib) = 1.0; elecstate->wg(ik, ib) = 2.0; @@ -373,19 +373,19 @@ TEST_F(ElecStateTest, CalculateWeightsIWeights) } elecstate->eferm.ef = 0.0; elecstate->klist = klist; - elecstate->ekb.create(nks, GlobalV::NBANDS); + elecstate->ekb.create(nks, PARAM.input.nbands); for (int ik = 0; ik < nks; ++ik) { - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) + for (int ib = 0; ib < PARAM.input.nbands; ++ib) { elecstate->ekb(ik, ib) = 100.0; } } - elecstate->wg.create(nks, GlobalV::NBANDS); + elecstate->wg.create(nks, PARAM.input.nbands); elecstate->calculate_weights(); EXPECT_DOUBLE_EQ(elecstate->wg(0, 0), 2.0); - EXPECT_DOUBLE_EQ(elecstate->wg(nks-1, GlobalV::nelec/2-1), 2.0); - EXPECT_DOUBLE_EQ(elecstate->wg(nks-1, GlobalV::NBANDS-1), 0.0); + EXPECT_DOUBLE_EQ(elecstate->wg(nks-1, PARAM.input.nelec/2-1), 2.0); + EXPECT_DOUBLE_EQ(elecstate->wg(nks-1, PARAM.input.nbands-1), 0.0); EXPECT_DOUBLE_EQ(elecstate->eferm.ef, 100.0); delete klist; } @@ -430,10 +430,10 @@ TEST_F(ElecStateTest, CalculateWeightsIWeightsTwoFermi) elecstate->eferm.ef_up = 0.0; elecstate->eferm.ef_dw = 0.0; elecstate->klist = klist; - elecstate->ekb.create(nks, GlobalV::NBANDS); + elecstate->ekb.create(nks, PARAM.input.nbands); for (int ik = 0; ik < nks; ++ik) { - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) + for (int ib = 0; ib < PARAM.input.nbands; ++ib) { if(ik < 5) { @@ -445,11 +445,11 @@ TEST_F(ElecStateTest, CalculateWeightsIWeightsTwoFermi) } } } - elecstate->wg.create(nks, GlobalV::NBANDS); + elecstate->wg.create(nks, PARAM.input.nbands); elecstate->calculate_weights(); EXPECT_DOUBLE_EQ(elecstate->wg(0, 0), 1.1); - EXPECT_DOUBLE_EQ(elecstate->wg(nks-1, GlobalV::nelec/2-1), 1.0); - EXPECT_DOUBLE_EQ(elecstate->wg(nks-1, GlobalV::NBANDS-1), 0.0); + EXPECT_DOUBLE_EQ(elecstate->wg(nks-1, PARAM.input.nelec/2-1), 1.0); + EXPECT_DOUBLE_EQ(elecstate->wg(nks-1, PARAM.input.nbands-1), 0.0); EXPECT_DOUBLE_EQ(elecstate->eferm.ef_up, 100.0); EXPECT_DOUBLE_EQ(elecstate->eferm.ef_dw, 200.0); delete klist; @@ -474,23 +474,23 @@ TEST_F(ElecStateTest, CalculateWeightsGWeights) } elecstate->eferm.ef = 0.0; elecstate->klist = klist; - elecstate->ekb.create(nks, GlobalV::NBANDS); + elecstate->ekb.create(nks, PARAM.input.nbands); for (int ik = 0; ik < nks; ++ik) { - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) + for (int ib = 0; ib < PARAM.input.nbands; ++ib) { elecstate->ekb(ik, ib) = 100.0; } } - elecstate->wg.create(nks, GlobalV::NBANDS); + elecstate->wg.create(nks, PARAM.input.nbands); elecstate->calculate_weights(); - // GlobalV::nelec = 10; - // GlobalV::NBANDS = 6; + // PARAM.input.nelec = 10; + // PARAM.input.nbands = 6; // nks = 5; // wg = 10/(5*6) = 0.33333333333 EXPECT_NEAR(elecstate->wg(0, 0), 0.33333333333, 1e-10); - EXPECT_NEAR(elecstate->wg(nks-1, GlobalV::nelec/2-1), 0.33333333333, 1e-10); - EXPECT_NEAR(elecstate->wg(nks-1, GlobalV::NBANDS-1), 0.33333333333,1e-10); + EXPECT_NEAR(elecstate->wg(nks-1, PARAM.input.nelec/2-1), 0.33333333333, 1e-10); + EXPECT_NEAR(elecstate->wg(nks-1, PARAM.input.nbands-1), 0.33333333333,1e-10); EXPECT_NEAR(elecstate->eferm.ef, 99.993159296503, 1e-10); delete klist; Occupy::use_gaussian_broadening = false; @@ -537,10 +537,10 @@ TEST_F(ElecStateTest, CalculateWeightsGWeightsTwoFermi) elecstate->eferm.ef_up = 0.0; elecstate->eferm.ef_dw = 0.0; elecstate->klist = klist; - elecstate->ekb.create(nks, GlobalV::NBANDS); + elecstate->ekb.create(nks, PARAM.input.nbands); for (int ik = 0; ik < nks; ++ik) { - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) + for (int ib = 0; ib < PARAM.input.nbands; ++ib) { if(ik < 5) { @@ -552,15 +552,15 @@ TEST_F(ElecStateTest, CalculateWeightsGWeightsTwoFermi) } } } - elecstate->wg.create(nks, GlobalV::NBANDS); + elecstate->wg.create(nks, PARAM.input.nbands); elecstate->calculate_weights(); - // GlobalV::nelec = 10; - // GlobalV::NBANDS = 6; + // PARAM.input.nelec = 10; + // PARAM.input.nbands = 6; // nks = 10; // wg = 10/(10*6) = 0.16666666666 EXPECT_NEAR(elecstate->wg(0, 0), 0.16666666666, 1e-10); - EXPECT_NEAR(elecstate->wg(nks-1, GlobalV::nelec/2-1), 0.16666666666, 1e-10); - EXPECT_NEAR(elecstate->wg(nks-1, GlobalV::NBANDS-1), 0.16666666666, 1e-10); + EXPECT_NEAR(elecstate->wg(nks-1, PARAM.input.nelec/2-1), 0.16666666666, 1e-10); + EXPECT_NEAR(elecstate->wg(nks-1, PARAM.input.nbands-1), 0.16666666666, 1e-10); EXPECT_NEAR(elecstate->eferm.ef_up, 99.992717105890961, 1e-10); EXPECT_NEAR(elecstate->eferm.ef_dw, 199.99315929650351, 1e-10); delete klist; diff --git a/source/module_elecstate/test/elecstate_energy_test.cpp b/source/module_elecstate/test/elecstate_energy_test.cpp index a9d0c477c5..3d145ea187 100644 --- a/source/module_elecstate/test/elecstate_energy_test.cpp +++ b/source/module_elecstate/test/elecstate_energy_test.cpp @@ -77,11 +77,11 @@ class MockElecState : public ElecState PARAM.input.dft_plus_u = 0; // base class PARAM.input.nspin = 1; - GlobalV::nelec = 10.0; - GlobalV::nupdown = 0.0; + PARAM.input.nelec = 10.0; + PARAM.input.nupdown = 0.0; PARAM.sys.two_fermi = false; - GlobalV::NBANDS = 6; - GlobalV::NLOCAL = 6; + PARAM.input.nbands = 6; + PARAM.sys.nlocal = 6; PARAM.input.esolver_type = "ksdft"; PARAM.input.lspinorb = false; PARAM.input.basis_type = "pw"; @@ -193,10 +193,10 @@ TEST_F(ElecStateEnergyTest, CalBandgap) K_Vectors* klist = new K_Vectors; klist->set_nks(5); elecstate->klist = klist; - elecstate->ekb.create(klist->get_nks(), GlobalV::NBANDS); + elecstate->ekb.create(klist->get_nks(), PARAM.input.nbands); for (int ik = 0; ik < klist->get_nks(); ik++) { - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.input.nbands; ib++) { elecstate->ekb(ik, ib) = ib; } @@ -230,10 +230,10 @@ TEST_F(ElecStateEnergyTest, CalBandgapUpDw) } } elecstate->klist = klist; - elecstate->ekb.create(klist->get_nks(), GlobalV::NBANDS); + elecstate->ekb.create(klist->get_nks(), PARAM.input.nbands); for (int ik = 0; ik < klist->get_nks(); ik++) { - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.input.nbands; ib++) { if (ik < 3) { diff --git a/source/module_elecstate/test/elecstate_magnetism_test.cpp b/source/module_elecstate/test/elecstate_magnetism_test.cpp index 893ef36c5a..b9266c7244 100644 --- a/source/module_elecstate/test/elecstate_magnetism_test.cpp +++ b/source/module_elecstate/test/elecstate_magnetism_test.cpp @@ -75,7 +75,7 @@ TEST_F(MagnetismTest, ComputeMagnetizationS2) { PARAM.input.nspin = 2; PARAM.sys.two_fermi = false; - GlobalV::nelec = 10.0; + PARAM.input.nelec = 10.0; Charge* chr = new Charge; chr->nrxx = 100; diff --git a/source/module_elecstate/test/elecstate_print_test.cpp b/source/module_elecstate/test/elecstate_print_test.cpp index 748f44c2e9..5d24019660 100644 --- a/source/module_elecstate/test/elecstate_print_test.cpp +++ b/source/module_elecstate/test/elecstate_print_test.cpp @@ -183,7 +183,7 @@ TEST_F(ElecStatePrintTest, PrintEigenvalueS4) TEST_F(ElecStatePrintTest, PrintBand) { PARAM.input.nspin = 1; - GlobalV::NBANDS = 2; + PARAM.input.nbands = 2; GlobalV::MY_RANK = 0; GlobalV::ofs_running.open("test.dat", std::ios::out); // print eigenvalue diff --git a/source/module_elecstate/test/elecstate_pw_test.cpp b/source/module_elecstate/test/elecstate_pw_test.cpp index 738af2b044..b491da01a0 100644 --- a/source/module_elecstate/test/elecstate_pw_test.cpp +++ b/source/module_elecstate/test/elecstate_pw_test.cpp @@ -164,23 +164,23 @@ void Charge::check_rho() void Set_GlobalV_Default() { - PARAM.sys.device_flag = "cpu"; + PARAM.input.device = "cpu"; PARAM.input.precision = "double"; PARAM.sys.domag = false; PARAM.sys.domag_z = false; // Base class dependent PARAM.input.nspin = 1; - GlobalV::nelec = 10.0; - GlobalV::nupdown = 0.0; + PARAM.input.nelec = 10.0; + PARAM.input.nupdown = 0.0; PARAM.sys.two_fermi = false; - GlobalV::NBANDS = 6; - GlobalV::NLOCAL = 6; + PARAM.input.nbands = 6; + PARAM.sys.nlocal = 6; PARAM.input.esolver_type = "ksdft"; PARAM.input.lspinorb = false; PARAM.input.basis_type = "pw"; GlobalV::KPAR = 1; GlobalV::NPROC_IN_POOL = 1; - GlobalV::use_uspp = false; + PARAM.sys.use_uspp = false; } /************************************************ diff --git a/source/module_elecstate/test/potential_new_test.cpp b/source/module_elecstate/test/potential_new_test.cpp index b30a2b21cf..e03619d867 100644 --- a/source/module_elecstate/test/potential_new_test.cpp +++ b/source/module_elecstate/test/potential_new_test.cpp @@ -55,7 +55,7 @@ PotBase* Potential::get_pot_type(const std::string& pot_type) void Set_GlobalV_Default() { PARAM.input.nspin = 1; - PARAM.sys.device_flag = "cpu"; + PARAM.input.device = "cpu"; PARAM.input.precision = "double"; } } // namespace elecstate @@ -193,7 +193,7 @@ TEST_F(PotentialNewTest, ConstructorGPUDouble) { // this is just a trivial call to the GPU code rhopw->nrxx = 100; - PARAM.sys.device_flag = "gpu"; + PARAM.input.device = "gpu"; pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc); EXPECT_TRUE(pot->fixed_mode); EXPECT_TRUE(pot->dynamic_mode); @@ -206,7 +206,7 @@ TEST_F(PotentialNewTest, ConstructorGPUSingle) { // this is just a trivial call to the GPU code rhopw->nrxx = 100; - PARAM.sys.device_flag = "gpu"; + PARAM.input.device = "gpu"; PARAM.input.precision = "single"; pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc); EXPECT_TRUE(pot->fixed_mode); diff --git a/source/module_esolver/cal_edm_tddft.cpp b/source/module_esolver/cal_edm_tddft.cpp index e3fe4d0b2c..f5d31c9f5c 100644 --- a/source/module_esolver/cal_edm_tddft.cpp +++ b/source/module_esolver/cal_edm_tddft.cpp @@ -42,7 +42,7 @@ namespace ModuleESolver void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() { // mohan add 2024-03-27 - const int nlocal = GlobalV::NLOCAL; + const int nlocal = PARAM.globalv.nlocal; assert(nlocal >= 0); dynamic_cast>*>(this->pelec) diff --git a/source/module_esolver/esolver.cpp b/source/module_esolver/esolver.cpp index 28473d1d99..3501cc79b2 100644 --- a/source/module_esolver/esolver.cpp +++ b/source/module_esolver/esolver.cpp @@ -100,7 +100,7 @@ std::string determine_type() GlobalV::ofs_running << " The esolver type has been set to : " << esolver_type << std::endl; - auto device_info = PARAM.globalv.device_flag; + auto device_info = PARAM.inp.device; for (char &c : device_info) { @@ -112,11 +112,11 @@ std::string determine_type() if (GlobalV::MY_RANK == 0) { std::cout << " RUNNING WITH DEVICE : " << device_info << " / " - << base_device::information::get_device_info(PARAM.globalv.device_flag) << std::endl; + << base_device::information::get_device_info(PARAM.inp.device) << std::endl; } GlobalV::ofs_running << "\n RUNNING WITH DEVICE : " << device_info << " / " - << base_device::information::get_device_info(PARAM.globalv.device_flag) << std::endl; + << base_device::information::get_device_info(PARAM.inp.device) << std::endl; return esolver_type; } @@ -132,7 +132,7 @@ ESolver* init_esolver(const Input_para& inp, UnitCell& ucell) if (esolver_type == "ksdft_pw") { #if ((defined __CUDA) || (defined __ROCM)) - if (PARAM.globalv.device_flag == "gpu") + if (PARAM.inp.device == "gpu") { if (PARAM.inp.precision == "single") { diff --git a/source/module_esolver/esolver_fp.cpp b/source/module_esolver/esolver_fp.cpp index be9b260285..7bbf7888c1 100644 --- a/source/module_esolver/esolver_fp.cpp +++ b/source/module_esolver/esolver_fp.cpp @@ -17,11 +17,11 @@ namespace ModuleESolver ESolver_FP::ESolver_FP() { // pw_rho = new ModuleBase::PW_Basis(); - pw_rho = new ModulePW::PW_Basis_Big(PARAM.globalv.device_flag, PARAM.inp.precision); + pw_rho = new ModulePW::PW_Basis_Big(PARAM.inp.device, PARAM.inp.precision); if ( PARAM.globalv.double_grid) { - pw_rhod = new ModulePW::PW_Basis_Big(PARAM.globalv.device_flag, PARAM.inp.precision); + pw_rhod = new ModulePW::PW_Basis_Big(PARAM.inp.device, PARAM.inp.precision); } else { diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index 1e851f9651..6ae66c76f3 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -56,7 +56,7 @@ ESolver_KS::ESolver_KS() // pw_rho = new ModuleBase::PW_Basis(); // temporary, it will be removed - pw_wfc = new ModulePW::PW_Basis_K_Big(PARAM.globalv.device_flag, PARAM.inp.precision); + pw_wfc = new ModulePW::PW_Basis_K_Big(PARAM.inp.device, PARAM.inp.precision); ModulePW::PW_Basis_K_Big* tmp = static_cast(pw_wfc); // should not use INPUT here, mohan 2024-05-12 @@ -449,7 +449,7 @@ void ESolver_KS::runner(const int istep, UnitCell& ucell) drho, PARAM.inp.pw_diag_thr, diag_ethr, - GlobalV::nelec); + PARAM.inp.nelec); } else if (PARAM.inp.esolver_type == "sdft") { @@ -462,7 +462,7 @@ void ESolver_KS::runner(const int istep, UnitCell& ucell) drho, PARAM.inp.pw_diag_thr, diag_ethr, - GlobalV::NBANDS, + PARAM.inp.nbands, esolver_KS_ne); } @@ -487,7 +487,7 @@ void ESolver_KS::runner(const int istep, UnitCell& ucell) // double drho = this->estate.caldr2(); // EState should be used after it is constructed. - drho = p_chgmix->get_drho(pelec->charge, GlobalV::nelec); + drho = p_chgmix->get_drho(pelec->charge, PARAM.inp.nelec); double hsolver_error = 0.0; if (firstscf) { @@ -495,7 +495,7 @@ void ESolver_KS::runner(const int istep, UnitCell& ucell) hsolver_error = hsolver::cal_hsolve_error(PARAM.inp.basis_type, PARAM.inp.esolver_type, diag_ethr, - GlobalV::nelec); + PARAM.inp.nelec); // The error of HSolver is larger than drho, // so a more precise HSolver should be excuconv_elected. @@ -508,16 +508,16 @@ void ESolver_KS::runner(const int istep, UnitCell& ucell) hsolver_error, drho, diag_ethr, - GlobalV::nelec); + PARAM.inp.nelec); this->hamilt2density(istep, iter, diag_ethr); - drho = p_chgmix->get_drho(pelec->charge, GlobalV::nelec); + drho = p_chgmix->get_drho(pelec->charge, PARAM.inp.nelec); hsolver_error = hsolver::cal_hsolve_error(PARAM.inp.basis_type, PARAM.inp.esolver_type, diag_ethr, - GlobalV::nelec); + PARAM.inp.nelec); } } // mixing will restart at this->p_chgmix->mixing_restart steps @@ -601,7 +601,7 @@ void ESolver_KS::runner(const int istep, UnitCell& ucell) double dkin = 0.0; // for meta-GGA if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5) { - dkin = p_chgmix->get_dkin(pelec->charge, GlobalV::nelec); + dkin = p_chgmix->get_dkin(pelec->charge, PARAM.inp.nelec); } this->print_iter(iter, drho, dkin, duration, diag_ethr); diff --git a/source/module_esolver/esolver_ks_lcao.cpp b/source/module_esolver/esolver_ks_lcao.cpp index 217f14e89d..6ada51bfe2 100644 --- a/source/module_esolver/esolver_ks_lcao.cpp +++ b/source/module_esolver/esolver_ks_lcao.cpp @@ -251,7 +251,7 @@ void ESolver_KS_LCAO::before_all_runners(const Input_para& inp, UnitCell // 14) set occupations if (PARAM.inp.ocp) { - this->pelec->fixed_weights(PARAM.inp.ocp_kb, GlobalV::NBANDS, GlobalV::nelec); + this->pelec->fixed_weights(PARAM.inp.ocp_kb, PARAM.inp.nbands, PARAM.inp.nelec); } // 15) if kpar is not divisible by nks, print a warning @@ -419,7 +419,7 @@ void ESolver_KS_LCAO::after_all_runners() GlobalV::ofs_running << "\n Output bands in file: " << ss2.str() << std::endl; ModuleIO::nscf_band(is, ss2.str(), - GlobalV::NBANDS, + PARAM.inp.nbands, 0.0, PARAM.inp.out_band[1], this->pelec->ekb, @@ -446,14 +446,14 @@ void ESolver_KS_LCAO::after_all_runners() GlobalC::Pkpoints, GlobalC::ucell, this->pelec->eferm, - GlobalV::NBANDS, + PARAM.inp.nbands, this->p_hamilt); } if (PARAM.inp.out_mat_xc) { ModuleIO::write_Vxc(PARAM.inp.nspin, - GlobalV::NLOCAL, + PARAM.globalv.nlocal, GlobalV::DRANK, &this->pv, *this->psi, @@ -480,7 +480,7 @@ void ESolver_KS_LCAO::after_all_runners() if (PARAM.inp.out_eband_terms) { ModuleIO::write_eband_terms(PARAM.inp.nspin, - GlobalV::NLOCAL, + PARAM.globalv.nlocal, GlobalV::DRANK, &this->pv, *this->psi, @@ -843,7 +843,7 @@ void ESolver_KS_LCAO::update_pot(const int istep, const int iter) { ModuleIO::save_mat(istep, h_mat.p, - GlobalV::NLOCAL, + PARAM.globalv.nlocal, bit, PARAM.inp.out_mat_hs[1], 1, @@ -854,7 +854,7 @@ void ESolver_KS_LCAO::update_pot(const int istep, const int iter) GlobalV::DRANK); ModuleIO::save_mat(istep, s_mat.p, - GlobalV::NLOCAL, + PARAM.globalv.nlocal, bit, PARAM.inp.out_mat_hs[1], 1, @@ -1164,7 +1164,7 @@ void ESolver_KS_LCAO::after_scf(const int istep) LDI.out_deepks_labels(this->pelec->f_en.etot, this->pelec->klist->get_nks(), GlobalC::ucell.nat, - GlobalV::NLOCAL, + PARAM.globalv.nlocal, this->pelec->ekb, this->pelec->klist->kvec_d, GlobalC::ucell, @@ -1288,7 +1288,7 @@ void ESolver_KS_LCAO::after_scf(const int istep) ekinetic->init(ik); ModuleIO::save_mat(0, hsk.get_hk(), - GlobalV::NLOCAL, + PARAM.globalv.nlocal, false, PARAM.inp.out_mat_tk[1], 1, diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index c1bf644d52..976501980b 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -128,8 +128,8 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(const int istep, const int iter, cons if (istep >= 1) { module_tddft::Evolve_elec::solve_psi(istep, - GlobalV::NBANDS, - GlobalV::NLOCAL, + PARAM.inp.nbands, + PARAM.globalv.nlocal, this->p_hamilt, this->pv, this->psi, @@ -147,8 +147,8 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(const int istep, const int iter, cons else if (istep >= 2) { module_tddft::Evolve_elec::solve_psi(istep, - GlobalV::NBANDS, - GlobalV::NLOCAL, + PARAM.inp.nbands, + PARAM.globalv.nlocal, this->p_hamilt, this->pv, this->psi, @@ -189,7 +189,7 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(const int istep, const int iter, cons GlobalV::ofs_running << std::setiosflags(std::ios::showpoint); for (int ik = 0; ik < kv.get_nks(); ik++) { - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { std::setprecision(6); GlobalV::ofs_running << ik + 1 << " " << ib + 1 << " " << this->pelec_td->wg(ik, ib) @@ -256,7 +256,7 @@ void ESolver_KS_LCAO_TDDFT::update_pot(const int istep, const int iter) { ModuleIO::save_mat(istep, h_mat.p, - GlobalV::NLOCAL, + PARAM.globalv.nlocal, bit, PARAM.inp.out_mat_hs[1], 1, @@ -268,7 +268,7 @@ void ESolver_KS_LCAO_TDDFT::update_pot(const int istep, const int iter) ModuleIO::save_mat(istep, s_mat.p, - GlobalV::NLOCAL, + PARAM.globalv.nlocal, bit, PARAM.inp.out_mat_hs[1], 1, @@ -312,8 +312,8 @@ void ESolver_KS_LCAO_TDDFT::update_pot(const int istep, const int iter) const int nloc = this->pv.nloc; const int ncol_nbands = this->pv.ncol_bands; const int nrow = this->pv.nrow; - const int nbands = GlobalV::NBANDS; - const int nlocal = GlobalV::NLOCAL; + const int nbands = PARAM.inp.nbands; + const int nlocal = PARAM.globalv.nlocal; // store wfc and Hk laststep if (istep >= (wf.init_wfc == "file" ? 0 : 1) && this->conv_elec) @@ -390,7 +390,7 @@ void ESolver_KS_LCAO_TDDFT::update_pot(const int istep, const int iter) for (int ik = 0; ik < kv.get_nks(); ik++) { - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { GlobalV::ofs_running << ik + 1 << " " << ib + 1 << " " << this->pelec_td->ekb(ik, ib) * ModuleBase::Ry_to_eV << std::endl; diff --git a/source/module_esolver/esolver_ks_lcaopw.cpp b/source/module_esolver/esolver_ks_lcaopw.cpp index c91e8414a5..a5869c4a57 100644 --- a/source/module_esolver/esolver_ks_lcaopw.cpp +++ b/source/module_esolver/esolver_ks_lcaopw.cpp @@ -261,7 +261,7 @@ namespace ModuleESolver #ifdef __LCAO if (PARAM.inp.out_mat_xc) { - ModuleIO::write_Vxc(PARAM.inp.nspin, GlobalV::NLOCAL, + ModuleIO::write_Vxc(PARAM.inp.nspin, PARAM.globalv.nlocal, GlobalV::DRANK, *this->kspw_psi, GlobalC::ucell, this->sf, *this->pw_wfc, *this->pw_rho, *this->pw_rhod, GlobalC::ppcell.vloc, *this->pelec->charge, this->kv, this->pelec->wg diff --git a/source/module_esolver/esolver_ks_pw.cpp b/source/module_esolver/esolver_ks_pw.cpp index af75d8175f..4deedeba39 100644 --- a/source/module_esolver/esolver_ks_pw.cpp +++ b/source/module_esolver/esolver_ks_pw.cpp @@ -161,7 +161,7 @@ void ESolver_KS_PW::before_all_runners(const Input_para& inp, UnitCel //! 9) setup occupations if (PARAM.inp.ocp) { - this->pelec->fixed_weights(PARAM.inp.ocp_kb, GlobalV::NBANDS, GlobalV::nelec); + this->pelec->fixed_weights(PARAM.inp.ocp_kb, PARAM.inp.nbands, PARAM.inp.nelec); } } @@ -369,7 +369,7 @@ void ESolver_KS_PW::hamilt2density(const int istep, const int iter, c PARAM.inp.basis_type, PARAM.inp.ks_solver, PARAM.inp.use_paw, - GlobalV::use_uspp, + PARAM.globalv.use_uspp, PARAM.inp.nspin, hsolver::DiagoIterAssist::SCF_ITER, @@ -457,7 +457,7 @@ void ESolver_KS_PW::iter_finish(int& iter) // D in uspp need vloc, thus needs update when veff updated // calculate the effective coefficient matrix for non-local pseudopotential // projectors - if (GlobalV::use_uspp) + if (PARAM.globalv.use_uspp) { ModuleBase::matrix veff = this->pelec->pot->get_effective_v(); GlobalC::ppcell.cal_effective_D(veff, this->pw_rhod, GlobalC::ucell); @@ -738,7 +738,7 @@ void ESolver_KS_PW::after_all_runners() GlobalV::ofs_running << "\n Output bands in file: " << ss2.str() << std::endl; ModuleIO::nscf_band(is, ss2.str(), - GlobalV::NBANDS, + PARAM.inp.nbands, 0.0, PARAM.inp.out_band[1], this->pelec->ekb, diff --git a/source/module_esolver/esolver_of.cpp b/source/module_esolver/esolver_of.cpp index f125f1098e..8c7f54509c 100644 --- a/source/module_esolver/esolver_of.cpp +++ b/source/module_esolver/esolver_of.cpp @@ -134,7 +134,7 @@ void ESolver_OF::before_all_runners(const Input_para& inp, UnitCell& ucell) this->nelec_ = new double[PARAM.inp.nspin]; if (PARAM.inp.nspin == 1) { - this->nelec_[0] = GlobalV::nelec; + this->nelec_[0] = PARAM.inp.nelec; } else if (PARAM.inp.nspin == 2) { diff --git a/source/module_esolver/esolver_sdft_pw.cpp b/source/module_esolver/esolver_sdft_pw.cpp index 19ce25f03b..e8241d7e67 100644 --- a/source/module_esolver/esolver_sdft_pw.cpp +++ b/source/module_esolver/esolver_sdft_pw.cpp @@ -86,7 +86,7 @@ void ESolver_SDFT_PW::before_all_runners(const Input_para& inp, UnitCell& ucell) // 7) set occupatio, redundant? if (PARAM.inp.ocp) { - this->pelec->fixed_weights(PARAM.inp.ocp_kb, GlobalV::NBANDS, GlobalV::nelec); + this->pelec->fixed_weights(PARAM.inp.ocp_kb, PARAM.inp.nbands, PARAM.inp.nelec); } // 8) initialize the global classes @@ -120,7 +120,7 @@ void ESolver_SDFT_PW::before_all_runners(const Input_para& inp, UnitCell& ucell) ModuleBase::Memory::record("SDFT::shchi", size * sizeof(std::complex)); - if (GlobalV::NBANDS > 0) + if (PARAM.inp.nbands > 0) { this->stowf.chiortho = new psi::Psi>(kv.get_nks(), stowf.nchip_max, wf.npwx, kv.ngk.data()); @@ -182,7 +182,7 @@ void ESolver_SDFT_PW::hamilt2density(int istep, int iter, double ethr) PARAM.inp.basis_type, PARAM.inp.ks_solver, PARAM.inp.use_paw, - GlobalV::use_uspp, + PARAM.globalv.use_uspp, PARAM.inp.nspin, hsolver::DiagoIterAssist>::SCF_ITER, hsolver::DiagoIterAssist>::PW_DIAG_NMAX, @@ -333,7 +333,7 @@ void ESolver_SDFT_PW::nscf() const int iter = 1; - const double diag_thr = std::max(std::min(1e-5, 0.1 * PARAM.inp.scf_thr / std::max(1.0, GlobalV::nelec)), 1e-12); + const double diag_thr = std::max(std::min(1e-5, 0.1 * PARAM.inp.scf_thr / std::max(1.0, PARAM.inp.nelec)), 1e-12); std::cout << " DIGA_THR : " << diag_thr << std::endl; diff --git a/source/module_esolver/io_npz.cpp b/source/module_esolver/io_npz.cpp index 2747f9d286..062e16f51c 100644 --- a/source/module_esolver/io_npz.cpp +++ b/source/module_esolver/io_npz.cpp @@ -1,5 +1,6 @@ //Deals with io of dm(r)/h(r) in npz format +#include "module_parameter/parameter.h" #include "module_esolver/esolver_ks_lcao.h" #include "module_base/parallel_reduce.h" @@ -426,8 +427,8 @@ void ESolver_KS_LCAO::output_mat_npz(std::string& zipname, const hamilt: #ifdef __MPI hamilt::HContainer* HR_serial; Parallel_Orbitals serialV; - serialV.set_serial(GlobalV::NLOCAL, GlobalV::NLOCAL); - serialV.set_atomic_trace(GlobalC::ucell.get_iat2iwt(), GlobalC::ucell.nat, GlobalV::NLOCAL); + serialV.set_serial(PARAM.globalv.nlocal, PARAM.globalv.nlocal); + serialV.set_atomic_trace(GlobalC::ucell.get_iat2iwt(), GlobalC::ucell.nat, PARAM.globalv.nlocal); if(GlobalV::MY_RANK == 0) { HR_serial = new hamilt::HContainer(&serialV); diff --git a/source/module_esolver/lcao_before_scf.cpp b/source/module_esolver/lcao_before_scf.cpp index 3bef3a70d3..7f75907aae 100644 --- a/source/module_esolver/lcao_before_scf.cpp +++ b/source/module_esolver/lcao_before_scf.cpp @@ -77,7 +77,7 @@ void ESolver_KS_LCAO::beforesolver(const int istep) #ifdef __MPI ncol = this->pv.ncol_bands; #else - ncol = GlobalV::NBANDS; + ncol = PARAM.inp.nbands; #endif } this->psi = new psi::Psi(nsk, ncol, this->pv.nrow, nullptr); diff --git a/source/module_esolver/lcao_nscf.cpp b/source/module_esolver/lcao_nscf.cpp index 56a3414696..e8a91b5b90 100644 --- a/source/module_esolver/lcao_nscf.cpp +++ b/source/module_esolver/lcao_nscf.cpp @@ -62,7 +62,7 @@ void ESolver_KS_LCAO::nscf() { GlobalV::ofs_running << " band eigenvalue in this processor (eV) :" << std::endl; const int nspin = PARAM.inp.nspin; - const int nbands = GlobalV::NBANDS; + const int nbands = PARAM.inp.nbands; for (int ik = 0; ik < this->kv.get_nks(); ++ik) { diff --git a/source/module_esolver/lcao_others.cpp b/source/module_esolver/lcao_others.cpp index 667eac6c20..5587baed1d 100644 --- a/source/module_esolver/lcao_others.cpp +++ b/source/module_esolver/lcao_others.cpp @@ -111,10 +111,10 @@ void ESolver_KS_LCAO::others(const int istep) PARAM.globalv.gamma_only_local, PARAM.inp.nbands_istate, PARAM.inp.bands_to_print, - GlobalV::NBANDS, - GlobalV::nelec, + PARAM.inp.nbands, + PARAM.inp.nelec, PARAM.inp.nspin, - GlobalV::NLOCAL, + PARAM.globalv.nlocal, PARAM.globalv.global_out_dir, GlobalV::MY_RANK, GlobalV::ofs_warning, @@ -141,10 +141,10 @@ void ESolver_KS_LCAO::others(const int istep) PARAM.globalv.gamma_only_local, PARAM.inp.nbands_istate, PARAM.inp.bands_to_print, - GlobalV::NBANDS, - GlobalV::nelec, + PARAM.inp.nbands, + PARAM.inp.nelec, PARAM.inp.nspin, - GlobalV::NLOCAL, + PARAM.globalv.nlocal, PARAM.globalv.global_out_dir, GlobalV::MY_RANK, GlobalV::ofs_warning, @@ -172,12 +172,12 @@ void ESolver_KS_LCAO::others(const int istep) PARAM.inp.out_wfc_pw, this->wf.out_wfc_r, this->kv, - GlobalV::nelec, + PARAM.inp.nelec, PARAM.inp.nbands_istate, PARAM.inp.bands_to_print, - GlobalV::NBANDS, + PARAM.inp.nbands, PARAM.inp.nspin, - GlobalV::NLOCAL, + PARAM.globalv.nlocal, PARAM.globalv.global_out_dir); } else @@ -191,12 +191,12 @@ void ESolver_KS_LCAO::others(const int istep) PARAM.inp.out_wfc_pw, this->wf.out_wfc_r, this->kv, - GlobalV::nelec, + PARAM.inp.nelec, PARAM.inp.nbands_istate, PARAM.inp.bands_to_print, - GlobalV::NBANDS, + PARAM.inp.nbands, PARAM.inp.nspin, - GlobalV::NLOCAL, + PARAM.globalv.nlocal, PARAM.globalv.global_out_dir); } std::cout << FmtCore::format(" >> Finish %s.\n * * * * * *\n", "getting wave function"); diff --git a/source/module_esolver/pw_fun.cpp b/source/module_esolver/pw_fun.cpp index dd22724598..d1867099a3 100644 --- a/source/module_esolver/pw_fun.cpp +++ b/source/module_esolver/pw_fun.cpp @@ -87,7 +87,7 @@ void ESolver_KS_PW::hamilt2estates(const double ethr) PARAM.inp.basis_type, PARAM.inp.ks_solver, PARAM.inp.use_paw, - GlobalV::use_uspp, + PARAM.globalv.use_uspp, PARAM.inp.nspin, hsolver::DiagoIterAssist::SCF_ITER, diff --git a/source/module_esolver/pw_init_globalc.cpp b/source/module_esolver/pw_init_globalc.cpp index 9fd7b7110e..52763d368f 100644 --- a/source/module_esolver/pw_init_globalc.cpp +++ b/source/module_esolver/pw_init_globalc.cpp @@ -90,7 +90,7 @@ void ESolver_KS_PW::Init_GlobalC(const Input_para& inp, &(this->sf)); this->kspw_psi - = PARAM.globalv.device_flag == "gpu" || PARAM.inp.precision == "single" + = PARAM.inp.device == "gpu" || PARAM.inp.precision == "single" ? new psi::Psi(this->psi[0]) : reinterpret_cast*>(this->psi); diff --git a/source/module_esolver/pw_nscf.cpp b/source/module_esolver/pw_nscf.cpp index acc5534be9..4919892090 100644 --- a/source/module_esolver/pw_nscf.cpp +++ b/source/module_esolver/pw_nscf.cpp @@ -64,7 +64,7 @@ void ESolver_KS_PW::nscf() { if (diag_ethr - 1e-2 > -1e-5) { diag_ethr = std::max(1e-13, - 0.1 * std::min(1e-2, PARAM.inp.scf_thr / GlobalV::nelec)); + 0.1 * std::min(1e-2, PARAM.inp.scf_thr / PARAM.inp.nelec)); } GlobalV::ofs_running << " PW_DIAG_THR = " << diag_ethr << std::endl; @@ -79,7 +79,7 @@ void ESolver_KS_PW::nscf() { //! 4) print out band energies and weights std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "writing band energies"); const int nspin = PARAM.inp.nspin; - const int nbands = GlobalV::NBANDS; + const int nbands = PARAM.inp.nbands; for (int ik = 0; ik < this->kv.get_nks(); ik++) { if (nspin == 2) { if (ik == 0) { diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp index 8fd39e3f0e..9f72bf544c 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp @@ -158,13 +158,13 @@ void Force_LCAO::finish_ftable(ForceStressArrays& fsr) //{ // std::cout << "\n PRINT " << name << std::endl; // std::cout << std::setprecision(6) << std::endl; -// for (int i = 0; i < GlobalV::NLOCAL; i++) +// for (int i = 0; i < PARAM.globalv.nlocal; i++) // { -// for (int j = 0; j < GlobalV::NLOCAL; j++) +// for (int j = 0; j < PARAM.globalv.nlocal; j++) // { -// if (std::abs(mm[i * GlobalV::NLOCAL + j]) > 1.0e-5) +// if (std::abs(mm[i * PARAM.globalv.nlocal + j]) > 1.0e-5) // { -// std::cout << std::setw(12) << mm[i * GlobalV::NLOCAL + j]; +// std::cout << std::setw(12) << mm[i * PARAM.globalv.nlocal + j]; // } // else // { @@ -271,7 +271,7 @@ void Force_LCAO::ftable(const bool isforce, if (PARAM.inp.deepks_out_unittest) { - LCAO_deepks_io::print_dm(dm_gamma[0], GlobalV::NLOCAL, this->ParaV->nrow); + LCAO_deepks_io::print_dm(dm_gamma[0], PARAM.globalv.nlocal, this->ParaV->nrow); GlobalC::ld.check_projected_dm(); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_k.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_k.cpp index ff11c217c4..81e10d3bbf 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_k.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_k.cpp @@ -216,8 +216,8 @@ void Force_LCAO>::finish_ftable(ForceStressArrays& fsr) // RA.for_2d(pv, GlobalV::GAMMA_ONLY_LOCAL, GlobalC::ORB.cutoffs()); // // double* test; -// test = new double[GlobalV::NLOCAL * GlobalV::NLOCAL]; -// ModuleBase::GlobalFunc::ZEROS(test, GlobalV::NLOCAL * GlobalV::NLOCAL); +// test = new double[PARAM.globalv.nlocal * PARAM.globalv.nlocal]; +// ModuleBase::GlobalFunc::ZEROS(test, PARAM.globalv.nlocal * PARAM.globalv.nlocal); // // for (int T1 = 0; T1 < GlobalC::ucell.ntype; T1++) // { @@ -240,7 +240,7 @@ void Force_LCAO>::finish_ftable(ForceStressArrays& fsr) // { // const int iw2_all = start2 + kk; // assert(irr < pv.nnr); -// test[iw1_all * GlobalV::NLOCAL + iw2_all] += mmm[irr]; +// test[iw1_all * PARAM.globalv.nlocal + iw2_all] += mmm[irr]; // ++irr; // } // } @@ -251,13 +251,13 @@ void Force_LCAO>::finish_ftable(ForceStressArrays& fsr) // // std::cout << "\n " << name << std::endl; // std::cout << std::setprecision(4); -// for (int i = 0; i < GlobalV::NLOCAL; i++) +// for (int i = 0; i < PARAM.globalv.nlocal; i++) // { -// for (int j = 0; j < GlobalV::NLOCAL; j++) +// for (int j = 0; j < PARAM.globalv.nlocal; j++) // { -// if (std::abs(test[i * GlobalV::NLOCAL + j]) > 1.0e-5) +// if (std::abs(test[i * PARAM.globalv.nlocal + j]) > 1.0e-5) // { -// std::cout << std::setw(12) << test[i * GlobalV::NLOCAL + j]; +// std::cout << std::setw(12) << test[i * PARAM.globalv.nlocal + j]; // } // else // { diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_init_basis.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_init_basis.cpp index 92384e4c5c..e0dc45bd6d 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_init_basis.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_init_basis.cpp @@ -23,7 +23,7 @@ void init_basis_lcao(Parallel_Orbitals& pv, { ModuleBase::TITLE("ESolver_KS_LCAO", "init_basis_lcao"); - const int nlocal = GlobalV::NLOCAL; + const int nlocal = PARAM.globalv.nlocal; int nb2d = PARAM.inp.nb2d; // autoset NB2D first if (nb2d == 0) @@ -76,20 +76,20 @@ void init_basis_lcao(Parallel_Orbitals& pv, // is determined in 'divide_HS_2d' subroutine int try_nb = pv.init(nlocal, nlocal, nb2d, DIAG_WORLD); - try_nb += pv.set_nloc_wfc_Eij(GlobalV::NBANDS, GlobalV::ofs_running, GlobalV::ofs_warning); + try_nb += pv.set_nloc_wfc_Eij(PARAM.inp.nbands, GlobalV::ofs_running, GlobalV::ofs_warning); if (try_nb != 0) { pv.set(nlocal, nlocal, 1, pv.blacs_ctxt); - try_nb = pv.set_nloc_wfc_Eij(GlobalV::NBANDS, GlobalV::ofs_running, GlobalV::ofs_warning); + try_nb = pv.set_nloc_wfc_Eij(PARAM.inp.nbands, GlobalV::ofs_running, GlobalV::ofs_warning); } // init blacs context for genelpa - pv.set_desc_wfc_Eij(nlocal, GlobalV::NBANDS, pv.nrow); + pv.set_desc_wfc_Eij(nlocal, PARAM.inp.nbands, pv.nrow); #else pv.set_serial(nlocal, nlocal); pv.nrow_bands = nlocal; - pv.ncol_bands = GlobalV::NBANDS; + pv.ncol_bands = PARAM.inp.nbands; // Zhang Xiaoyang enable the serial version of LCAO and recovered this function usage. 2024-07-06 #endif diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/fedm_gamma.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/fedm_gamma.cpp index 728525a656..6fe6420d6d 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/fedm_gamma.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/fedm_gamma.cpp @@ -29,8 +29,8 @@ void Force_LCAO::cal_fedm( ModuleBase::timer::tick("Force_LCAO","cal_fedm"); const int nspin = PARAM.inp.nspin; - const int nbands = GlobalV::NBANDS; - const int nlocal = GlobalV::NLOCAL; + const int nbands = PARAM.inp.nbands; + const int nlocal = PARAM.globalv.nlocal; ModuleBase::matrix wg_ekb; wg_ekb.create(nspin, nbands); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/fedm_k.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/fedm_k.cpp index 9eb705d489..4f090b5f7b 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/fedm_k.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/fedm_k.cpp @@ -42,7 +42,7 @@ void Force_LCAO>::cal_fedm(const bool isforce, ModuleBase::timer::tick("Force_LCAO", "cal_fedm"); const int nspin = PARAM.inp.nspin; - const int nbands = GlobalV::NBANDS; + const int nbands = PARAM.inp.nbands; // construct a DensityMatrix object elecstate::DensityMatrix, double> edm(kv, &pv, nspin); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/ftvnl_dphi_gamma.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/ftvnl_dphi_gamma.cpp index ea5ca9ed83..f639f4c511 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/ftvnl_dphi_gamma.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/ftvnl_dphi_gamma.cpp @@ -20,7 +20,7 @@ void Force_LCAO::cal_ftvnl_dphi( ModuleBase::TITLE("Force_LCAO","cal_ftvnl_dphi"); ModuleBase::timer::tick("Force_LCAO","cal_ftvnl_dphi"); - const int nlocal = GlobalV::NLOCAL; + const int nlocal = PARAM.globalv.nlocal; const int nspin = PARAM.inp.nspin; for(int i=0; i>::OperatorEXX(HS_Matrix_K* hsk_in, const std::string file_name_exx = PARAM.globalv.global_readin_dir + "HexxR" + std::to_string(GlobalV::MY_RANK); if (GlobalC::exx_info.info_ri.real_number) { - ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, PARAM.inp.nspin, GlobalV::NLOCAL, *Hexxd); + ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxd); if (this->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer(*Hexxd, this->hR); } } else { - ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, PARAM.inp.nspin, GlobalV::NLOCAL, *Hexxc); + ModuleIO::read_Hexxs_csr(file_name_exx, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxc); if (this->add_hexx_type == Add_Hexx_Type::R) { reallocate_hcontainer(*Hexxc, this->hR); } } this->use_cell_nearest = false; @@ -180,10 +180,10 @@ OperatorEXX>::OperatorEXX(HS_Matrix_K* hsk_in, // read in Hexx(R) const std::string restart_HR_path = GlobalC::restart.folder + "HexxR" + std::to_string(GlobalV::MY_RANK); if (GlobalC::exx_info.info_ri.real_number) { - ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, PARAM.inp.nspin, GlobalV::NLOCAL, *Hexxd); + ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxd); } else { - ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, PARAM.inp.nspin, GlobalV::NLOCAL, *Hexxc); + ModuleIO::read_Hexxs_csr(restart_HR_path, GlobalC::ucell, PARAM.inp.nspin, PARAM.globalv.nlocal, *Hexxc); } } diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/spar_u.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/spar_u.cpp index f8f886688a..4515ea185c 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/spar_u.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/spar_u.cpp @@ -76,12 +76,12 @@ void sparse_format::cal_HR_dftu( GlobalC::dftu.cal_eff_pot_mat_R_double(current_spin, SR_tmp, HR_tmp); - for (int i = 0; i < GlobalV::NLOCAL; ++i) + for (int i = 0; i < PARAM.globalv.nlocal; ++i) { ir = pv.global2local_row(i); if (ir >= 0) { - for (int j = 0; j < GlobalV::NLOCAL; ++j) + for (int j = 0; j < PARAM.globalv.nlocal; ++j) { ic = pv.global2local_col(j); if (ic >= 0) @@ -196,12 +196,12 @@ void sparse_format::cal_HR_dftu_soc( GlobalC::dftu.cal_eff_pot_mat_R_complex_double(current_spin, SR_soc_tmp, HR_soc_tmp); - for (int i = 0; i < GlobalV::NLOCAL; ++i) + for (int i = 0; i < PARAM.globalv.nlocal; ++i) { ir = pv.global2local_row(i); if (ir >= 0) { - for (int j = 0; j < GlobalV::NLOCAL; ++j) + for (int j = 0; j < PARAM.globalv.nlocal; ++j) { ic = pv.global2local_col(j); if (ic >= 0) diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/wavefunc_in_pw.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/wavefunc_in_pw.cpp index 5d4917d9e0..db06c13f3a 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/wavefunc_in_pw.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/wavefunc_in_pw.cpp @@ -452,7 +452,7 @@ void Wavefunc_in_pw::produce_local_basis_in_pw(const int& ik, delete[] sk; } // end for ia } // end for it - assert(iwall == GlobalV::NLOCAL); + assert(iwall == PARAM.globalv.nlocal); delete[] flq; delete[] aux; delete[] chiaux; diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp index a95ab763a0..8b10d55d41 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp @@ -54,7 +54,7 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, if (PARAM.inp.deepks_bandgap) { - const int nocc = GlobalV::nelec / 2; + const int nocc = PARAM.inp.nelec / 2; ModuleBase::matrix deepks_bands; deepks_bands.create(nks, 1); for (int iks = 0; iks < nks; ++iks) @@ -72,7 +72,7 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, if (PARAM.inp.deepks_scf) { ModuleBase::matrix wg_hl; - wg_hl.create(nspin, GlobalV::NBANDS); + wg_hl.create(nspin, PARAM.inp.nbands); std::vector> dm_bandgap_gamma; @@ -275,7 +275,7 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, if (PARAM.inp.deepks_bandgap) { - int nocc = GlobalV::nelec / 2; + int nocc = PARAM.inp.nelec / 2; ModuleBase::matrix deepks_bands; deepks_bands.create(nks, 1); for (int iks = 0; iks < nks; iks++) @@ -291,9 +291,9 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot, if (PARAM.inp.deepks_scf) { - int nocc = GlobalV::nelec / 2; + int nocc = PARAM.inp.nelec / 2; ModuleBase::matrix wg_hl; - wg_hl.create(nks, GlobalV::NBANDS); + wg_hl.create(nks, PARAM.inp.nbands); std::vector> dm_bandgap_k; dm_bandgap_k.resize(1); diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_odelta.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_odelta.cpp index e51f8a66d3..7f9885d76f 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_odelta.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_odelta.cpp @@ -19,9 +19,9 @@ void LCAO_Deepks::cal_o_delta(const std::vector> this->o_delta.zero_out(); for (int hl = 0; hl < 1; ++hl) { - for (int i = 0; i < GlobalV::NLOCAL; ++i) + for (int i = 0; i < PARAM.globalv.nlocal; ++i) { - for (int j = 0; j < GlobalV::NLOCAL; ++j) + for (int j = 0; j < PARAM.globalv.nlocal; ++j) { const int mu = pv->global2local_row(j); const int nu = pv->global2local_col(i); @@ -54,9 +54,9 @@ void LCAO_Deepks::cal_o_delta_k(const std::vector o_delta_k=std::complex(0.0,0.0); - for (int i = 0; i < GlobalV::NLOCAL; ++i) + for (int i = 0; i < PARAM.globalv.nlocal; ++i) { - for (int j = 0; j < GlobalV::NLOCAL; ++j) + for (int j = 0; j < PARAM.globalv.nlocal; ++j) { const int mu = pv->global2local_row(j); const int nu = pv->global2local_col(i); diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_vdelta.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_vdelta.cpp index 90b4687778..459ff5c10d 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_vdelta.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_vdelta.cpp @@ -22,9 +22,9 @@ void LCAO_Deepks::cal_e_delta_band(const std::vector>& dm) { ModuleBase::TITLE("LCAO_Deepks", "cal_e_delta_band"); this->e_delta_band = 0; - for (int i = 0; i < GlobalV::NLOCAL; ++i) + for (int i = 0; i < PARAM.globalv.nlocal; ++i) { - for (int j = 0; j < GlobalV::NLOCAL; ++j) + for (int j = 0; j < PARAM.globalv.nlocal; ++j) { const int mu = pv->global2local_row(j); const int nu = pv->global2local_col(i); @@ -54,9 +54,9 @@ void LCAO_Deepks::cal_e_delta_band_k(const std::vector e_delta_band_k=std::complex(0.0,0.0); - for (int i = 0; i < GlobalV::NLOCAL; ++i) + for (int i = 0; i < PARAM.globalv.nlocal; ++i) { - for (int j = 0; j < GlobalV::NLOCAL; ++j) + for (int j = 0; j < PARAM.globalv.nlocal; ++j) { const int mu = pv->global2local_row(j); const int nu = pv->global2local_col(i); diff --git a/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test.cpp b/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test.cpp index 59f2a54094..010da2073d 100644 --- a/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test.cpp +++ b/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test.cpp @@ -45,11 +45,11 @@ void test_deepks::read_dm() { std::ifstream ifs("dm"); dm.resize(1); - dm[0].create(GlobalV::NLOCAL, GlobalV::NLOCAL); + dm[0].create(PARAM.sys.nlocal, PARAM.sys.nlocal); - for (int mu = 0; mu < GlobalV::NLOCAL; mu++) + for (int mu = 0; mu < PARAM.sys.nlocal; mu++) { - for (int nu = 0; nu < GlobalV::NLOCAL; nu++) + for (int nu = 0; nu < PARAM.sys.nlocal; nu++) { double c; ifs >> c; @@ -67,11 +67,11 @@ void test_deepks::read_dm_k(const int nks) ss.str(""); ss << "dm_" << ik; std::ifstream ifs(ss.str().c_str()); - dm_k[ik].create(GlobalV::NLOCAL, GlobalV::NLOCAL); + dm_k[ik].create(PARAM.sys.nlocal, PARAM.sys.nlocal); - for (int mu = 0; mu < GlobalV::NLOCAL; mu++) + for (int mu = 0; mu < PARAM.sys.nlocal; mu++) { - for (int nu = 0; nu < GlobalV::NLOCAL; nu++) + for (int nu = 0; nu < PARAM.sys.nlocal; nu++) { std::complex c; ifs >> c; diff --git a/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test_prep.cpp b/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test_prep.cpp index 593f628464..f97e26a0ea 100644 --- a/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test_prep.cpp +++ b/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test_prep.cpp @@ -16,7 +16,7 @@ void test_deepks::preparation() this->set_orbs(ucell.lat0); this->prep_neighbour(); - this->ParaO.set_serial(GlobalV::NLOCAL, GlobalV::NLOCAL); + this->ParaO.set_serial(PARAM.sys.nlocal, PARAM.sys.nlocal); } void test_deepks::set_parameters() diff --git a/source/module_hamilt_lcao/module_dftu/dftu.cpp b/source/module_hamilt_lcao/module_dftu/dftu.cpp index d3a6e09dc0..5bae255122 100644 --- a/source/module_hamilt_lcao/module_dftu/dftu.cpp +++ b/source/module_hamilt_lcao/module_dftu/dftu.cpp @@ -57,7 +57,7 @@ void DFTU::init(UnitCell& cell, // unitcell class // needs reconstructions in future // global parameters, need to be removed in future const int npol = PARAM.globalv.npol; // number of polarization directions - const int nlocal = GlobalV::NLOCAL; // number of total local orbitals + const int nlocal = PARAM.globalv.nlocal; // number of total local orbitals const int nspin = PARAM.inp.nspin; // number of spins this->EU = 0.0; diff --git a/source/module_hamilt_lcao/module_dftu/dftu_force.cpp b/source/module_hamilt_lcao/module_dftu/dftu_force.cpp index 15d9d02902..89ac1b8192 100644 --- a/source/module_hamilt_lcao/module_dftu/dftu_force.cpp +++ b/source/module_hamilt_lcao/module_dftu/dftu_force.cpp @@ -81,7 +81,7 @@ void DFTU::force_stress(const elecstate::ElecState* pelec, ModuleBase::TITLE("DFTU", "force_stress"); ModuleBase::timer::tick("DFTU", "force_stress"); - const int nlocal = GlobalV::NLOCAL; + const int nlocal = PARAM.globalv.nlocal; if (PARAM.inp.cal_force) { @@ -272,9 +272,9 @@ void DFTU::cal_force_k(ForceStressArrays& fsr, #ifdef __MPI pzgemm_(&transN, &transC, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, &one, &dSm_k[0], &one_int, @@ -310,9 +310,9 @@ void DFTU::cal_force_k(ForceStressArrays& fsr, #ifdef __MPI pzgemm_(&transN, &transN, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, &one, &dSm_k[0], &one_int, @@ -384,7 +384,7 @@ void DFTU::cal_stress_k(ForceStressArrays& fsr, ModuleBase::TITLE("DFTU", "cal_stress_k"); ModuleBase::timer::tick("DFTU", "cal_stress_k"); - const int nlocal = GlobalV::NLOCAL; + const int nlocal = PARAM.globalv.nlocal; const char transN = 'N'; const int one_int = 1; @@ -483,9 +483,9 @@ void DFTU::cal_force_gamma(const double* rho_VU, #ifdef __MPI pdgemm_(&transN, &transT, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, &one, tmp_ptr, &one_int, @@ -521,9 +521,9 @@ void DFTU::cal_force_gamma(const double* rho_VU, #ifdef __MPI pdgemm_(&transN, &transT, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, &one, tmp_ptr, &one_int, @@ -610,7 +610,7 @@ void DFTU::cal_stress_gamma(const UnitCell& ucell, std::vector dSR_gamma(pv.nloc); std::vector dm_VU_sover(pv.nloc); - const int nlocal = GlobalV::NLOCAL; + const int nlocal = PARAM.globalv.nlocal; for (int dim1 = 0; dim1 < 3; dim1++) { diff --git a/source/module_hamilt_lcao/module_dftu/dftu_hamilt.cpp b/source/module_hamilt_lcao/module_dftu/dftu_hamilt.cpp index 717dcb853c..c350aef529 100644 --- a/source/module_hamilt_lcao/module_dftu/dftu_hamilt.cpp +++ b/source/module_hamilt_lcao/module_dftu/dftu_hamilt.cpp @@ -1,5 +1,6 @@ #include "dftu.h" #include "module_base/scalapack_connector.h" +#include "module_parameter/parameter.h" #include "module_base/timer.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" @@ -34,7 +35,7 @@ void DFTU::cal_eff_pot_mat_complex(const int ik, std::complex* eff_pot, #ifdef __MPI pzgemm_(&transN, &transN, - &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, &PARAM.globalv.nlocal, &PARAM.globalv.nlocal, &half, ModuleBase::GlobalFunc::VECTOR_TO_PTR(VU), &one_int, &one_int, this->paraV->desc, sk, &one_int, &one_int, this->paraV->desc, @@ -46,7 +47,7 @@ void DFTU::cal_eff_pot_mat_complex(const int ik, std::complex* eff_pot, VU[irc] = eff_pot[irc]; #ifdef __MPI - pztranc_(&GlobalV::NLOCAL, &GlobalV::NLOCAL, + pztranc_(&PARAM.globalv.nlocal, &PARAM.globalv.nlocal, &one, &VU[0], &one_int, &one_int, this->paraV->desc, &one, @@ -83,7 +84,7 @@ void DFTU::cal_eff_pot_mat_real(const int ik, double* eff_pot, const std::vector #ifdef __MPI pdgemm_(&transN, &transN, - &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, &PARAM.globalv.nlocal, &PARAM.globalv.nlocal, &half, ModuleBase::GlobalFunc::VECTOR_TO_PTR(VU), &one_int, &one_int, this->paraV->desc, sk, &one_int, &one_int, this->paraV->desc, @@ -95,7 +96,7 @@ void DFTU::cal_eff_pot_mat_real(const int ik, double* eff_pot, const std::vector VU[irc] = eff_pot[irc]; #ifdef __MPI - pdtran_(&GlobalV::NLOCAL, &GlobalV::NLOCAL, + pdtran_(&PARAM.globalv.nlocal, &PARAM.globalv.nlocal, &one, &VU[0], &one_int, &one_int, const_cast(this->paraV->desc), &one, @@ -117,7 +118,7 @@ void DFTU::cal_eff_pot_mat_R_double(const int ispin, double* SR, double* HR) #ifdef __MPI pdgemm_(&transN, &transN, - &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, &PARAM.globalv.nlocal, &PARAM.globalv.nlocal, &half, ModuleBase::GlobalFunc::VECTOR_TO_PTR(VU), &one_int, &one_int, this->paraV->desc, SR, &one_int, &one_int, this->paraV->desc, @@ -125,7 +126,7 @@ void DFTU::cal_eff_pot_mat_R_double(const int ispin, double* SR, double* HR) HR, &one_int, &one_int, this->paraV->desc); pdgemm_(&transN, &transN, - &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, &PARAM.globalv.nlocal, &PARAM.globalv.nlocal, &half, SR, &one_int, &one_int, this->paraV->desc, ModuleBase::GlobalFunc::VECTOR_TO_PTR(VU), &one_int, &one_int, this->paraV->desc, @@ -147,7 +148,7 @@ void DFTU::cal_eff_pot_mat_R_complex_double(const int ispin, std::complexparaV->desc, SR, &one_int, &one_int, this->paraV->desc, @@ -155,7 +156,7 @@ void DFTU::cal_eff_pot_mat_R_complex_double(const int ispin, std::complexparaV->desc); pzgemm_(&transN, &transN, - &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, &PARAM.globalv.nlocal, &PARAM.globalv.nlocal, &half, SR, &one_int, &one_int, this->paraV->desc, ModuleBase::GlobalFunc::VECTOR_TO_PTR(VU), &one_int, &one_int, this->paraV->desc, diff --git a/source/module_hamilt_lcao/module_dftu/dftu_occup.cpp b/source/module_hamilt_lcao/module_dftu/dftu_occup.cpp index 8e3b2ee206..396fd7355f 100644 --- a/source/module_hamilt_lcao/module_dftu/dftu_occup.cpp +++ b/source/module_hamilt_lcao/module_dftu/dftu_occup.cpp @@ -175,9 +175,9 @@ void DFTU::cal_occup_m_k(const int iter, #ifdef __MPI pzgemm_(&transN, &transT, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, &alpha, s_k_pointer, &one_int, @@ -376,9 +376,9 @@ void DFTU::cal_occup_m_gamma(const int iter, const std::vectorgridt->max_atom > 0) { #ifdef __CUDA - if (PARAM.globalv.device_flag == "gpu" + if (PARAM.inp.device == "gpu" && (inout->job == Gint_Tools::job_type::vlocal || inout->job == Gint_Tools::job_type::rho || inout->job == Gint_Tools::job_type::force)) { diff --git a/source/module_hamilt_lcao/module_gint/gint_k_sparse1.cpp b/source/module_hamilt_lcao/module_gint/gint_k_sparse1.cpp index 24caf2e7ba..9f1db918fc 100644 --- a/source/module_hamilt_lcao/module_gint/gint_k_sparse1.cpp +++ b/source/module_hamilt_lcao/module_gint/gint_k_sparse1.cpp @@ -58,7 +58,7 @@ void Gint_k::distribute_pvdpR_sparseMatrix( // Parallel_Reduce::reduce_pool(minus_nonzero_num, total_R_num); double* tmp = nullptr; - tmp = new double[GlobalV::NLOCAL]; + tmp = new double[PARAM.globalv.nlocal]; count = 0; for (auto& R_coor: HS_Arrays.all_R_coor) @@ -67,9 +67,9 @@ void Gint_k::distribute_pvdpR_sparseMatrix( { auto minus_R_coor = -1 * R_coor; - for (int row = 0; row < GlobalV::NLOCAL; ++row) + for (int row = 0; row < PARAM.globalv.nlocal; ++row) { - ModuleBase::GlobalFunc::ZEROS(tmp, GlobalV::NLOCAL); + ModuleBase::GlobalFunc::ZEROS(tmp, PARAM.globalv.nlocal); auto iter = pvdpR_sparseMatrix.find(R_coor); if (iter != pvdpR_sparseMatrix.end()) @@ -108,11 +108,11 @@ void Gint_k::distribute_pvdpR_sparseMatrix( } } - Parallel_Reduce::reduce_pool(tmp, GlobalV::NLOCAL); + Parallel_Reduce::reduce_pool(tmp, PARAM.globalv.nlocal); if (pv->global2local_row(row) >= 0) { - for (int col = 0; col < GlobalV::NLOCAL; ++col) + for (int col = 0; col < PARAM.globalv.nlocal; ++col) { if (pv->global2local_col(col) >= 0) { @@ -212,7 +212,7 @@ void Gint_k::distribute_pvdpR_soc_sparseMatrix( // Parallel_Reduce::reduce_pool(minus_nonzero_num, total_R_num); std::complex* tmp_soc = nullptr; - tmp_soc = new std::complex[GlobalV::NLOCAL]; + tmp_soc = new std::complex[PARAM.globalv.nlocal]; count = 0; for (auto& R_coor: HS_Arrays.all_R_coor) @@ -221,9 +221,9 @@ void Gint_k::distribute_pvdpR_soc_sparseMatrix( { auto minus_R_coor = -1 * R_coor; - for (int row = 0; row < GlobalV::NLOCAL; ++row) + for (int row = 0; row < PARAM.globalv.nlocal; ++row) { - ModuleBase::GlobalFunc::ZEROS(tmp_soc, GlobalV::NLOCAL); + ModuleBase::GlobalFunc::ZEROS(tmp_soc, PARAM.globalv.nlocal); auto iter = pvdpR_soc_sparseMatrix.find(R_coor); if (iter != pvdpR_soc_sparseMatrix.end()) @@ -261,11 +261,11 @@ void Gint_k::distribute_pvdpR_soc_sparseMatrix( } } - Parallel_Reduce::reduce_pool(tmp_soc, GlobalV::NLOCAL); + Parallel_Reduce::reduce_pool(tmp_soc, PARAM.globalv.nlocal); if (pv->global2local_row(row) >= 0) { - for (int col = 0; col < GlobalV::NLOCAL; ++col) + for (int col = 0; col < PARAM.globalv.nlocal; ++col) { if (pv->global2local_col(col) >= 0) { diff --git a/source/module_hamilt_lcao/module_gint/grid_technique.cpp b/source/module_hamilt_lcao/module_gint/grid_technique.cpp index c66c47a24f..eca316eb58 100644 --- a/source/module_hamilt_lcao/module_gint/grid_technique.cpp +++ b/source/module_hamilt_lcao/module_gint/grid_technique.cpp @@ -13,7 +13,7 @@ Grid_Technique::Grid_Technique() { allocate_find_R2 = false; #if ((defined __CUDA) /* || (defined __ROCM) */) - if (PARAM.globalv.device_flag == "gpu") { + if (PARAM.inp.device == "gpu") { is_malloced = false; } #endif @@ -22,7 +22,7 @@ Grid_Technique::Grid_Technique() { Grid_Technique::~Grid_Technique() { #if ((defined __CUDA) /* || (defined __ROCM) */) - if (PARAM.globalv.device_flag == "gpu") { + if (PARAM.inp.device == "gpu") { free_gpu_gint_variables(this->nat); } #endif @@ -118,7 +118,7 @@ void Grid_Technique::set_pbc_grid( this->cal_trace_lo(ucell); #if ((defined __CUDA) /* || (defined __ROCM) */) - if (PARAM.globalv.device_flag == "gpu") { + if (PARAM.inp.device == "gpu") { this->init_gpu_gint_variables(ucell, num_stream); } #endif @@ -485,8 +485,8 @@ void Grid_Technique::cal_trace_lo(const UnitCell& ucell) { // save the atom information in trace_lo, // in fact the trace_lo dimension can be reduced // to ucell.nat, but I think this is another way. - this->trace_lo = std::vector(GlobalV::NLOCAL, -1); - ModuleBase::Memory::record("GT::trace_lo", sizeof(int) * GlobalV::NLOCAL); + this->trace_lo = std::vector(PARAM.globalv.nlocal, -1); + ModuleBase::Memory::record("GT::trace_lo", sizeof(int) * PARAM.globalv.nlocal); this->lnat = 0; this->lgd = 0; @@ -533,7 +533,7 @@ void Grid_Technique::cal_trace_lo(const UnitCell& ucell) { } assert(iw_local == lgd); - assert(iw_all == GlobalV::NLOCAL); + assert(iw_all == PARAM.globalv.nlocal); return; } diff --git a/source/module_hamilt_pw/hamilt_pwdft/VNL_in_pw.cpp b/source/module_hamilt_pw/hamilt_pwdft/VNL_in_pw.cpp index b27b62459e..1b3f92b60a 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/VNL_in_pw.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/VNL_in_pw.cpp @@ -32,7 +32,7 @@ void pseudopot_cell_vnl::release_memory() if (this->nhm <= 0 || memory_released) { return; } - if (PARAM.globalv.device_flag == "gpu") + if (PARAM.inp.device == "gpu") { if (PARAM.inp.precision == "single") { @@ -153,7 +153,7 @@ void pseudopot_cell_vnl::init(const int ntype, this->deeq_nc.create(PARAM.inp.nspin, GlobalC::ucell.nat, this->nhm, this->nhm); this->qq_nt.create(ntype, this->nhm, this->nhm); this->qq_so.create(ntype, 4, this->nhm, this->nhm); - if (PARAM.globalv.device_flag == "gpu") + if (PARAM.inp.device == "gpu") { if (PARAM.inp.precision == "single") { @@ -270,7 +270,7 @@ void pseudopot_cell_vnl::init(const int ntype, ModuleBase::Memory::record("VNL::tab_at", ntype * nchix_nc * PARAM.globalv.nqx * sizeof(double)); } } - if (PARAM.globalv.device_flag == "gpu") + if (PARAM.inp.device == "gpu") { if (PARAM.inp.precision == "single") { @@ -464,7 +464,7 @@ void pseudopot_cell_vnl::getvnl(Device* ctx, const int& ik, std::complex { _gk[ig] = this->wfcpw->getgpluskcar(ik, ig); } - if (PARAM.globalv.device_flag == "gpu") + if (PARAM.inp.device == "gpu") { resmem_int_op()(ctx, atom_nh, GlobalC::ucell.ntype); resmem_int_op()(ctx, atom_nb, GlobalC::ucell.ntype); @@ -721,7 +721,7 @@ void pseudopot_cell_vnl::init_vnl(UnitCell& cell, const ModulePW::PW_Basis* rho_ // g) It computes the qq terms which define the S matrix. // compute Clebsch-Gordan coefficients - if (GlobalV::use_uspp) + if (PARAM.globalv.use_uspp) { ModuleBase::Clebsch_Gordan::clebsch_gordan(lmaxkb + 1, ap, lpx, lpl); } @@ -861,7 +861,7 @@ void pseudopot_cell_vnl::init_vnl(UnitCell& cell, const ModulePW::PW_Basis* rho_ delete[] aux; delete[] jl; } - if (PARAM.globalv.device_flag == "gpu") + if (PARAM.inp.device == "gpu") { if (PARAM.inp.precision == "single") { @@ -1387,7 +1387,7 @@ void pseudopot_cell_vnl::cal_effective_D(const ModuleBase::matrix& veff, 3. rotate to effective matrix when spin-orbital coupling is used */ - if (!GlobalV::use_uspp) + if (!PARAM.globalv.use_uspp) { for (int iat = 0; iat < cell.nat; iat++) { @@ -1479,7 +1479,7 @@ void pseudopot_cell_vnl::cal_effective_D(const ModuleBase::matrix& veff, } } } - if (PARAM.globalv.device_flag == "gpu") + if (PARAM.inp.device == "gpu") { if (PARAM.inp.precision == "single") { diff --git a/source/module_hamilt_pw/hamilt_pwdft/elecond.cpp b/source/module_hamilt_pw/hamilt_pwdft/elecond.cpp index 4307018260..f7ac5000d4 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/elecond.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/elecond.cpp @@ -97,7 +97,7 @@ void EleCond::KG(const int& smear_type, const double& fwhmin, const double& wcut void EleCond::jjresponse_ks(const int ik, const int nt, const double dt, const double decut, ModuleBase::matrix& wg, hamilt::Velocity& velop, double* ct11, double* ct12, double* ct22) { - const int nbands = GlobalV::NBANDS; + const int nbands = PARAM.inp.nbands; if (wg(ik, 0) - wg(ik, nbands - 1) < 1e-8 || nbands == 0) { return; } diff --git a/source/module_hamilt_pw/hamilt_pwdft/forces.cpp b/source/module_hamilt_pw/hamilt_pwdft/forces.cpp index 0e7ed6b229..589fc71009 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/forces.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/forces.cpp @@ -69,7 +69,7 @@ void Forces::cal_force(ModuleBase::matrix& force, this->npwx = wfc_basis->npwk_max; Forces::cal_force_nl(forcenl, wg, ekb, pkv, wfc_basis, p_sf, &GlobalC::ppcell, GlobalC::ucell, psi_in); - if (GlobalV::use_uspp) + if (PARAM.globalv.use_uspp) { this->cal_force_us(forcenl, rho_basis, &GlobalC::ppcell, elec, GlobalC::ucell); } @@ -134,9 +134,9 @@ void Forces::cal_force(ModuleBase::matrix& force, psi_in[0].fix_k(ik); double *weight, *epsilon; - weight = new double[GlobalV::NBANDS]; - epsilon = new double[GlobalV::NBANDS]; - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + weight = new double[PARAM.inp.nbands]; + epsilon = new double[PARAM.inp.nbands]; + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { weight[ib] = wg(ik, ib); epsilon[ib] = ekb(ik, ib); @@ -144,7 +144,7 @@ void Forces::cal_force(ModuleBase::matrix& force, GlobalC::paw_cell.paw_nl_force(reinterpret_cast*>(psi_in[0].get_pointer()), epsilon, weight, - GlobalV::NBANDS, + PARAM.inp.nbands, forcenl.c); delete[] weight; diff --git a/source/module_hamilt_pw/hamilt_pwdft/fs_nonlocal_tools.cpp b/source/module_hamilt_pw/hamilt_pwdft/fs_nonlocal_tools.cpp index 5e4d54b86f..cc05bc8e52 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/fs_nonlocal_tools.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/fs_nonlocal_tools.cpp @@ -32,7 +32,7 @@ FS_Nonlocal_tools::FS_Nonlocal_tools(const pseudopot_cell_vnl* n // There is a contribution for jh<>ih in US case or multi projectors case // Actually, the judge of nondiagonal should be done on every atom type - this->nondiagonal = (GlobalV::use_uspp || this->nlpp_->multi_proj) ? true : false; + this->nondiagonal = (PARAM.globalv.use_uspp || this->nlpp_->multi_proj) ? true : false; // allocate memory this->allocate_memory(wg, ekb); diff --git a/source/module_hamilt_pw/hamilt_pwdft/hamilt_pw.cpp b/source/module_hamilt_pw/hamilt_pwdft/hamilt_pw.cpp index 725591c990..db877bac07 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/hamilt_pw.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/hamilt_pw.cpp @@ -225,7 +225,7 @@ void HamiltPW::sPsi(const T* psi_in, // psi } syncmem_op()(this->ctx, this->ctx, spsi, psi_in, static_cast(nbands * nrow)); - if (GlobalV::use_uspp) + if (PARAM.globalv.use_uspp) { T* becp = nullptr; T* ps = nullptr; diff --git a/source/module_hamilt_pw/hamilt_pwdft/kernels/force_op.h b/source/module_hamilt_pw/hamilt_pwdft/kernels/force_op.h index b04b769df8..885997222c 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/kernels/force_op.h +++ b/source/module_hamilt_pw/hamilt_pwdft/kernels/force_op.h @@ -1,5 +1,6 @@ #ifndef W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_HAMILT_PW_HAMILT_PWDFT_KERNELS_FORCE_OP_H #define W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_HAMILT_PW_HAMILT_PWDFT_KERNELS_FORCE_OP_H +#include "module_parameter/parameter.h" #include "module_psi/psi.h" @@ -64,8 +65,8 @@ struct cal_force_nl_op /// @param d_ekb - input parameter ekb /// @param qq_nt - GlobalC::ppcell.qq_nt /// @param deeq - GlobalC::ppcell.deeq - /// @param becp - intermediate matrix with GlobalV::NBANDS * nkb - /// @param dbecp - intermediate matrix with 3 * GlobalV::NBANDS * nkb + /// @param becp - intermediate matrix with PARAM.inp.nbands * nkb + /// @param dbecp - intermediate matrix with 3 * PARAM.inp.nbands * nkb /// /// Output Parameters /// @param force - output forces diff --git a/source/module_hamilt_pw/hamilt_pwdft/kernels/stress_op.h b/source/module_hamilt_pw/hamilt_pwdft/kernels/stress_op.h index 62e373f1ff..3603b16cac 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/kernels/stress_op.h +++ b/source/module_hamilt_pw/hamilt_pwdft/kernels/stress_op.h @@ -1,5 +1,6 @@ #ifndef SRC_PW_STRESS_MULTI_DEVICE_H #define SRC_PW_STRESS_MULTI_DEVICE_H +#include "module_parameter/parameter.h" #include "module_psi/psi.h" @@ -76,8 +77,8 @@ struct cal_stress_nl_op /// @param d_ekb - input parameter ekb /// @param qq_nt - GlobalC::ppcell.qq_nt /// @param deeq - GlobalC::ppcell.deeq - /// @param becp - intermediate matrix with GlobalV::NBANDS * nkb - /// @param dbecp - intermediate matrix with 3 * GlobalV::NBANDS * nkb + /// @param becp - intermediate matrix with PARAM.inp.nbands * nkb + /// @param dbecp - intermediate matrix with 3 * PARAM.inp.nbands * nkb /// /// Output Parameters /// @param stress - output stresses diff --git a/source/module_hamilt_pw/hamilt_pwdft/stress_func_kin.cpp b/source/module_hamilt_pw/hamilt_pwdft/stress_func_kin.cpp index bca76a5ff0..48a212d3ef 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/stress_func_kin.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/stress_func_kin.cpp @@ -1,5 +1,6 @@ #include "stress_func.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_parameter/parameter.h" #include "module_base/timer.h" //calculate the kinetic stress in PW base @@ -69,7 +70,7 @@ void Stress_Func::stress_kin(ModuleBase::matrix& sigma, { for (int m = 0; m < l + 1; m++) { - for (int ibnd = 0; ibnd < GlobalV::NBANDS; ibnd++) + for (int ibnd = 0; ibnd < PARAM.inp.nbands; ibnd++) { if (std::fabs(wg(ik, ibnd)) < ModuleBase::threshold_wg * wg(ik, 0)) continue; diff --git a/source/module_hamilt_pw/hamilt_pwdft/stress_func_mgga.cpp b/source/module_hamilt_pw/hamilt_pwdft/stress_func_mgga.cpp index 56ef7ebd86..352634bee1 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/stress_func_mgga.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/stress_func_mgga.cpp @@ -19,8 +19,9 @@ void Stress_Func::stress_mgga(ModuleBase::matrix& sigma, { ModuleBase::timer::tick("Stress_Func", "stress_mgga"); - if (PARAM.inp.nspin == 4) + if (PARAM.inp.nspin == 4) { ModuleBase::WARNING_QUIT("stress_mgga", "noncollinear stress + mGGA not implemented"); +} int current_spin = 0; const int nrxx = wfc_basis->nrxx; @@ -44,11 +45,12 @@ void Stress_Func::stress_mgga(ModuleBase::matrix& sigma, auto cal_stress_mgga_solver = hamilt::cal_stress_mgga_op, Device>(); for (int ik = 0; ik < p_kv->get_nks(); ik++) { - if (PARAM.inp.nspin == 2) + if (PARAM.inp.nspin == 2) { current_spin = p_kv->isk[ik]; +} const int npw = p_kv->ngk[ik]; - for (int ibnd = 0; ibnd < GlobalV::NBANDS; ibnd++) + for (int ibnd = 0; ibnd < PARAM.inp.nbands; ibnd++) { const FPTYPE w1 = wg(ik, ibnd) / GlobalC::ucell.omega; const std::complex* psi = &psi_in[0](ik, ibnd, 0); @@ -85,8 +87,9 @@ void Stress_Func::stress_mgga(ModuleBase::matrix& sigma, for (int iy = 0; iy < 3; iy++) { FPTYPE delta = 0.0; - if (ix == iy) + if (ix == iy) { delta = 1.0; +} for (int ir = 0; ir < nrxx; ir++) { FPTYPE x diff --git a/source/module_hamilt_pw/hamilt_pwdft/stress_pw.cpp b/source/module_hamilt_pw/hamilt_pwdft/stress_pw.cpp index 2f1d90361e..b56553c708 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/stress_pw.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/stress_pw.cpp @@ -99,7 +99,7 @@ void Stress_PW::cal_stress(ModuleBase::matrix& sigmatot, this->stress_nl(sigmanl, this->pelec->wg, this->pelec->ekb, p_sf, p_kv, p_symm, wfc_basis, d_psi_in, nlpp, ucell); // add US term from augmentation charge derivatives - if (GlobalV::use_uspp) + if (PARAM.globalv.use_uspp) { this->stress_us(sigmanl, rho_basis, &GlobalC::ppcell, ucell); } diff --git a/source/module_hamilt_pw/hamilt_pwdft/structure_factor.cpp b/source/module_hamilt_pw/hamilt_pwdft/structure_factor.cpp index 575cb53508..163d6ca210 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/structure_factor.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/structure_factor.cpp @@ -21,7 +21,7 @@ Structure_Factor::Structure_Factor() Structure_Factor::~Structure_Factor() { - if (PARAM.globalv.device_flag == "gpu") { + if (PARAM.inp.device == "gpu") { if (PARAM.inp.precision == "single") { delmem_cd_op()(gpu_ctx, this->c_eigts1); delmem_cd_op()(gpu_ctx, this->c_eigts2); @@ -145,7 +145,7 @@ void Structure_Factor::setup_structure_factor(UnitCell* Ucell, const ModulePW::P inat++; } } - if (PARAM.globalv.device_flag == "gpu") { + if (PARAM.inp.device == "gpu") { if (PARAM.inp.precision == "single") { resmem_cd_op()(gpu_ctx, this->c_eigts1, Ucell->nat * (2 * rho_basis->nx + 1)); resmem_cd_op()(gpu_ctx, this->c_eigts2, Ucell->nat * (2 * rho_basis->ny + 1)); diff --git a/source/module_hamilt_pw/hamilt_pwdft/wavefunc.cpp b/source/module_hamilt_pw/hamilt_pwdft/wavefunc.cpp index 00c0bded36..41e110885c 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/wavefunc.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/wavefunc.cpp @@ -55,15 +55,15 @@ psi::Psi>* wavefunc::allocate(const int nkstot, const int n if (PARAM.inp.calculation == "nscf" && this->mem_saver == 1) { // initial psi rather than evc - psi_out = new psi::Psi>(1, GlobalV::NBANDS, npwx * PARAM.globalv.npol, ngk); + psi_out = new psi::Psi>(1, PARAM.inp.nbands, npwx * PARAM.globalv.npol, ngk); if (PARAM.inp.basis_type == "lcao_in_pw") { - wanf2[0].create(GlobalV::NLOCAL, npwx * PARAM.globalv.npol); - const size_t memory_cost = GlobalV::NLOCAL * (PARAM.globalv.npol * npwx) * sizeof(std::complex); + wanf2[0].create(PARAM.globalv.nlocal, npwx * PARAM.globalv.npol); + const size_t memory_cost = PARAM.globalv.nlocal * (PARAM.globalv.npol * npwx) * sizeof(std::complex); std::cout << " Memory for wanf2 (MB): " << double(memory_cost) / 1024.0 / 1024.0 << std::endl; ModuleBase::Memory::record("WF::wanf2", memory_cost); } - const size_t memory_cost = GlobalV::NBANDS * (PARAM.globalv.npol * npwx) * sizeof(std::complex); + const size_t memory_cost = PARAM.inp.nbands * (PARAM.globalv.npol * npwx) * sizeof(std::complex); std::cout << " MEMORY FOR PSI (MB) : " << double(memory_cost) / 1024.0 / 1024.0 << std::endl; ModuleBase::Memory::record("Psi_PW", memory_cost); } @@ -79,10 +79,10 @@ psi::Psi>* wavefunc::allocate(const int nkstot, const int n for (int ik = 0; ik < nks2; ik++) { - this->wanf2[ik].create(GlobalV::NLOCAL, npwx * PARAM.globalv.npol); + this->wanf2[ik].create(PARAM.globalv.nlocal, npwx * PARAM.globalv.npol); } - const size_t memory_cost = nks2 * GlobalV::NLOCAL * (npwx * PARAM.globalv.npol) * sizeof(std::complex); + const size_t memory_cost = nks2 * PARAM.globalv.nlocal * (npwx * PARAM.globalv.npol) * sizeof(std::complex); std::cout << " Memory for wanf2 (MB): " << double(memory_cost) / 1024.0 / 1024.0 << std::endl; ModuleBase::Memory::record("WF::wanf2", memory_cost); } @@ -90,8 +90,8 @@ psi::Psi>* wavefunc::allocate(const int nkstot, const int n else { // initial psi rather than evc - psi_out = new psi::Psi>(nks2, GlobalV::NBANDS, npwx * PARAM.globalv.npol, ngk); - const size_t memory_cost = nks2 * GlobalV::NBANDS * (PARAM.globalv.npol * npwx) * sizeof(std::complex); + psi_out = new psi::Psi>(nks2, PARAM.inp.nbands, npwx * PARAM.globalv.npol, ngk); + const size_t memory_cost = nks2 * PARAM.inp.nbands * (PARAM.globalv.npol * npwx) * sizeof(std::complex); std::cout << " MEMORY FOR PSI (MB) : " << double(memory_cost) / 1024.0 / 1024.0 << std::endl; ModuleBase::Memory::record("Psi_PW", memory_cost); } @@ -117,7 +117,7 @@ void wavefunc::wfcinit(psi::Psi>* psi_in, ModulePW::PW_Basi this->irindex = new int[wfc_basis->fftnxy]; wfc_basis->getfftixy2is(this->irindex); #if defined(__CUDA) || defined(__ROCM) - if (PARAM.globalv.device_flag == "gpu") + if (PARAM.inp.device == "gpu") { wfc_basis->get_ig2ixyz_k(); } @@ -131,11 +131,11 @@ int wavefunc::get_starting_nw() const { if (init_wfc == "file") { - return GlobalV::NBANDS; + return PARAM.inp.nbands; } else if (init_wfc.substr(0, 6) == "atomic") { - if (GlobalC::ucell.natomwfc >= GlobalV::NBANDS) + if (GlobalC::ucell.natomwfc >= PARAM.inp.nbands) { if (PARAM.inp.test_wf) { @@ -147,11 +147,11 @@ int wavefunc::get_starting_nw() const if (PARAM.inp.test_wf) { GlobalV::ofs_running << " Start wave functions are atomic + " - << GlobalV::NBANDS - GlobalC::ucell.natomwfc << " random wave functions." + << PARAM.inp.nbands - GlobalC::ucell.natomwfc << " random wave functions." << std::endl; } } - return std::max(GlobalC::ucell.natomwfc, GlobalV::NBANDS); + return std::max(GlobalC::ucell.natomwfc, PARAM.inp.nbands); } else if (init_wfc == "random") { @@ -159,7 +159,7 @@ int wavefunc::get_starting_nw() const { GlobalV::ofs_running << " Start wave functions are all random." << std::endl; } - return GlobalV::NBANDS; + return PARAM.inp.nbands; } else { @@ -728,7 +728,7 @@ void wavefunc::init_after_vc(const int nks) assert(this->npwx > 0); assert(nks > 0); - assert(GlobalV::NBANDS > 0); + assert(PARAM.inp.nbands > 0); const int nks2 = nks; const int nbasis = this->npwx * PARAM.globalv.npol; @@ -742,7 +742,7 @@ void wavefunc::init_after_vc(const int nks) this->wanf2 = new ModuleBase::ComplexMatrix[nks2]; for (int ik = 0; ik < nks2; ik++) { - this->wanf2[ik].create(GlobalV::NLOCAL, nbasis); + this->wanf2[ik].create(PARAM.globalv.nlocal, nbasis); } } diff --git a/source/module_hamilt_pw/hamilt_stodft/sto_dos.cpp b/source/module_hamilt_pw/hamilt_stodft/sto_dos.cpp index 145f7bb89c..550a3fecfe 100644 --- a/source/module_hamilt_pw/hamilt_stodft/sto_dos.cpp +++ b/source/module_hamilt_pw/hamilt_stodft/sto_dos.cpp @@ -108,7 +108,7 @@ void Sto_DOS::caldos(const double sigmain, const double de, const int npart) const int nchipk = this->p_stowf->nchip[ik]; std::complex* pchi; - if (GlobalV::NBANDS > 0) + if (PARAM.inp.nbands > 0) { p_stowf->chiortho->fix_k(ik); pchi = p_stowf->chiortho->get_pointer(); @@ -195,12 +195,12 @@ void Sto_DOS::caldos(const double sigmain, const double de, const int npart) che.calcoef_real(nroot_gauss); tmpsto = vTMv(che.coef_real, spolyv.data(), dos_nche); } - if (GlobalV::NBANDS > 0) + if (PARAM.inp.nbands > 0) { for (int ik = 0; ik < nk; ++ik) { double* en = &(this->p_elec->ekb(ik, 0)); - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) + for (int ib = 0; ib < PARAM.inp.nbands; ++ib) { tmpks += this->stofunc.gauss(en[ib]) * p_kv->wk[ik] / 2; } diff --git a/source/module_hamilt_pw/hamilt_stodft/sto_iter.cpp b/source/module_hamilt_pw/hamilt_stodft/sto_iter.cpp index 13be8b08d2..6e04eee91d 100644 --- a/source/module_hamilt_pw/hamilt_stodft/sto_iter.cpp +++ b/source/module_hamilt_pw/hamilt_stodft/sto_iter.cpp @@ -1,5 +1,6 @@ #include "sto_iter.h" +#include "module_parameter/parameter.h" #include "module_base/parallel_reduce.h" #include "module_base/timer.h" #include "module_base/tool_quit.h" @@ -26,7 +27,7 @@ void Stochastic_Iter::init(K_Vectors* pkv_in, p_che = stoche.p_che; spolyv = stoche.spolyv; nchip = stowf.nchip; - targetne = GlobalV::nelec; + targetne = PARAM.inp.nelec; this->pkv = pkv_in; this->method = stoche.method_sto; @@ -38,7 +39,7 @@ void Stochastic_Iter::orthog(const int& ik, psi::Psi>& psi, { ModuleBase::TITLE("Stochastic_Iter", "orthog"); // orthogonal part - if (GlobalV::NBANDS > 0) + if (PARAM.inp.nbands > 0) { const int nchipk = stowf.nchip[ik]; const int npw = psi.get_current_nbas(); @@ -52,14 +53,14 @@ void Stochastic_Iter::orthog(const int& ik, psi::Psi>& psi, } // orthogonal part - std::complex* sum = new std::complex[GlobalV::NBANDS * nchipk]; + std::complex* sum = new std::complex[PARAM.inp.nbands * nchipk]; char transC = 'C'; char transN = 'N'; // sum(b zgemm_(&transC, &transN, - &GlobalV::NBANDS, + &PARAM.inp.nbands, &nchipk, &npw, &ModuleBase::ONE, @@ -69,20 +70,20 @@ void Stochastic_Iter::orthog(const int& ik, psi::Psi>& psi, &npwx, &ModuleBase::ZERO, sum, - &GlobalV::NBANDS); - Parallel_Reduce::reduce_pool(sum, GlobalV::NBANDS * nchipk); + &PARAM.inp.nbands); + Parallel_Reduce::reduce_pool(sum, PARAM.inp.nbands * nchipk); // psi -= psi * sum zgemm_(&transN, &transN, &npw, &nchipk, - &GlobalV::NBANDS, + &PARAM.inp.nbands, &ModuleBase::NEG_ONE, &psi(ik, 0, 0), &npwx, sum, - &GlobalV::NBANDS, + &PARAM.inp.nbands, &ModuleBase::ONE, wfgout, &npwx); @@ -123,7 +124,7 @@ void Stochastic_Iter::checkemm(const int& ik, const int istep, const int iter, S for (int ichi = 0; ichi < ntest; ++ichi) { - if (GlobalV::NBANDS > 0) + if (PARAM.inp.nbands > 0) { pchi = &stowf.chiortho->operator()(ik, ichi, 0); } @@ -217,13 +218,13 @@ void Stochastic_Iter::itermu(const int iter, elecstate::ElecState* pes) if (iter == 1) { dmu = 2; - th_ne = 0.1 * PARAM.inp.scf_thr * GlobalV::nelec; + th_ne = 0.1 * PARAM.inp.scf_thr * PARAM.inp.nelec; // std::cout<<"th_ne "<stofunc.mu = mu0 - dmu; @@ -288,12 +289,12 @@ void Stochastic_Iter::itermu(const int iter, elecstate::ElecState* pes) this->check_precision(targetne, 10 * PARAM.inp.scf_thr, "Ne"); // Set wf.wg - if (GlobalV::NBANDS > 0) + if (PARAM.inp.nbands > 0) { for (int ikk = 0; ikk < this->pkv->get_nks(); ++ikk) { double* en = &pes->ekb(ikk, 0); - for (int iksb = 0; iksb < GlobalV::NBANDS; ++iksb) + for (int iksb = 0; iksb < PARAM.inp.nbands; ++iksb) { pes->wg(ikk, iksb) = stofunc.fd(en[iksb]) * this->pkv->wk[ikk]; } @@ -324,7 +325,7 @@ void Stochastic_Iter::calPn(const int& ik, Stochastic_WF& stowf) } } std::complex* pchi; - if (GlobalV::NBANDS > 0) + if (PARAM.inp.nbands > 0) { stowf.chiortho->fix_k(ik); pchi = stowf.chiortho->get_pointer(); @@ -385,12 +386,12 @@ double Stochastic_Iter::calne(elecstate::ElecState* pes) p_che->calcoef_real(nroot_fd); sto_ne = vTMv(p_che->coef_real, spolyv, norder); } - if (GlobalV::NBANDS > 0) + if (PARAM.inp.nbands > 0) { for (int ikk = 0; ikk < this->pkv->get_nks(); ++ikk) { double* en = &pes->ekb(ikk, 0); - for (int iksb = 0; iksb < GlobalV::NBANDS; ++iksb) + for (int iksb = 0; iksb < PARAM.inp.nbands; ++iksb) { KS_ne += stofunc.fd(en[iksb]) * this->pkv->wk[ikk]; } @@ -457,13 +458,13 @@ void Stochastic_Iter::sum_stoband(Stochastic_WF& stowf, stodemet = -vTMv(p_che->coef_real, spolyv, norder); } - if (GlobalV::NBANDS > 0) + if (PARAM.inp.nbands > 0) { for (int ikk = 0; ikk < this->pkv->get_nks(); ++ikk) { double* enb = &pes->ekb(ikk, 0); // number of electrons in KS orbitals - for (int iksb = 0; iksb < GlobalV::NBANDS; ++iksb) + for (int iksb = 0; iksb < PARAM.inp.nbands; ++iksb) { pes->f_en.demet += stofunc.fdlnfd(enb[iksb]) * this->pkv->wk[ikk]; } @@ -529,7 +530,7 @@ void Stochastic_Iter::sum_stoband(Stochastic_WF& stowf, double out2; double* ksrho = nullptr; - if (GlobalV::NBANDS > 0 && GlobalV::MY_STOGROUP == 0) + if (PARAM.inp.nbands > 0 && GlobalV::MY_STOGROUP == 0) { ksrho = new double[nrxx]; ModuleBase::GlobalFunc::DCOPY(pes->charge->rho[0], ksrho, nrxx); @@ -582,7 +583,7 @@ void Stochastic_Iter::sum_stoband(Stochastic_WF& stowf, if (GlobalV::MY_STOGROUP == 0) { - if (GlobalV::NBANDS > 0) + if (PARAM.inp.nbands > 0) { ModuleBase::GlobalFunc::DCOPY(ksrho, pes->charge->rho[0], nrxx); } @@ -616,7 +617,7 @@ void Stochastic_Iter::calTnchi_ik(const int& ik, Stochastic_WF& stowf) stowf.shchi->fix_k(ik); std::complex* out = stowf.shchi->get_pointer(); std::complex* pchi; - if (GlobalV::NBANDS > 0) + if (PARAM.inp.nbands > 0) { stowf.chiortho->fix_k(ik); pchi = stowf.chiortho->get_pointer(); diff --git a/source/module_hamilt_pw/hamilt_stodft/sto_tool.cpp b/source/module_hamilt_pw/hamilt_stodft/sto_tool.cpp index 1f5675f675..cf3584736d 100644 --- a/source/module_hamilt_pw/hamilt_stodft/sto_tool.cpp +++ b/source/module_hamilt_pw/hamilt_stodft/sto_tool.cpp @@ -26,12 +26,12 @@ void check_che(const int& nche_in, int ntest0 = 5; *stohchi.Emax = try_emax; *stohchi.Emin = try_emin; - // if (GlobalV::NBANDS > 0) + // if (PARAM.inp.nbands > 0) // { // double tmpemin = 1e10; // for (int ik = 0; ik < nk; ++ik) // { - // tmpemin = std::min(tmpemin, this->pelec->ekb(ik, GlobalV::NBANDS - 1)); + // tmpemin = std::min(tmpemin, this->pelec->ekb(ik, PARAM.inp.nbands - 1)); // } // stohchi.Emin = tmpemin; // } @@ -60,7 +60,7 @@ void check_che(const int& nche_in, pchi[ig] = std::complex(rr * cos(arg), rr * sin(arg)); } } - else if (GlobalV::NBANDS > 0) + else if (PARAM.inp.nbands > 0) { pchi = &p_stowf->chiortho[0](ik, i, 0); } diff --git a/source/module_hsolver/diago_cusolver.cpp b/source/module_hsolver/diago_cusolver.cpp index b8abf642d2..5511ec941c 100644 --- a/source/module_hsolver/diago_cusolver.cpp +++ b/source/module_hsolver/diago_cusolver.cpp @@ -1,5 +1,6 @@ #include "diago_cusolver.h" +#include "module_parameter/parameter.h" #include "module_base/blacs_connector.h" #include "module_base/global_variable.h" #include "module_base/scalapack_connector.h" @@ -140,7 +141,7 @@ void DiagoCusolver::diag(hamilt::Hamilt* phm_in, psi::Psi& psi, Real* e #endif // Allocate memory for eigenvalues - std::vector eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); // Start the timer for the cusolver operation ModuleBase::timer::tick("DiagoCusolver", "cusolver"); @@ -170,7 +171,7 @@ void DiagoCusolver::diag(hamilt::Hamilt* phm_in, psi::Psi& psi, Real* e MPI_Barrier(MPI_COMM_WORLD); // broadcast eigenvalues to all processes - MPI_Bcast(eigen.data(), GlobalV::NBANDS, MPI_DOUBLE, root_proc, MPI_COMM_WORLD); + MPI_Bcast(eigen.data(), PARAM.inp.nbands, MPI_DOUBLE, root_proc, MPI_COMM_WORLD); // distribute psi to all processes distributePsi(this->ParaV->desc_wfc, psi.get_pointer(), psi_g.data()); @@ -194,7 +195,7 @@ void DiagoCusolver::diag(hamilt::Hamilt* phm_in, psi::Psi& psi, Real* e // Copy the eigenvalues to the output arrays const int inc = 1; - BlasConnector::copy(GlobalV::NBANDS, eigen.data(), inc, eigenvalue_in, inc); + BlasConnector::copy(PARAM.inp.nbands, eigen.data(), inc, eigenvalue_in, inc); } // Explicit instantiation of the DiagoCusolver class for real and complex numbers diff --git a/source/module_hsolver/diago_cusolvermp.cpp b/source/module_hsolver/diago_cusolvermp.cpp index 84fcdd09ef..09aa85940b 100644 --- a/source/module_hsolver/diago_cusolvermp.cpp +++ b/source/module_hsolver/diago_cusolvermp.cpp @@ -1,5 +1,6 @@ #ifdef __CUSOLVERMP +#include "module_parameter/parameter.h" #include "diago_cusolvermp.h" #include "module_base/timer.h" @@ -15,7 +16,7 @@ void DiagoCusolverMP::diag(hamilt::Hamilt* phm_in, psi::Psi& psi, Real* hamilt::MatrixBlock h_mat, s_mat; phm_in->matrix(h_mat, s_mat); - std::vector eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); std::vector eigenvectors(h_mat.row * h_mat.col); MPI_Comm COMM_DIAG = MPI_COMM_WORLD; // use all processes @@ -27,7 +28,7 @@ void DiagoCusolverMP::diag(hamilt::Hamilt* phm_in, psi::Psi& psi, Real* ModuleBase::timer::tick("DiagoCusolverMP", "Diag_CusolverMP_gvd"); } const int inc = 1; - BlasConnector::copy(GlobalV::NBANDS, eigen.data(), inc, eigenvalue_in, inc); + BlasConnector::copy(PARAM.inp.nbands, eigen.data(), inc, eigenvalue_in, inc); const int size = psi.get_nbands() * psi.get_nbasis(); BlasConnector::copy(size, eigenvectors.data(), inc, psi.get_pointer(), inc); } diff --git a/source/module_hsolver/diago_elpa.cpp b/source/module_hsolver/diago_elpa.cpp index fcfeed43ef..817c1737ca 100644 --- a/source/module_hsolver/diago_elpa.cpp +++ b/source/module_hsolver/diago_elpa.cpp @@ -1,5 +1,6 @@ #include "diago_elpa.h" +#include "module_parameter/parameter.h" #include "genelpa/elpa_solver.h" #include "module_base/blacs_connector.h" #include "module_base/global_variable.h" @@ -74,13 +75,13 @@ void DiagoElpa>::diag( matcd h_mat, s_mat; phm_in->matrix(h_mat, s_mat); - std::vector eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); bool isReal = false; MPI_Comm COMM_DIAG = setmpicomm(); // set mpi_comm needed ELPA_Solver es((const bool)isReal, COMM_DIAG, - (const int)GlobalV::NBANDS, + (const int)PARAM.inp.nbands, (const int)h_mat.row, (const int)h_mat.col, (const int*)h_mat.desc); @@ -96,7 +97,7 @@ void DiagoElpa>::diag( es.exit(); const int inc = 1; - BlasConnector::copy(GlobalV::NBANDS, eigen.data(), inc, eigenvalue_in, inc); + BlasConnector::copy(PARAM.inp.nbands, eigen.data(), inc, eigenvalue_in, inc); #else ModuleBase::WARNING_QUIT("DiagoElpa", "DiagoElpa only can be used with macro __MPI"); @@ -112,15 +113,15 @@ void DiagoElpa::diag(hamilt::Hamilt* phm_in, matd h_mat, s_mat; phm_in->matrix(h_mat, s_mat); - std::vector eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); bool isReal = true; MPI_Comm COMM_DIAG = setmpicomm(); // set mpi_comm needed - // ELPA_Solver es(isReal, COMM_DIAG, GlobalV::NBANDS, h_mat.row, h_mat.col, + // ELPA_Solver es(isReal, COMM_DIAG, PARAM.inp.nbands, h_mat.row, h_mat.col, // h_mat.desc); ELPA_Solver es((const bool)isReal, COMM_DIAG, - (const int)GlobalV::NBANDS, + (const int)PARAM.inp.nbands, (const int)h_mat.row, (const int)h_mat.col, (const int*)h_mat.desc); @@ -136,7 +137,7 @@ void DiagoElpa::diag(hamilt::Hamilt* phm_in, const int inc = 1; ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "K-S equation was solved by genelpa2"); - BlasConnector::copy(GlobalV::NBANDS, eigen.data(), inc, eigenvalue_in, inc); + BlasConnector::copy(PARAM.inp.nbands, eigen.data(), inc, eigenvalue_in, inc); ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "eigenvalues were copied to ekb"); #else @@ -154,11 +155,11 @@ void DiagoElpa>::diag_pool(hamilt::MatrixBlock eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); bool isReal = false; ELPA_Solver es((const bool)isReal, comm, - (const int)GlobalV::NBANDS, + (const int)PARAM.inp.nbands, (const int)h_mat.row, (const int)h_mat.col, (const int*)h_mat.desc); @@ -173,7 +174,7 @@ void DiagoElpa>::diag_pool(hamilt::MatrixBlock @@ -183,14 +184,14 @@ void DiagoElpa::diag_pool(hamilt::MatrixBlock& h_mat, Real* eigenvalue_in, MPI_Comm& comm) { - std::vector eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); bool isReal = true; - // ELPA_Solver es(isReal, COMM_DIAG, GlobalV::NBANDS, h_mat.row, h_mat.col, + // ELPA_Solver es(isReal, COMM_DIAG, PARAM.inp.nbands, h_mat.row, h_mat.col, // h_mat.desc); ELPA_Solver es((const bool)isReal, comm, - (const int)GlobalV::NBANDS, + (const int)PARAM.inp.nbands, (const int)h_mat.row, (const int)h_mat.col, (const int*)h_mat.desc); @@ -206,7 +207,7 @@ void DiagoElpa::diag_pool(hamilt::MatrixBlock& h_mat, const int inc = 1; ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "K-S equation was solved by genelpa2"); - BlasConnector::copy(GlobalV::NBANDS, eigen.data(), inc, eigenvalue_in, inc); + BlasConnector::copy(PARAM.inp.nbands, eigen.data(), inc, eigenvalue_in, inc); ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "eigenvalues were copied to ekb"); } diff --git a/source/module_hsolver/diago_elpa_native.cpp b/source/module_hsolver/diago_elpa_native.cpp index f187a62288..2bd5953147 100644 --- a/source/module_hsolver/diago_elpa_native.cpp +++ b/source/module_hsolver/diago_elpa_native.cpp @@ -59,7 +59,7 @@ void DiagoElpaNative::diag_pool(hamilt::MatrixBlock& h_mat, ModuleBase::timer::tick("DiagoElpaNative", "elpa_solve"); - int nev = GlobalV::NBANDS; + int nev = PARAM.inp.nbands; int narows = h_mat.row; int nacols = h_mat.col; @@ -70,7 +70,7 @@ void DiagoElpaNative::diag_pool(hamilt::MatrixBlock& h_mat, int nprows, npcols, myprow, mypcol; Cblacs_gridinfo(cblacs_ctxt, &nprows, &npcols, &myprow, &mypcol); - std::vector eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); std::vector eigenvectors(narows * nacols); if (elpa_init(20210430) != ELPA_OK) @@ -103,7 +103,7 @@ void DiagoElpaNative::diag_pool(hamilt::MatrixBlock& h_mat, #define ELPA_WITH_SYCL_GPU_VERSION 0 */ #if ELPA_WITH_NVIDIA_GPU_VERSION - if (PARAM.globalv.device_flag == "gpu") + if (PARAM.inp.device == "gpu") { elpa_set(handle, "nvidia-gpu", 1, &success); elpa_set(handle, "real_kernel", ELPA_2STAGE_REAL_NVIDIA_GPU, &success); @@ -134,7 +134,7 @@ void DiagoElpaNative::diag_pool(hamilt::MatrixBlock& h_mat, } const int inc = 1; - BlasConnector::copy(GlobalV::NBANDS, eigen.data(), inc, eigenvalue_in, inc); + BlasConnector::copy(PARAM.inp.nbands, eigen.data(), inc, eigenvalue_in, inc); const int size = psi.get_nbands() * psi.get_nbasis(); BlasConnector::copy(size, eigenvectors.data(), inc, psi.get_pointer(), inc); } diff --git a/source/module_hsolver/diago_lapack.cpp b/source/module_hsolver/diago_lapack.cpp index 3fc4154444..33ce4f156c 100644 --- a/source/module_hsolver/diago_lapack.cpp +++ b/source/module_hsolver/diago_lapack.cpp @@ -1,5 +1,6 @@ // Refactored according to diago_scalapack // This code will be futher refactored to remove the dependency of psi and hamilt +#include "module_parameter/parameter.h" #include "diago_lapack.h" @@ -24,7 +25,7 @@ void DiagoLapack::diag(hamilt::Hamilt* phm_in, psi::Psi& assert(h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc); - std::vector eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); // Diag this->dsygvx_diag(h_mat.col, h_mat.row, h_mat.p, s_mat.p, eigen.data(), psi); @@ -45,7 +46,7 @@ void DiagoLapack>::diag(hamilt::Hamilt phm_in->matrix(h_mat, s_mat); assert(h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc); - std::vector eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); this->zhegvx_diag(h_mat.col, h_mat.row, h_mat.p, s_mat.p, eigen.data(), psi); int size = eigen.size(); for (int i = 0; i < size; i++) @@ -72,7 +73,7 @@ int DiagoLapack::dsygvx_once(const int ncol, // Prepare caculate parameters const char jobz = 'V', range = 'I', uplo = 'U'; - const int itype = 1, il = 1, iu = GlobalV::NBANDS, one = 1; + const int itype = 1, il = 1, iu = PARAM.inp.nbands, one = 1; int M = 0, info = 0; double vl = 0, vu = 0; const double abstol = 0; @@ -81,14 +82,14 @@ int DiagoLapack::dsygvx_once(const int ncol, std::vector work(3, 0); std::vector iwork(1, 0); - std::vector ifail(GlobalV::NLOCAL, 0); + std::vector ifail(PARAM.globalv.nlocal, 0); // Original Lapack caculate, obelsete /*dsygvx_(&itype, &jobz, &range, &uplo, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, h_tmp.c, &ncol, s_tmp.c, @@ -121,11 +122,11 @@ int DiagoLapack::dsygvx_once(const int ncol, &jobz, &range, &uplo, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, h_tmp.c, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, s_tmp.c, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, &vl, &vu, &il, @@ -143,7 +144,7 @@ int DiagoLapack::dsygvx_once(const int ncol, double *ev = new double[ncol * ncol]; - dsygv_(&itype, &jobz, &uplo, &GlobalV::NLOCAL, h_tmp.c, &ncol, s_tmp.c, &ncol, ekb, ev, &lwork, &info); + dsygv_(&itype, &jobz, &uplo, &PARAM.globalv.nlocal, h_tmp.c, &ncol, s_tmp.c, &ncol, ekb, ev, &lwork, &info); return info; } @@ -163,7 +164,7 @@ int DiagoLapack::zhegvx_once(const int ncol, memcpy(s_tmp.c, s_mat, sizeof(std::complex) * ncol * nrow); const char jobz = 'V', range = 'I', uplo = 'U'; - const int itype = 1, il = 1, iu = GlobalV::NBANDS, one = 1; + const int itype = 1, il = 1, iu = PARAM.inp.nbands, one = 1; int M = 0, lrwork = -1, info = 0; const double abstol = 0; @@ -173,7 +174,7 @@ int DiagoLapack::zhegvx_once(const int ncol, std::vector> work(1, 0); double *rwork = new double[3 * ncol - 2]; std::vector iwork(1, 0); - std::vector ifail(GlobalV::NLOCAL, 0); + std::vector ifail(PARAM.globalv.nlocal, 0); // Original Lapack caculate, obelsete /* @@ -181,11 +182,11 @@ int DiagoLapack::zhegvx_once(const int ncol, &jobz, &range, &uplo, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, h_tmp.c, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, s_tmp.c, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, &vl, &vu, &il, @@ -219,11 +220,11 @@ int DiagoLapack::zhegvx_once(const int ncol, &jobz, &range, &uplo, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, h_tmp.c, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, s_tmp.c, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, &vl, &vu, &il, @@ -244,7 +245,7 @@ int DiagoLapack::zhegvx_once(const int ncol, std::complex *ev = new std::complex[ncol * ncol]; - zhegv_(&itype, &jobz, &uplo, &GlobalV::NLOCAL, h_tmp.c, &ncol, s_tmp.c, &ncol, ekb, ev, &lwork, rwork, &info); + zhegv_(&itype, &jobz, &uplo, &PARAM.globalv.nlocal, h_tmp.c, &ncol, s_tmp.c, &ncol, ekb, ev, &lwork, rwork, &info); return info; } diff --git a/source/module_hsolver/diago_pexsi.cpp b/source/module_hsolver/diago_pexsi.cpp index 431fe5660f..85df14c9af 100644 --- a/source/module_hsolver/diago_pexsi.cpp +++ b/source/module_hsolver/diago_pexsi.cpp @@ -66,7 +66,7 @@ void DiagoPexsi::diag(hamilt::Hamilt* phm_in, psi::Psi& ModuleBase::TITLE("DiagoPEXSI", "diag"); matd h_mat, s_mat; phm_in->matrix(h_mat, s_mat); - std::vector eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); int ik = psi.get_current_k(); this->ps->prepare(this->ParaV->blacs_ctxt, this->ParaV->nb, diff --git a/source/module_hsolver/diago_scalapack.cpp b/source/module_hsolver/diago_scalapack.cpp index e2c187a9ac..d29e324154 100644 --- a/source/module_hsolver/diago_scalapack.cpp +++ b/source/module_hsolver/diago_scalapack.cpp @@ -1,5 +1,6 @@ //===================== // AUTHOR : Peize Lin +#include "module_parameter/parameter.h" // DATE : 2021-11-02 // REFACTORING AUTHOR : Daye Zheng // DATE : 2022-04-14 @@ -27,10 +28,10 @@ namespace hsolver matd h_mat, s_mat; phm_in->matrix(h_mat, s_mat); assert(h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc); - std::vector eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); this->pdsygvx_diag(h_mat.desc, h_mat.col, h_mat.row, h_mat.p, s_mat.p, eigen.data(), psi); const int inc = 1; - BlasConnector::copy(GlobalV::NBANDS, eigen.data(), inc, eigenvalue_in, inc); + BlasConnector::copy(PARAM.inp.nbands, eigen.data(), inc, eigenvalue_in, inc); } template<> void DiagoScalapack>::diag(hamilt::Hamilt>* phm_in, psi::Psi>& psi, Real* eigenvalue_in) @@ -39,10 +40,10 @@ namespace hsolver matcd h_mat, s_mat; phm_in->matrix(h_mat, s_mat); assert(h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc); - std::vector eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); this->pzhegvx_diag(h_mat.desc, h_mat.col, h_mat.row, h_mat.p, s_mat.p, eigen.data(), psi); const int inc = 1; - BlasConnector::copy(GlobalV::NBANDS, eigen.data(), inc, eigenvalue_in, inc); + BlasConnector::copy(PARAM.inp.nbands, eigen.data(), inc, eigenvalue_in, inc); } #ifdef __MPI @@ -55,10 +56,10 @@ namespace hsolver { ModuleBase::TITLE("DiagoScalapack", "diag_pool"); assert(h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc); - std::vector eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); this->pdsygvx_diag(h_mat.desc, h_mat.col, h_mat.row, h_mat.p, s_mat.p, eigen.data(), psi); const int inc = 1; - BlasConnector::copy(GlobalV::NBANDS, eigen.data(), inc, eigenvalue_in, inc); + BlasConnector::copy(PARAM.inp.nbands, eigen.data(), inc, eigenvalue_in, inc); } template<> void DiagoScalapack>::diag_pool(hamilt::MatrixBlock>& h_mat, @@ -69,10 +70,10 @@ namespace hsolver { ModuleBase::TITLE("DiagoScalapack", "diag_pool"); assert(h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc); - std::vector eigen(GlobalV::NLOCAL, 0.0); + std::vector eigen(PARAM.globalv.nlocal, 0.0); this->pzhegvx_diag(h_mat.desc, h_mat.col, h_mat.row, h_mat.p, s_mat.p, eigen.data(), psi); const int inc = 1; - BlasConnector::copy(GlobalV::NBANDS, eigen.data(), inc, eigenvalue_in, inc); + BlasConnector::copy(PARAM.inp.nbands, eigen.data(), inc, eigenvalue_in, inc); } #endif @@ -91,13 +92,13 @@ namespace hsolver memcpy(s_tmp.c, s_mat, sizeof(double) * ncol * nrow); const char jobz = 'V', range = 'I', uplo = 'U'; - const int itype = 1, il = 1, iu = GlobalV::NBANDS, one = 1; + const int itype = 1, il = 1, iu = PARAM.inp.nbands, one = 1; int M = 0, NZ = 0, lwork = -1, liwork = -1, info = 0; double vl = 0, vu = 0; const double abstol = 0, orfac = -1; std::vector work(3, 0); std::vector iwork(1, 0); - std::vector ifail(GlobalV::NLOCAL, 0); + std::vector ifail(PARAM.globalv.nlocal, 0); std::vector iclustr(2 * GlobalV::DSIZE); std::vector gap(GlobalV::DSIZE); @@ -105,7 +106,7 @@ namespace hsolver &jobz, &range, &uplo, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, h_tmp.c, &one, &one, @@ -151,7 +152,7 @@ namespace hsolver &jobz, &range, &uplo, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, h_tmp.c, &one, &one, @@ -216,7 +217,7 @@ namespace hsolver memcpy(s_tmp.c, s_mat, sizeof(std::complex) * ncol * nrow); const char jobz = 'V', range = 'I', uplo = 'U'; - const int itype = 1, il = 1, iu = GlobalV::NBANDS, one = 1; + const int itype = 1, il = 1, iu = PARAM.inp.nbands, one = 1; int M = 0, NZ = 0, lwork = -1, lrwork = -1, liwork = -1, info = 0; const double abstol = 0, orfac = -1; //Note: pzhegvx_ has a bug @@ -226,7 +227,7 @@ namespace hsolver std::vector> work(1, 0); std::vector rwork(3, 0); std::vector iwork(1, 0); - std::vector ifail(GlobalV::NLOCAL, 0); + std::vector ifail(PARAM.globalv.nlocal, 0); std::vector iclustr(2 * GlobalV::DSIZE); std::vector gap(GlobalV::DSIZE); @@ -234,7 +235,7 @@ namespace hsolver &jobz, &range, &uplo, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, h_tmp.c, &one, &one, @@ -275,7 +276,7 @@ namespace hsolver // GlobalV::ofs_running<<"lwork="<degeneracy_max * GlobalV::NLOCAL; + lrwork = rwork[0] + this->degeneracy_max * PARAM.globalv.nlocal; int maxlrwork = std::max(lrwork,3); rwork.resize(maxlrwork, 0); liwork = iwork[0]; @@ -285,7 +286,7 @@ namespace hsolver &jobz, &range, &uplo, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, h_tmp.c, &one, &one, @@ -430,7 +431,7 @@ namespace hsolver const std::string str_M = "M = " + ModuleBase::GlobalFunc::TO_STRING(vec[0]) + ".\n"; const std::string str_NZ = "NZ = " + ModuleBase::GlobalFunc::TO_STRING(vec[1]) + ".\n"; const std::string str_NBANDS - = "GlobalV::NBANDS = " + ModuleBase::GlobalFunc::TO_STRING(GlobalV::NBANDS) + ".\n"; + = "PARAM.inp.nbands = " + ModuleBase::GlobalFunc::TO_STRING(PARAM.inp.nbands) + ".\n"; throw std::runtime_error(str_info_FILE + str_M + str_NZ + str_NBANDS); } else if (info / 16 % 2) diff --git a/source/module_hsolver/hsolver.cpp b/source/module_hsolver/hsolver.cpp index a0b54ed9d9..1d0edb0e56 100644 --- a/source/module_hsolver/hsolver.cpp +++ b/source/module_hsolver/hsolver.cpp @@ -1,5 +1,6 @@ #include "hsolver.h" +#include "module_parameter/parameter.h" namespace hsolver { @@ -110,7 +111,7 @@ double set_diagethr_sdft(const std::string basis_type, } else { - if (nband_in > 0 && stoiter_ks_ne_in > 1e-6) //GlobalV::NBANDS > 0 && this->stoiter.KS_ne > 1e-6 + if (nband_in > 0 && stoiter_ks_ne_in > 1e-6) //PARAM.inp.nbands > 0 && this->stoiter.KS_ne > 1e-6 { res_diag_ethr = std::min(res_diag_ethr, 0.1 * drho / std::max(1.0, stoiter_ks_ne_in)); } diff --git a/source/module_hsolver/hsolver_pw.cpp b/source/module_hsolver/hsolver_pw.cpp index 678ec0adde..d6fa9ea649 100644 --- a/source/module_hsolver/hsolver_pw.cpp +++ b/source/module_hsolver/hsolver_pw.cpp @@ -519,7 +519,7 @@ void HSolverPW::hamiltSolvePsiK(hamilt::Hamilt* hm, const int nvec // Number of vectors(bands) ){ ModuleBase::timer::tick("David", "spsi_func"); - // sPsi determines S=I or not by GlobalV::use_uspp inside + // sPsi determines S=I or not by PARAM.globalv.use_uspp inside // sPsi(psi, spsi, nrow, npw, nbands) hm->sPsi(psi_in, spsi_out, ld_spsi, ld_psi, nvec); ModuleBase::timer::tick("David", "spsi_func"); diff --git a/source/module_hsolver/module_pexsi/pexsi_solver.cpp b/source/module_hsolver/module_pexsi/pexsi_solver.cpp index 7a71e6ca01..e830eb2eaf 100644 --- a/source/module_hsolver/module_pexsi/pexsi_solver.cpp +++ b/source/module_hsolver/module_pexsi/pexsi_solver.cpp @@ -1,5 +1,6 @@ #include "module_base/parallel_global.h" #ifdef __PEXSI +#include "module_parameter/parameter.h" #include "pexsi_solver.h" #include @@ -78,14 +79,14 @@ int PEXSI_Solver::solve(double mu0) DIAG_WORLD, grid_group, this->blacs_text, - GlobalV::NLOCAL, + PARAM.globalv.nlocal, this->nb, this->nrow, this->ncol, 'c', this->h, this->s, - GlobalV::nelec, + PARAM.inp.nelec, "PEXSIOPTION", this->DM, this->EDM, diff --git a/source/module_hsolver/test/diago_lapack_test.cpp b/source/module_hsolver/test/diago_lapack_test.cpp index 7e9d583e6b..5b1430ce8d 100644 --- a/source/module_hsolver/test/diago_lapack_test.cpp +++ b/source/module_hsolver/test/diago_lapack_test.cpp @@ -1,5 +1,8 @@ // Author: Zhang Xiaoyang // A modified version of diago_lcao_test.cpp +#define private public +#include "module_parameter/parameter.h" +#undef private // Remove some useless functions and dependencies. Serialized the full code // and refactored some function. @@ -185,8 +188,8 @@ class DiagoLapackPrepare void set_env() { - GlobalV::NLOCAL = nlocal; - GlobalV::NBANDS = nbands; + PARAM.sys.nlocal = nlocal; + PARAM.input.nbands = nbands; } void diago() diff --git a/source/module_hsolver/test/diago_lcao_cusolver_test.cpp b/source/module_hsolver/test/diago_lcao_cusolver_test.cpp index b54cebe251..d88a4aecc9 100644 --- a/source/module_hsolver/test/diago_lcao_cusolver_test.cpp +++ b/source/module_hsolver/test/diago_lcao_cusolver_test.cpp @@ -1,5 +1,8 @@ #include "module_hsolver/diago_scalapack.h" #include "module_hsolver/test/diago_elpa_utils.h" +#define private public +#include "module_parameter/parameter.h" +#undef private #include "mpi.h" #include "string.h" @@ -200,8 +203,8 @@ class DiagoPrepare void set_env() { - GlobalV::NLOCAL = nlocal; - GlobalV::NBANDS = nbands; + PARAM.sys.nlocal = nlocal; + PARAM.input.nbands = nbands; GlobalV::DSIZE = dsize; } diff --git a/source/module_hsolver/test/diago_lcao_test.cpp b/source/module_hsolver/test/diago_lcao_test.cpp index de2e4c88b4..7c24dd39e5 100644 --- a/source/module_hsolver/test/diago_lcao_test.cpp +++ b/source/module_hsolver/test/diago_lcao_test.cpp @@ -1,5 +1,8 @@ #include "module_hsolver/diago_scalapack.h" #include "module_hsolver/test/diago_elpa_utils.h" +#define private public +#include "module_parameter/parameter.h" +#undef private #include "mpi.h" #include "string.h" @@ -197,8 +200,8 @@ class DiagoPrepare void set_env() { - GlobalV::NLOCAL = nlocal; - GlobalV::NBANDS = nbands; + PARAM.sys.nlocal = nlocal; + PARAM.input.nbands = nbands; GlobalV::DSIZE = dsize; } diff --git a/source/module_hsolver/test/diago_pexsi_test.cpp b/source/module_hsolver/test/diago_pexsi_test.cpp index 1c0f6e08ea..3b2ca3cb42 100644 --- a/source/module_hsolver/test/diago_pexsi_test.cpp +++ b/source/module_hsolver/test/diago_pexsi_test.cpp @@ -183,8 +183,8 @@ class PexsiPrepare void set_env() { - GlobalV::NLOCAL = nlocal; - GlobalV::NBANDS = nbands; + PARAM.sys.nlocal = nlocal; + PARAM.input.nbands = nbands; GlobalV::DSIZE = dsize; PARAM.input.nspin = 1; DIAG_WORLD = MPI_COMM_WORLD; @@ -298,7 +298,7 @@ class PexsiPrepare return false; } - f_dm >> GlobalV::nelec >> mu; + f_dm >> PARAM.input.nelec >> mu; dm.resize(nread * nread); // T* edm = new T[nglobal*nglobal]; diff --git a/source/module_hsolver/test/test_hsolver_pw.cpp b/source/module_hsolver/test/test_hsolver_pw.cpp index 2d8d5b4f07..f0877371b8 100644 --- a/source/module_hsolver/test/test_hsolver_pw.cpp +++ b/source/module_hsolver/test/test_hsolver_pw.cpp @@ -43,7 +43,7 @@ class TestHSolverPW : public ::testing::Test { "pw", "cg", false, - GlobalV::use_uspp, + PARAM.sys.use_uspp, PARAM.input.nspin, hsolver::DiagoIterAssist, base_device::DEVICE_CPU>::SCF_ITER, hsolver::DiagoIterAssist, base_device::DEVICE_CPU>::PW_DIAG_NMAX, @@ -58,7 +58,7 @@ class TestHSolverPW : public ::testing::Test { "pw", "cg", false, - GlobalV::use_uspp, + PARAM.sys.use_uspp, PARAM.input.nspin, hsolver::DiagoIterAssist, base_device::DEVICE_CPU>::SCF_ITER, hsolver::DiagoIterAssist, base_device::DEVICE_CPU>::PW_DIAG_NMAX, @@ -87,7 +87,7 @@ TEST_F(TestHSolverPW, solve) { this->ekb_f.resize(2); psi_test_cf.resize(1, 2, 3); psi_test_cd.resize(1, 2, 3); - GlobalV::nelec = 1.0; + PARAM.input.nelec = 1.0; // check solve() EXPECT_EQ(this->hs_f.initialed_psi, false); @@ -247,7 +247,7 @@ TEST_F(TestHSolverPW, SolveLcaoInPW) { psi_value_f += std::complex(1.0, 0.0); } } - GlobalV::nelec = 1.0; + PARAM.input.nelec = 1.0; // check solve() elecstate_test.ekb.c[0] = 1.0; diff --git a/source/module_hsolver/test/test_hsolver_sdft.cpp b/source/module_hsolver/test/test_hsolver_sdft.cpp index 1943701078..c48db2cee0 100644 --- a/source/module_hsolver/test/test_hsolver_sdft.cpp +++ b/source/module_hsolver/test/test_hsolver_sdft.cpp @@ -146,7 +146,7 @@ class TestHSolverPW_SDFT : public ::testing::Test "pw", "cg", false, - GlobalV::use_uspp, + PARAM.sys.use_uspp, PARAM.input.nspin, hsolver::DiagoIterAssist>::SCF_ITER, hsolver::DiagoIterAssist>::PW_DIAG_NMAX, @@ -176,7 +176,7 @@ TEST_F(TestHSolverPW_SDFT, solve) stowf.nchi = 0; stowf.nchip_max = 0; psi_test_cd.resize(1, 2, 3); - GlobalV::nelec = 1.0; + PARAM.input.nelec = 1.0; GlobalV::MY_STOGROUP = 0.0; int istep = 0; int iter = 0; @@ -221,7 +221,7 @@ TEST_F(TestHSolverPW_SDFT, solve_noband_skipcharge) psi_test_no.nk = 2; psi_test_no.nbands = 0; psi_test_no.nbasis = 0; - GlobalV::nelec = 1.0; + PARAM.input.nelec = 1.0; GlobalV::MY_STOGROUP = 0.0; PARAM.input.nspin = 1; elecstate_test.charge = new Charge; diff --git a/source/module_io/berryphase.cpp b/source/module_io/berryphase.cpp index 7324a22822..71b173b095 100644 --- a/source/module_io/berryphase.cpp +++ b/source/module_io/berryphase.cpp @@ -24,14 +24,14 @@ berryphase::~berryphase() void berryphase::get_occupation_bands() { - double occupied_bands = static_cast(GlobalV::nelec / ModuleBase::DEGSPIN); + double occupied_bands = static_cast(PARAM.inp.nelec / ModuleBase::DEGSPIN); if ((occupied_bands - std::floor(occupied_bands)) > 0.0) { occupied_bands = std::floor(occupied_bands) + 1.0; } occ_nbands = (int)occupied_bands; - if (occ_nbands > GlobalV::NBANDS) + if (occ_nbands > PARAM.inp.nbands) { ModuleBase::WARNING_QUIT("berryphase::get_occupation_bands", "not enough bands for berryphase, increase band numbers."); diff --git a/source/module_io/cal_r_overlap_R.cpp b/source/module_io/cal_r_overlap_R.cpp index 3f4c35a6ba..7c1044572c 100644 --- a/source/module_io/cal_r_overlap_R.cpp +++ b/source/module_io/cal_r_overlap_R.cpp @@ -194,11 +194,11 @@ void cal_r_overlap_R::construct_orbs_and_orb_r(const LCAO_Orbitals& orb) } } - iw2it.resize(GlobalV::NLOCAL); - iw2ia.resize(GlobalV::NLOCAL); - iw2iL.resize(GlobalV::NLOCAL); - iw2iN.resize(GlobalV::NLOCAL); - iw2im.resize(GlobalV::NLOCAL); + iw2it.resize(PARAM.globalv.nlocal); + iw2ia.resize(PARAM.globalv.nlocal); + iw2iL.resize(PARAM.globalv.nlocal); + iw2iN.resize(PARAM.globalv.nlocal); + iw2im.resize(PARAM.globalv.nlocal); int iw = 0; for (int it = 0; it < GlobalC::ucell.ntype; it++) @@ -299,12 +299,12 @@ void cal_r_overlap_R::out_rR(const int& istep) ModuleBase::Vector3 R_car = ModuleBase::Vector3(dRx, dRy, dRz) * GlobalC::ucell.latvec; int ir, ic; - for (int iw1 = 0; iw1 < GlobalV::NLOCAL; iw1++) + for (int iw1 = 0; iw1 < PARAM.globalv.nlocal; iw1++) { ir = this->ParaV->global2local_row(iw1); if (ir >= 0) { - for (int iw2 = 0; iw2 < GlobalV::NLOCAL; iw2++) + for (int iw2 = 0; iw2 < PARAM.globalv.nlocal; iw2++) { ic = this->ParaV->global2local_col(iw2); if (ic >= 0) @@ -460,6 +460,7 @@ void cal_r_overlap_R::out_rR(const int& istep) if (binary) { ofs_tem1.close(); + int nlocal = PARAM.globalv.nlocal; if (PARAM.inp.calculation == "md" && PARAM.inp.out_app_flag && step) { out_r.open(ssr.str().c_str(), std::ios::binary | std::ios::app); @@ -469,7 +470,7 @@ void cal_r_overlap_R::out_rR(const int& istep) out_r.open(ssr.str().c_str(), std::ios::binary); } out_r.write(reinterpret_cast(&step), sizeof(int)); - out_r.write(reinterpret_cast(&GlobalV::NLOCAL), sizeof(int)); + out_r.write(reinterpret_cast(&nlocal), sizeof(int)); out_r.write(reinterpret_cast(&output_R_number), sizeof(int)); ifs_tem1.open(tem1.str().c_str(), std::ios::binary); @@ -489,7 +490,7 @@ void cal_r_overlap_R::out_rR(const int& istep) out_r.open(ssr.str().c_str()); } out_r << "STEP: " << step << std::endl; - out_r << "Matrix Dimension of r(R): " << GlobalV::NLOCAL << std::endl; + out_r << "Matrix Dimension of r(R): " << PARAM.globalv.nlocal << std::endl; out_r << "Matrix number of r(R): " << output_R_number << std::endl; ifs_tem1.open(tem1.str().c_str()); @@ -533,6 +534,7 @@ void cal_r_overlap_R::out_rR_other(const int& istep, const std::set(&step), sizeof(int)); - out_r.write(reinterpret_cast(&GlobalV::NLOCAL), sizeof(int)); + out_r.write(reinterpret_cast(&nlocal), sizeof(int)); out_r.write(reinterpret_cast(&output_R_number), sizeof(int)); } else @@ -556,7 +558,7 @@ void cal_r_overlap_R::out_rR_other(const int& istep, const std::setParaV->global2local_row(iw1); if (ir >= 0) { - for (int iw2 = 0; iw2 < GlobalV::NLOCAL; iw2++) + for (int iw2 = 0; iw2 < PARAM.globalv.nlocal; iw2++) { ic = this->ParaV->global2local_col(iw2); if (ic >= 0) diff --git a/source/module_io/cal_test.cpp b/source/module_io/cal_test.cpp index 9575b991f5..680ba6028f 100644 --- a/source/module_io/cal_test.cpp +++ b/source/module_io/cal_test.cpp @@ -1,5 +1,8 @@ #include "module_hamilt_pw/hamilt_pwdft/global.h" #include "module_base/global_function.h" +#define private public +#include "module_parameter/parameter.h" +#undef private #include "module_base/global_variable.h" #include "module_base/memory.h" #include "cal_test.h" @@ -94,9 +97,9 @@ void Cal_Test::test_memory( mrhog_save = ModuleBase::Memory::calculate_mem( ngmc, "cdouble"); mrhog_core = ModuleBase::Memory::calculate_mem( ngmc, "cdouble"); - mhs = ModuleBase::Memory::calculate_mem( GlobalV::NLOCAL*GlobalV::NLOCAL, "double" ); - mwf = ModuleBase::Memory::calculate_mem( GlobalV::NLOCAL*GlobalV::NBANDS, "double" ); - mnonzero = ModuleBase::Memory::calculate_mem( GlobalV::NLOCAL*(GlobalV::NLOCAL+1)/2, "bool"); + mhs = ModuleBase::Memory::calculate_mem( PARAM.globalv.nlocal*PARAM.globalv.nlocal, "double" ); + mwf = ModuleBase::Memory::calculate_mem( PARAM.globalv.nlocal*PARAM.inp.nbands, "double" ); + mnonzero = ModuleBase::Memory::calculate_mem( PARAM.globalv.nlocal*(PARAM.globalv.nlocal+1)/2, "bool"); // mohan comment out 2021-02-11 // mspar_hsrho = Memory::calculate_mem( Hnnz*3, "double"); @@ -109,18 +112,18 @@ void Cal_Test::test_memory( meigts123 = ModuleBase::Memory::calculate_mem( GlobalC::ucell.nat * (2*rhopw->nx+1+2*rhopw->ny+1+2*rhopw->nz+1), "cdouble"); //(3) Memory for H,S matrix. - std::cout << " NLOCAL = " << GlobalV::NLOCAL << std::endl; - std::cout << " NBANDS = " << GlobalV::NBANDS << std::endl; + std::cout << " NLOCAL = " << PARAM.globalv.nlocal << std::endl; + std::cout << " NBANDS = " << PARAM.inp.nbands << std::endl; std::cout << " Memory for H,S matrix ( " - << GlobalV::NLOCAL << ", " - << GlobalV::NLOCAL << ") = " + << PARAM.globalv.nlocal << ", " + << PARAM.globalv.nlocal << ") = " << mhs << " MB" << std::endl; //(4) Memory for wave functions. std::cout << " Memory for wave functions ( " - << GlobalV::NLOCAL << ", " - << GlobalV::NBANDS << ") = " + << PARAM.globalv.nlocal << ", " + << PARAM.inp.nbands << ") = " << mwf << " MB" << std::endl; print_mem(1); @@ -223,6 +226,6 @@ void Cal_Test::print_mem(const int &nproc) std::cout << " TOTAL MEMORY : " << std::setw(15) << mtot/nproc << " MB" << std::endl; std::cout << " MEMORY FOR nonzero : " << std::setw(15) - << (double)GlobalV::NLOCAL*(GlobalV::NLOCAL+1)/1028/1028/2.0/nproc + << (double)PARAM.globalv.nlocal*(PARAM.globalv.nlocal+1)/1028/1028/2.0/nproc << " MB" << std::endl; } diff --git a/source/module_io/get_wf_lcao.cpp b/source/module_io/get_wf_lcao.cpp index 6792c4a64a..e6360cb6ae 100644 --- a/source/module_io/get_wf_lcao.cpp +++ b/source/module_io/get_wf_lcao.cpp @@ -1,5 +1,6 @@ #include "get_wf_lcao.h" +#include "module_parameter/parameter.h" #include "module_base/global_function.h" #include "module_base/global_variable.h" #include "module_base/memory.h" @@ -541,7 +542,7 @@ int IState_Envelope::set_wfc_grid(const int naroc[2], for (int j = 0; j < naroc[1]; ++j) { int igcol = globalIndex(j, nb, dim1, ipcol); - if (igcol >= GlobalV::NBANDS) + if (igcol >= PARAM.inp.nbands) { continue; } diff --git a/source/module_io/input_conv.cpp b/source/module_io/input_conv.cpp index 732b1e27ec..7c3997bc22 100644 --- a/source/module_io/input_conv.cpp +++ b/source/module_io/input_conv.cpp @@ -181,13 +181,7 @@ void Input_Conv::Convert() } - GlobalV::NBANDS = PARAM.inp.nbands; - - GlobalV::device_flag = base_device::information::get_device_flag(PARAM.inp.device, - PARAM.inp.ks_solver, - PARAM.inp.basis_type); - - if (GlobalV::device_flag == "gpu" && PARAM.inp.basis_type == "pw") + if (PARAM.inp.device == "gpu" && PARAM.inp.basis_type == "pw") { GlobalV::KPAR = base_device::information::get_device_kpar(PARAM.inp.kpar); } @@ -203,7 +197,7 @@ void Input_Conv::Convert() { GlobalV::KPAR = PARAM.inp.kpar; } - if (GlobalV::device_flag == "cpu" and PARAM.inp.precision == "single") + if (PARAM.inp.device == "cpu" and PARAM.inp.precision == "single") { // cpu single precision is not supported while float_fftw lib is not available #ifndef __ENABLE_FLOAT_FFTW @@ -277,11 +271,6 @@ void Input_Conv::Convert() //---------------------------------------------------------- // Yu Liu add 2022-09-13 //---------------------------------------------------------- - GlobalV::nelec = PARAM.inp.nelec; - if (PARAM.globalv.two_fermi) - { - GlobalV::nupdown = PARAM.inp.nupdown; - } elecstate::Gatefield::zgate = PARAM.inp.zgate; elecstate::Gatefield::relax = PARAM.inp.relax; elecstate::Gatefield::block = PARAM.inp.block; @@ -457,7 +446,6 @@ void Input_Conv::Convert() //---------------------------------------------------------- // wavefunction / charge / potential / (2/4) //---------------------------------------------------------- - GlobalV::nelec = PARAM.inp.nelec; #ifdef __LCAO diff --git a/source/module_io/json_output/init_info.cpp b/source/module_io/json_output/init_info.cpp index 5905bdfed3..657d37fe2d 100644 --- a/source/module_io/json_output/init_info.cpp +++ b/source/module_io/json_output/init_info.cpp @@ -1,5 +1,6 @@ #include "init_info.h" +#include "module_parameter/parameter.h" #include "../para_json.h" #include "abacusjson.h" @@ -21,10 +22,10 @@ void gen_init(UnitCell* ucell) int numAtoms = ucell->nat; AbacusJson::add_json({"init", "natom"}, numAtoms, false); - AbacusJson::add_json({"init", "nband"}, GlobalV::NBANDS, false); + AbacusJson::add_json({"init", "nband"}, PARAM.inp.nbands, false); // Json::AbacusJson::add_Json(numAtoms,false,"init", "natom"); - // Json::AbacusJson::add_Json(GlobalV::NBANDS,false,"init", "nband"); + // Json::AbacusJson::add_Json(PARAM.inp.nbands,false,"init", "nband"); int ntype = ucell->ntype, nelec_total = 0; for (int it = 0; it < ntype; it++) diff --git a/source/module_io/json_output/test/para_json_test.cpp b/source/module_io/json_output/test/para_json_test.cpp index b66affc8cc..9ac40256b0 100644 --- a/source/module_io/json_output/test/para_json_test.cpp +++ b/source/module_io/json_output/test/para_json_test.cpp @@ -272,7 +272,7 @@ TEST(AbacusJsonTest, InitInfo) ucell.symm.spgname = "O_h"; ucell.atoms = atomlist; ucell.ntype = 3; - GlobalV::NBANDS = 10; + PARAM.input.nbands = 10; ucell.atoms[0].label = "Si"; ucell.atoms[0].ncpp.zv = 3; diff --git a/source/module_io/nscf_fermi_surf.cpp b/source/module_io/nscf_fermi_surf.cpp index 1d62f42940..a6fb9c645f 100644 --- a/source/module_io/nscf_fermi_surf.cpp +++ b/source/module_io/nscf_fermi_surf.cpp @@ -1,5 +1,6 @@ #include "nscf_fermi_surf.h" #include "module_base/global_function.h" +#include "module_parameter/parameter.h" #include "module_base/global_variable.h" #include "module_base/timer.h" @@ -16,7 +17,7 @@ void ModuleIO::nscf_fermi_surface(const std::string &out_band_dir, #ifdef __MPI int start = 1; - int end = GlobalV::NBANDS; + int end = PARAM.inp.nbands; std::ofstream ofs; if(GlobalV::MY_RANK==0) diff --git a/source/module_io/numerical_basis.cpp b/source/module_io/numerical_basis.cpp index 4e562f91b8..65e43102e8 100644 --- a/source/module_io/numerical_basis.cpp +++ b/source/module_io/numerical_basis.cpp @@ -112,8 +112,8 @@ void Numerical_Basis::output_overlap(const psi::Psi>& psi, std::vector overlap_Sq(kv.get_nks()); ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "number of k points", kv.get_nks()); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "number of bands", GlobalV::NBANDS); - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "number of local orbitals", GlobalV::NLOCAL); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "number of bands", PARAM.inp.nbands); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "number of local orbitals", PARAM.globalv.nlocal); ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "number of eigenvalues of Jl(x)", this->bessel_basis.get_ecut_number()); @@ -232,7 +232,7 @@ ModuleBase::ComplexArray Numerical_Basis::cal_overlap_Q(const int& ik, const int << std::endl; GlobalV::ofs_running << " Q = < J_mu, q | Psi_n, k > " << std::endl; - ModuleBase::ComplexArray overlap_Q(GlobalV::NBANDS, GlobalV::NLOCAL, this->bessel_basis.get_ecut_number()); + ModuleBase::ComplexArray overlap_Q(PARAM.inp.nbands, PARAM.globalv.nlocal, this->bessel_basis.get_ecut_number()); overlap_Q.zero_out(); const double normalization = (4 * ModuleBase::PI) / sqrt(ucell.omega); // Peize Lin add normalization 2015-12-29 @@ -273,7 +273,7 @@ ModuleBase::ComplexArray Numerical_Basis::cal_overlap_Q(const int& ik, const int for (int m = 0; m < 2 * L + 1; m++) { const int lm = L * L + m; - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { std::complex overlap_tmp = ModuleBase::ZERO; for (int ig = 0; ig < np; ig++) @@ -309,7 +309,7 @@ ModuleBase::ComplexArray Numerical_Basis::cal_overlap_Sq(const int& ik, const in GlobalV::ofs_running << " S = < J_mu,q1 | J_nu,q2 >" << std::endl; const int enumber = this->bessel_basis.get_ecut_number(); - ModuleBase::ComplexArray overlap_Sq(GlobalV::NLOCAL, GlobalV::NLOCAL, enumber, enumber); + ModuleBase::ComplexArray overlap_Sq(PARAM.globalv.nlocal, PARAM.globalv.nlocal, enumber, enumber); overlap_Sq.zero_out(); const double normalization @@ -424,7 +424,7 @@ ModuleBase::matrix Numerical_Basis::cal_overlap_V(const ModulePW::PW_Basis_K* wf const double derivative_order, const K_Vectors& kv, const double tpiba) { - ModuleBase::matrix overlap_V(kv.get_nks(), GlobalV::NBANDS); + ModuleBase::matrix overlap_V(kv.get_nks(), PARAM.inp.nbands); for (int ik = 0; ik < kv.get_nks(); ++ik) { std::vector> gk(kv.ngk[ik]); @@ -434,7 +434,7 @@ ModuleBase::matrix Numerical_Basis::cal_overlap_V(const ModulePW::PW_Basis_K* wf const std::vector gpow = Numerical_Basis::cal_gpow(gk, derivative_order); - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) { + for (int ib = 0; ib < PARAM.inp.nbands; ++ib) { for (int ig = 0; ig < kv.ngk[ik]; ++ig) { overlap_V(ik, ib) += norm(psi(ik, ib, ig)) * gpow[ig]; } @@ -629,8 +629,8 @@ void Numerical_Basis::output_info(std::ofstream& ofs, const Bessel_Basis& bessel if (GlobalV::MY_RANK == 0) { ofs << kv.get_nkstot() << " nks" << std::endl; - ofs << GlobalV::NBANDS << " nbands" << std::endl; - ofs << GlobalV::NLOCAL << " nwfc" << std::endl; + ofs << PARAM.inp.nbands << " nbands" << std::endl; + ofs << PARAM.globalv.nlocal << " nwfc" << std::endl; ofs << bessel_basis.get_ecut_number() << " ne " << std::endl; } } diff --git a/source/module_io/numerical_descriptor.cpp b/source/module_io/numerical_descriptor.cpp index 1300ab89f4..aea1840e11 100644 --- a/source/module_io/numerical_descriptor.cpp +++ b/source/module_io/numerical_descriptor.cpp @@ -1,5 +1,6 @@ #include "numerical_descriptor.h" #include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_parameter/parameter.h" #include "module_cell/module_symmetry/symmetry.h" #include "winput.h" #include "module_base/math_ylmreal.h" @@ -85,8 +86,8 @@ void Numerical_Descriptor::output_descriptor(const psi::Psi // 3. Initialize overlap_Q1 and Q2 //------------------------------------- // OVERLAP : < J_mu | Psi > - ModuleBase::realArray overlap_Q1(nks, GlobalV::NBANDS, this->nlocal ); - ModuleBase::realArray overlap_Q2(nks, GlobalV::NBANDS, this->nlocal ); + ModuleBase::realArray overlap_Q1(nks, PARAM.inp.nbands, this->nlocal ); + ModuleBase::realArray overlap_Q2(nks, PARAM.inp.nbands, this->nlocal ); ModuleBase::GlobalFunc::ZEROS(overlap_Q1.ptr, overlap_Q1.getSize() ); ModuleBase::GlobalFunc::ZEROS(overlap_Q2.ptr, overlap_Q2.getSize() ); @@ -310,7 +311,7 @@ normalization 2015-12-29 for (int ie=0; ie < nmax; ie++) for (int m=0; m<2*L+1; m++) { const int lm = L*L+m; - for (int ib=0; ib overlap_tmp = ModuleBase::ZERO; for (int ig=0; ig #include @@ -756,6 +757,10 @@ void ReadInput::item_system() Input_Item item("device"); item.annotation = "the computing device for ABACUS"; read_sync_string(input.device); + item.reset_value = [](const Input_Item& item, Parameter& para) { + para.input.device=base_device::information::get_device_flag( + para.inp.device, para.inp.basis_type); + }; this->add_item(item); } { diff --git a/source/module_io/read_set_globalv.cpp b/source/module_io/read_set_globalv.cpp index cb8421533d..3579765add 100644 --- a/source/module_io/read_set_globalv.cpp +++ b/source/module_io/read_set_globalv.cpp @@ -1,5 +1,6 @@ #include "module_base/global_variable.h" #include "module_base/tool_quit.h" +#include "module_base/module_device/device.h" #include "module_parameter/parameter.h" #include "read_input.h" #include "read_input_tool.h" @@ -93,25 +94,6 @@ void ReadInput::set_globalv(Parameter& para) break; } - if (para.input.device == "cpu") - { - para.sys.device_flag = "cpu"; - } - else if (para.input.device == "gpu") - { - if (para.input.basis_type == "lcao_in_pw") - { - GlobalV::ofs_warning << "The GPU currently does not support the basis type \"lcao_in_pw\"!" << std::endl; - para.sys.device_flag = "cpu"; - } - para.sys.device_flag = "gpu"; - } - else - { - GlobalV::ofs_warning << "Parameter \"device\" can only be set to \"cpu\" or \"gpu\"!" << std::endl; - ModuleBase::WARNING_QUIT("device", "Parameter \"device\" can only be set to \"cpu\" or \"gpu\"!"); - } - para.sys.nqx=static_cast((sqrt(para.inp.ecutwfc) / para.sys.dq + 4.0) * para.inp.cell_factor); para.sys.nqxq=static_cast((sqrt(para.inp.ecutrho) / para.sys.dq + 4.0) * para.inp.cell_factor); } @@ -119,7 +101,9 @@ void ReadInput::set_globalv(Parameter& para) void ReadInput::set_globalv_bcast() { + add_int_bcast(sys.myrank); add_bool_bcast(sys.two_fermi); + add_bool_bcast(sys.use_uspp); add_bool_bcast(sys.dos_setemin); add_bool_bcast(sys.dos_setemax); @@ -143,8 +127,6 @@ void ReadInput::set_globalv_bcast() add_bool_bcast(sys.domag); add_bool_bcast(sys.domag_z); add_int_bcast(sys.npol); - - add_string_bcast(sys.device_flag); add_bool_bcast(sys.double_grid); add_double_bcast(sys.uramping); diff --git a/source/module_io/read_wfc_pw.cpp b/source/module_io/read_wfc_pw.cpp index dc1b742e5b..43977d0a3d 100644 --- a/source/module_io/read_wfc_pw.cpp +++ b/source/module_io/read_wfc_pw.cpp @@ -114,7 +114,7 @@ void ModuleIO::read_wfc_pw(const std::string& filename, MPI_Bcast(&tpiba_in, 1, MPI_DOUBLE, 0, POOL_WORLD); #endif - if (ikstot_in != ikstot + 1 || nkstot_in != nkstot || npwtot_in != npwtot || nbands_in != GlobalV::NBANDS) + if (ikstot_in != ikstot + 1 || nkstot_in != nkstot || npwtot_in != npwtot || nbands_in != PARAM.inp.nbands) { std::cout << "ikstot_in = " << ikstot_in << std::endl; std::cout << "ikstot = " << ikstot + 1 << std::endl; @@ -123,10 +123,10 @@ void ModuleIO::read_wfc_pw(const std::string& filename, std::cout << "npwtot_in = " << npwtot_in << std::endl; std::cout << "npwtot = " << npwtot << std::endl; std::cout << "nbands_in = " << nbands_in << std::endl; - std::cout << "nbands = " << GlobalV::NBANDS << std::endl; + std::cout << "nbands = " << PARAM.inp.nbands << std::endl; ModuleBase::WARNING_QUIT( "ModuleIO::read_wfc_pw", - "ikstot_in != ikstot || nkstot_in != nkstot || npwtot_in != npwtot || nbands_in != GlobalV::NBANDS"); + "ikstot_in != ikstot || nkstot_in != nkstot || npwtot_in != npwtot || nbands_in != PARAM.inp.nbands"); } if (kvec[0] != pw_wfc->kvec_c[ik].x || kvec[1] != pw_wfc->kvec_c[ik].y || kvec[2] != pw_wfc->kvec_c[ik].z) diff --git a/source/module_io/read_wfc_to_rho.cpp b/source/module_io/read_wfc_to_rho.cpp index ba641310ad..bef1a87462 100644 --- a/source/module_io/read_wfc_to_rho.cpp +++ b/source/module_io/read_wfc_to_rho.cpp @@ -19,7 +19,7 @@ void ModuleIO::read_wfc_to_rho(const ModulePW::PW_Basis_K* pw_wfc, const int kpar = GlobalV::KPAR; const int my_pool = GlobalV::MY_POOL; const int my_rank = GlobalV::MY_RANK; - const int nbands = GlobalV::NBANDS; + const int nbands = PARAM.inp.nbands; const int nspin = PARAM.inp.nspin; const int ng_npol = pw_wfc->npwk_max * PARAM.globalv.npol; diff --git a/source/module_io/single_R_io.cpp b/source/module_io/single_R_io.cpp index 8c81d8b3fb..f0116b8fba 100644 --- a/source/module_io/single_R_io.cpp +++ b/source/module_io/single_R_io.cpp @@ -24,7 +24,7 @@ void ModuleIO::output_single_R(std::ofstream& ofs, { T* line = nullptr; std::vector indptr; - indptr.reserve(GlobalV::NLOCAL + 1); + indptr.reserve(PARAM.globalv.nlocal + 1); indptr.push_back(0); std::stringstream tem1; @@ -44,10 +44,10 @@ void ModuleIO::output_single_R(std::ofstream& ofs, } } - line = new T[GlobalV::NLOCAL]; - for(int row = 0; row < GlobalV::NLOCAL; ++row) + line = new T[PARAM.globalv.nlocal]; + for(int row = 0; row < PARAM.globalv.nlocal; ++row) { - ModuleBase::GlobalFunc::ZEROS(line, GlobalV::NLOCAL); + ModuleBase::GlobalFunc::ZEROS(line, PARAM.globalv.nlocal); if (!reduce || pv.global2local_row(row) >= 0) { @@ -61,12 +61,13 @@ void ModuleIO::output_single_R(std::ofstream& ofs, } } - if (reduce)Parallel_Reduce::reduce_all(line, GlobalV::NLOCAL); + if (reduce) {Parallel_Reduce::reduce_all(line, PARAM.globalv.nlocal); +} if (!reduce || GlobalV::DRANK == 0) { int nonzeros_count = 0; - for (int col = 0; col < GlobalV::NLOCAL; ++col) + for (int col = 0; col < PARAM.globalv.nlocal; ++col) { if (std::abs(line[col]) > sparse_threshold) { diff --git a/source/module_io/test/read_wfc_pw_test.cpp b/source/module_io/test/read_wfc_pw_test.cpp index 78867db78b..0d717955de 100644 --- a/source/module_io/test/read_wfc_pw_test.cpp +++ b/source/module_io/test/read_wfc_pw_test.cpp @@ -1,5 +1,8 @@ #include "module_io/read_wfc_pw.h" +#define private public +#include "module_parameter/parameter.h" +#undef private #include "gmock/gmock.h" #include "gtest/gtest.h" #ifdef __MPI @@ -49,9 +52,9 @@ TEST_F(ReadWfcPwTest, ReadWfcPw) wfcpw->setuptransform(); wfcpw->collect_local_pw(); - GlobalV::NBANDS = 8; + PARAM.input.nbands = 8; const int nbasis = wfcpw->npwk[0]; - ModuleBase::ComplexMatrix wfcatom(GlobalV::NBANDS, nbasis); + ModuleBase::ComplexMatrix wfcatom(PARAM.input.nbands, nbasis); ModuleIO::read_wfc_pw(filename, wfcpw, 0, nkstot, wfcatom); if (GlobalV::NPROC_IN_POOL == 1) @@ -116,7 +119,7 @@ TEST_F(ReadWfcPwTest, NotFoundFile) wfcpw->setuptransform(); wfcpw->collect_local_pw(); - ModuleBase::ComplexMatrix wfcatom(GlobalV::NBANDS, wfcpw->npwk[0]); + ModuleBase::ComplexMatrix wfcatom(PARAM.input.nbands, wfcpw->npwk[0]); if(GlobalV::RANK_IN_POOL == 0) { @@ -159,9 +162,9 @@ TEST_F(ReadWfcPwTest, InconsistentBands) wfcpw->setuptransform(); wfcpw->collect_local_pw(); - GlobalV::NBANDS = 4; + PARAM.input.nbands = 4; const int nbasis = wfcpw->npwk[0]; - ModuleBase::ComplexMatrix wfcatom(GlobalV::NBANDS, nbasis); + ModuleBase::ComplexMatrix wfcatom(PARAM.input.nbands, nbasis); testing::internal::CaptureStdout(); EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, nkstot, wfcatom), ::testing::ExitedWithCode(0), ""); std::string output = testing::internal::GetCapturedStdout(); @@ -170,7 +173,7 @@ TEST_F(ReadWfcPwTest, InconsistentBands) EXPECT_THAT( output, testing::HasSubstr( - "ikstot_in != ikstot || nkstot_in != nkstot || npwtot_in != npwtot || nbands_in != GlobalV::NBANDS")); + "ikstot_in != ikstot || nkstot_in != nkstot || npwtot_in != npwtot || nbands_in != PARAM.inp.nbands")); } } @@ -191,9 +194,9 @@ TEST_F(ReadWfcPwTest, InconsistentKvec) wfcpw->setuptransform(); wfcpw->collect_local_pw(); - GlobalV::NBANDS = 8; + PARAM.input.nbands = 8; const int nbasis = wfcpw->npwk[0]; - ModuleBase::ComplexMatrix wfcatom(GlobalV::NBANDS, nbasis); + ModuleBase::ComplexMatrix wfcatom(PARAM.input.nbands, nbasis); testing::internal::CaptureStdout(); EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, nkstot, wfcatom), ::testing::ExitedWithCode(0), ""); std::string output = testing::internal::GetCapturedStdout(); @@ -219,9 +222,9 @@ TEST_F(ReadWfcPwTest, InconsistentLat0) wfcpw->setuptransform(); wfcpw->collect_local_pw(); - GlobalV::NBANDS = 8; + PARAM.input.nbands = 8; const int nbasis = wfcpw->npwk[0]; - ModuleBase::ComplexMatrix wfcatom(GlobalV::NBANDS, nbasis); + ModuleBase::ComplexMatrix wfcatom(PARAM.input.nbands, nbasis); testing::internal::CaptureStdout(); EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, nkstot, wfcatom), ::testing::ExitedWithCode(0), ""); std::string output = testing::internal::GetCapturedStdout(); @@ -247,9 +250,9 @@ TEST_F(ReadWfcPwTest, InconsistentG) wfcpw->setuptransform(); wfcpw->collect_local_pw(); - GlobalV::NBANDS = 8; + PARAM.input.nbands = 8; const int nbasis = wfcpw->npwk[0]; - ModuleBase::ComplexMatrix wfcatom(GlobalV::NBANDS, nbasis); + ModuleBase::ComplexMatrix wfcatom(PARAM.input.nbands, nbasis); testing::internal::CaptureStdout(); EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, nkstot, wfcatom), ::testing::ExitedWithCode(0), ""); std::string output = testing::internal::GetCapturedStdout(); diff --git a/source/module_io/test/read_wfc_to_rho_test.cpp b/source/module_io/test/read_wfc_to_rho_test.cpp index 0a1e42e09f..ad11042b59 100644 --- a/source/module_io/test/read_wfc_to_rho_test.cpp +++ b/source/module_io/test/read_wfc_to_rho_test.cpp @@ -115,7 +115,7 @@ class ReadWfcRhoTest : public ::testing::Test wfcpw = new ModulePW::PW_Basis_K; rhopw = new ModulePW::PW_Basis; kv = new K_Vectors; - GlobalV::NBANDS = 4; + PARAM.input.nbands = 4; PARAM.input.nspin = 1; PARAM.input.out_wfc_pw = 2; } @@ -132,7 +132,7 @@ TEST_F(ReadWfcRhoTest, ReadWfcRho) { // Init K_Vectors const int my_pool = GlobalV::MY_POOL; - const int nbands = GlobalV::NBANDS; + const int nbands = PARAM.input.nbands; const int nks = 2; const int nkstot = GlobalV::KPAR * nks; kv->set_nkstot(nkstot); diff --git a/source/module_io/test/single_R_io_test.cpp b/source/module_io/test/single_R_io_test.cpp index 779e36626f..7b142fa25f 100644 --- a/source/module_io/test/single_R_io_test.cpp +++ b/source/module_io/test/single_R_io_test.cpp @@ -1,5 +1,8 @@ #include "gtest/gtest.h" #include "gmock/gmock.h" +#define private public +#include "module_parameter/parameter.h" +#undef private #include "module_io/single_R_io.h" #include "module_base/global_variable.h" #include "module_basis/module_ao/parallel_orbitals.h" @@ -41,8 +44,8 @@ TEST(ModuleIOTest, OutputSingleR) const double sparse_threshold = 1e-8; const bool binary = false; Parallel_Orbitals pv; - GlobalV::NLOCAL = 5; - pv.set_serial(GlobalV::NLOCAL, GlobalV::NLOCAL); + PARAM.sys.nlocal = 5; + pv.set_serial(PARAM.sys.nlocal, PARAM.sys.nlocal); std::map> XR = { {0, {{1, 0.5}, {3, 0.3}}}, {1, {{0, 0.2}, {2, 0.4}}}, diff --git a/source/module_io/test/write_dos_pw_test.cpp b/source/module_io/test/write_dos_pw_test.cpp index 18448958a3..6415827d56 100644 --- a/source/module_io/test/write_dos_pw_test.cpp +++ b/source/module_io/test/write_dos_pw_test.cpp @@ -62,7 +62,7 @@ TEST_F(DosPWTest,Dos1) kv->isk[ik] = dosp.isk[ik]; kv->wk[ik] = dosp.wk[ik]; } - GlobalV::NBANDS = dosp.nbands; + PARAM.input.nbands = dosp.nbands; ModuleIO::write_dos_pw(dosp.ekb, dosp.wg, *kv, @@ -112,7 +112,7 @@ TEST_F(DosPWTest,Dos2) kv->isk[ik] = dosp.isk[ik]; kv->wk[ik] = dosp.wk[ik]; } - GlobalV::NBANDS = dosp.nbands; + PARAM.input.nbands = dosp.nbands; ModuleIO::write_dos_pw(dosp.ekb, dosp.wg, *kv, diff --git a/source/module_io/test/write_istate_info_test.cpp b/source/module_io/test/write_istate_info_test.cpp index 43fc87f2b3..9be9c28532 100644 --- a/source/module_io/test/write_istate_info_test.cpp +++ b/source/module_io/test/write_istate_info_test.cpp @@ -48,7 +48,7 @@ TEST_F(IstateInfoTest, OutIstateInfoS1) { // preconditions GlobalV::KPAR = 1; - GlobalV::NBANDS = 4; + PARAM.input.nbands = 4; PARAM.input.nspin = 1; PARAM.sys.global_out_dir = "./"; // mpi setting @@ -71,8 +71,8 @@ TEST_F(IstateInfoTest, OutIstateInfoS1) // std::cout<<"MY_POOL "<set_nks(Pkpoints->nks_pool[GlobalV::MY_POOL]); // std::cout<<"nks "<get_nks()<get_nks(), GlobalV::NBANDS); - wg.create(kv->get_nks(), GlobalV::NBANDS); + ekb.create(kv->get_nks(), PARAM.input.nbands); + wg.create(kv->get_nks(), PARAM.input.nbands); ekb.fill_out(0.15); wg.fill_out(0.0); kv->kvec_d.resize(kv->get_nkstot()); @@ -99,7 +99,7 @@ TEST_F(IstateInfoTest, OutIstateInfoS2) { // preconditions GlobalV::KPAR = 1; - GlobalV::NBANDS = 4; + PARAM.input.nbands = 4; PARAM.input.nspin = 2; PARAM.sys.global_out_dir = "./"; // mpi setting @@ -122,8 +122,8 @@ TEST_F(IstateInfoTest, OutIstateInfoS2) // std::cout<<"MY_POOL "<set_nks(Pkpoints->nks_pool[GlobalV::MY_POOL]); // std::cout<<"nks "<get_nks()<get_nks(), GlobalV::NBANDS); - wg.create(kv->get_nks(), GlobalV::NBANDS); + ekb.create(kv->get_nks(), PARAM.input.nbands); + wg.create(kv->get_nks(), PARAM.input.nbands); ekb.fill_out(0.15); wg.fill_out(0.0); kv->kvec_d.resize(kv->get_nkstot()); diff --git a/source/module_io/test/write_orb_info_test.cpp b/source/module_io/test/write_orb_info_test.cpp index b9c6f66483..9c4fae341b 100644 --- a/source/module_io/test/write_orb_info_test.cpp +++ b/source/module_io/test/write_orb_info_test.cpp @@ -49,7 +49,7 @@ TEST(OrbInfo,WriteOrbInfo) PARAM.input.nspin = 1; PARAM.input.basis_type = "pw"; PARAM.input.dft_functional = "default"; - GlobalV::NLOCAL = 18; + PARAM.sys.nlocal = 18; ucell->read_cell_pseudopots(pp_dir,ofs); ucell->cal_nwfc(ofs); ModuleIO::write_orb_info(ucell); diff --git a/source/module_io/test/write_wfc_nao_test.cpp b/source/module_io/test/write_wfc_nao_test.cpp index 64ebcf0959..f0503ad80c 100644 --- a/source/module_io/test/write_wfc_nao_test.cpp +++ b/source/module_io/test/write_wfc_nao_test.cpp @@ -229,8 +229,8 @@ TEST(ModuleIOTest, WriteWfcNao) { // Set up GlobalV GlobalV::DRANK = 0; - GlobalV::NBANDS = 2; - GlobalV::NLOCAL = 2; + PARAM.input.nbands = 2; + PARAM.sys.nlocal = 2; PARAM.input.out_app_flag = true; // Set up test data @@ -248,7 +248,7 @@ TEST(ModuleIOTest, WriteWfcNao) wg(1, 1) = 1.2; // Call the function to be tested - ModuleIO::wfc_nao_write2file(filename, ctot.data(), GlobalV::NLOCAL, 0, ekb, wg, false); + ModuleIO::wfc_nao_write2file(filename, ctot.data(), PARAM.sys.nlocal, 0, ekb, wg, false); // Check the output file std::ifstream ifs(filename); @@ -276,8 +276,8 @@ TEST(ModuleIOTest, WriteWfcNaoBinary) { // Set up GlobalV GlobalV::DRANK = 0; - GlobalV::NBANDS = 2; - GlobalV::NLOCAL = 2; + PARAM.input.nbands = 2; + PARAM.sys.nlocal = 2; PARAM.input.out_app_flag = true; // Set up test data @@ -295,7 +295,7 @@ TEST(ModuleIOTest, WriteWfcNaoBinary) wg(1, 1) = 1.2; // Call the function to be tested - ModuleIO::wfc_nao_write2file(filename, ctot.data(), GlobalV::NLOCAL, 0, ekb, wg, true); + ModuleIO::wfc_nao_write2file(filename, ctot.data(), PARAM.sys.nlocal, 0, ekb, wg, true); // Check the output file Binstream wfc(filename, "r"); @@ -333,8 +333,8 @@ TEST(ModuleIOTest, WriteWfcNaoComplex) if (GlobalV::MY_RANK == 0) { // Set up GlobalV - GlobalV::NBANDS = 2; - GlobalV::NLOCAL = 3; + PARAM.input.nbands = 2; + PARAM.sys.nlocal = 3; PARAM.input.out_app_flag = true; // set up test data std::string name = "test_wfc_nao_complex.txt"; @@ -354,7 +354,7 @@ TEST(ModuleIOTest, WriteWfcNaoComplex) std::complex(0.0, 3.0)}; // Call the function - ModuleIO::wfc_nao_write2file_complex(name, ctot.data(), GlobalV::NLOCAL, ik, kvec_c, ekb, wg); + ModuleIO::wfc_nao_write2file_complex(name, ctot.data(), PARAM.sys.nlocal, ik, kvec_c, ekb, wg); // Check the output file std::ifstream ifs(name); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); @@ -377,8 +377,8 @@ TEST(ModuleIOTest, WriteWfcNaoComplexBinary) if (GlobalV::MY_RANK == 0) { // Set up GlobalV - GlobalV::NBANDS = 2; - GlobalV::NLOCAL = 3; + PARAM.input.nbands = 2; + PARAM.sys.nlocal = 3; PARAM.input.out_app_flag = true; // set up test data std::string name = "test_wfc_nao_complex.dat"; @@ -398,7 +398,7 @@ TEST(ModuleIOTest, WriteWfcNaoComplexBinary) std::complex(6.0, 8.0)}; // Call the function - ModuleIO::wfc_nao_write2file_complex(name, ctot.data(), GlobalV::NLOCAL, ik, kvec_c, ekb, wg, true); + ModuleIO::wfc_nao_write2file_complex(name, ctot.data(), PARAM.sys.nlocal, ik, kvec_c, ekb, wg, true); // Check the output file Binstream wfc(name, "r"); diff --git a/source/module_io/test_serial/CMakeLists.txt b/source/module_io/test_serial/CMakeLists.txt index e6a7f3b80d..5119a6b1d1 100644 --- a/source/module_io/test_serial/CMakeLists.txt +++ b/source/module_io/test_serial/CMakeLists.txt @@ -27,7 +27,9 @@ install(DIRECTORY support DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) AddTest( TARGET io_read_input_serial LIBS parameter ${math_libs} io_input_serial - SOURCES read_input_test.cpp ../../module_base/test/tool_quit_no_exit.cpp + SOURCES read_input_test.cpp + ../../module_base/test/tool_quit_no_exit.cpp + ../../module_base/module_device/device.cpp ) AddTest( diff --git a/source/module_io/to_wannier90.cpp b/source/module_io/to_wannier90.cpp index 207fa4d150..aa54f6738d 100644 --- a/source/module_io/to_wannier90.cpp +++ b/source/module_io/to_wannier90.cpp @@ -479,31 +479,31 @@ bool toWannier90::try_read_nnkp(const K_Vectors& kv) nnkp_read.close(); - if (GlobalV::NBANDS <= num_exclude_bands) + if (PARAM.inp.nbands <= num_exclude_bands) { ModuleBase::WARNING_QUIT("toWannier90::read_nnkp", "you set the band numer is not enough, please add bands number."); } - // tag_cal_band = new bool[GlobalV::NBANDS]; - // for (int ib = 0; ib < GlobalV::NBANDS; ib++) tag_cal_band[ib] = true; + // tag_cal_band = new bool[PARAM.inp.nbands]; + // for (int ib = 0; ib < PARAM.inp.nbands; ib++) tag_cal_band[ib] = true; // for (int ib = 0; ib < num_exclude_bands; ib++) tag_cal_band[ib] = false; if (num_exclude_bands == 0) { - num_bands = GlobalV::NBANDS; + num_bands = PARAM.inp.nbands; cal_band_index = new int[num_bands]; - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { cal_band_index[ib] = ib; } } else { - num_bands = GlobalV::NBANDS - num_exclude_bands; + num_bands = PARAM.inp.nbands - num_exclude_bands; cal_band_index = new int[num_bands]; int count = 0; - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { if (exclude_bands.count(ib) != 1) { diff --git a/source/module_io/to_wannier90_lcao.cpp b/source/module_io/to_wannier90_lcao.cpp index 3ff2c6ad3f..a886c29f50 100644 --- a/source/module_io/to_wannier90_lcao.cpp +++ b/source/module_io/to_wannier90_lcao.cpp @@ -65,12 +65,12 @@ void toWannier90_LCAO::calculate(const ModuleBase::matrix& ekb, if (out_wannier_mmn || out_wannier_amn) { - iw2it.resize(GlobalV::NLOCAL); - iw2ia.resize(GlobalV::NLOCAL); - iw2iL.resize(GlobalV::NLOCAL); - iw2iN.resize(GlobalV::NLOCAL); - iw2im.resize(GlobalV::NLOCAL); - iw2iorb.resize(GlobalV::NLOCAL); + iw2it.resize(PARAM.globalv.nlocal); + iw2ia.resize(PARAM.globalv.nlocal); + iw2iL.resize(PARAM.globalv.nlocal); + iw2iN.resize(PARAM.globalv.nlocal); + iw2im.resize(PARAM.globalv.nlocal); + iw2iorb.resize(PARAM.globalv.nlocal); std::map>> temp_orb_index; int count = 0; @@ -421,8 +421,8 @@ void toWannier90_LCAO::unkdotkb(const K_Vectors& kv, char transa = 'C'; char transb = 'N'; - int Bands = GlobalV::NBANDS; - int nlocal = GlobalV::NLOCAL; + int Bands = PARAM.inp.nbands; + int nlocal = PARAM.globalv.nlocal; std::complex alpha = {1.0, 0.0}, beta = {0.0, 0.0}; int one = 1; @@ -474,7 +474,7 @@ void toWannier90_LCAO::unkdotkb(const K_Vectors& kv, #endif int count_m = -1; - for (int m = 0; m < GlobalV::NBANDS; m++) + for (int m = 0; m < PARAM.inp.nbands; m++) { if (exclude_bands.count(m)) { continue; @@ -485,7 +485,7 @@ void toWannier90_LCAO::unkdotkb(const K_Vectors& kv, if (ir >= 0) { int count_n = -1; - for (int n = 0; n < GlobalV::NBANDS; n++) + for (int n = 0; n < PARAM.inp.nbands; n++) { if (exclude_bands.count(n)) { continue; @@ -1138,7 +1138,7 @@ void toWannier90_LCAO::unkdotA(const K_Vectors& kv, int R_num = R_coor_car.size(); if (PARAM.inp.nspin != 4) { - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { if (exclude_bands.count(ib)) { continue; @@ -1170,7 +1170,7 @@ void toWannier90_LCAO::unkdotA(const K_Vectors& kv, } else { - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { if (exclude_bands.count(ib)) { continue; diff --git a/source/module_io/to_wannier90_lcao_in_pw.cpp b/source/module_io/to_wannier90_lcao_in_pw.cpp index cd962f9678..0419009d17 100644 --- a/source/module_io/to_wannier90_lcao_in_pw.cpp +++ b/source/module_io/to_wannier90_lcao_in_pw.cpp @@ -123,7 +123,7 @@ psi::Psi>* toWannier90_LCAO_IN_PW::get_unk_from_lcao( for (int ik = 0; ik < num_kpts; ik++) { int npw = kv.ngk[ik]; - ModuleBase::ComplexMatrix orbital_in_G(GlobalV::NLOCAL, npwx*PARAM.globalv.npol); + ModuleBase::ComplexMatrix orbital_in_G(PARAM.globalv.nlocal, npwx*PARAM.globalv.npol); // Wavefunc_in_pw::produce_local_basis_in_pw(ik, wfcpw, sf, orbital_in_G, table_local); //produce_local_basis_in_pw(ik, wfcpw, sf, orbital_in_G, table_local); nao_G_expansion(ik, wfcpw, orbital_in_G); @@ -137,7 +137,7 @@ psi::Psi>* toWannier90_LCAO_IN_PW::get_unk_from_lcao( { for (int ig = 0; ig < npw; ig++) { - for (int iw = 0; iw < GlobalV::NLOCAL; iw++) + for (int iw = 0; iw < PARAM.globalv.nlocal; iw++) { unk_inLcao[0](ik, ib, ig) += lcao_wfc_global(ib, iw) * orbital_in_G(iw, ig); } @@ -165,7 +165,7 @@ psi::Psi>* toWannier90_LCAO_IN_PW::get_unk_from_lcao( { // for (int ig = 0; ig < npwx*PARAM.globalv.npol; ig++) // { - // for (int iw = 0; iw < GlobalV::NLOCAL; iw++) + // for (int iw = 0; iw < PARAM.globalv.nlocal; iw++) // { // unk_inLcao[0](ik, ib, ig) += lcao_wfc_global(ib, iw) * orbital_in_G(iw, ig); // } @@ -173,7 +173,7 @@ psi::Psi>* toWannier90_LCAO_IN_PW::get_unk_from_lcao( for (int ig = 0; ig < npw; ig++) { - int basis_num = GlobalV::NLOCAL / 2; + int basis_num = PARAM.globalv.nlocal / 2; for (int iw = 0; iw < basis_num; iw++) { unk_inLcao[0](ik, ib, ig) += lcao_wfc_global(ib, 2*iw) * orbital_in_G(iw, ig); @@ -219,7 +219,7 @@ void toWannier90_LCAO_IN_PW::nao_G_expansion( std::weak_ptr>> psig = this->psi_init_->share_psig(); if(psig.expired()) { ModuleBase::WARNING_QUIT("toWannier90_LCAO_IN_PW::nao_G_expansion", "psig is expired"); } - int nbands = GlobalV::NLOCAL; + int nbands = PARAM.globalv.nlocal; int nbasis = npwx*PARAM.globalv.npol; for (int ib = 0; ib < nbands; ib++) { @@ -236,12 +236,12 @@ void toWannier90_LCAO_IN_PW::get_lcao_wfc_global_ik( ModuleBase::ComplexMatrix &lcao_wfc_global ) { - lcao_wfc_global.create(num_bands, GlobalV::NLOCAL); + lcao_wfc_global.create(num_bands, PARAM.globalv.nlocal); int count_b = -1; int row = this->ParaV->get_row_size(); int global_row_index = 0; - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { if (exclude_bands.count(ib)) { continue; } diff --git a/source/module_io/unk_overlap_lcao.cpp b/source/module_io/unk_overlap_lcao.cpp index cf31cbfdbe..b8ca83ebf2 100644 --- a/source/module_io/unk_overlap_lcao.cpp +++ b/source/module_io/unk_overlap_lcao.cpp @@ -15,7 +15,7 @@ unkOverlap_lcao::~unkOverlap_lcao() { if (allocate_flag) { - for (int iw = 0; iw < GlobalV::NLOCAL; iw++) + for (int iw = 0; iw < PARAM.globalv.nlocal; iw++) { delete [] cal_tag[iw]; } @@ -88,11 +88,11 @@ void unkOverlap_lcao::init(const Grid_Technique& gt, const int nkstot, const LCA this->kpoints_number = nkstot; if (allocate_flag) { - cal_tag = new int*[GlobalV::NLOCAL]; - for (int iw = 0; iw < GlobalV::NLOCAL; iw++) + cal_tag = new int*[PARAM.globalv.nlocal]; + for (int iw = 0; iw < PARAM.globalv.nlocal; iw++) { - cal_tag[iw] = new int[GlobalV::NLOCAL]; - ModuleBase::GlobalFunc::ZEROS(cal_tag[iw], GlobalV::NLOCAL); + cal_tag[iw] = new int[PARAM.globalv.nlocal]; + ModuleBase::GlobalFunc::ZEROS(cal_tag[iw], PARAM.globalv.nlocal); } } @@ -101,7 +101,7 @@ void unkOverlap_lcao::init(const Grid_Technique& gt, const int nkstot, const LCA int nproc, myrank; MPI_Comm_size(MPI_COMM_WORLD, &nproc); MPI_Comm_rank(MPI_COMM_WORLD, &myrank); - const int total_term = GlobalV::NLOCAL * GlobalV::NLOCAL; + const int total_term = PARAM.globalv.nlocal * PARAM.globalv.nlocal; const int remain = total_term % nproc; int local_term = total_term / nproc; if (myrank < remain) @@ -125,12 +125,12 @@ void unkOverlap_lcao::init(const Grid_Technique& gt, const int nkstot, const LCA } #else int start = 0; - int local_term = GlobalV::NLOCAL * GlobalV::NLOCAL; + int local_term = PARAM.globalv.nlocal * PARAM.globalv.nlocal; #endif int count = -1; - for (int iw1 = 0; iw1 < GlobalV::NLOCAL; iw1++) + for (int iw1 = 0; iw1 < PARAM.globalv.nlocal; iw1++) { - for (int iw2 = 0; iw2 < GlobalV::NLOCAL; iw2++) + for (int iw2 = 0; iw2 < PARAM.globalv.nlocal; iw2++) { count++; if (count >= start && count < (start + local_term)) @@ -361,10 +361,10 @@ void unkOverlap_lcao::cal_R_number() { // The number of overlaps between atomic orbitals 1 and atomic orbitals 2, // or the number of R, is empty when there is no overlap - orb1_orb2_R.resize(GlobalV::NLOCAL); - for (int iw = 0; iw < GlobalV::NLOCAL; iw++) + orb1_orb2_R.resize(PARAM.globalv.nlocal); + for (int iw = 0; iw < PARAM.globalv.nlocal; iw++) { - orb1_orb2_R[iw].resize(GlobalV::NLOCAL); + orb1_orb2_R[iw].resize(PARAM.globalv.nlocal); } ModuleBase::Vector3 tau1, tau2, dtau; @@ -419,19 +419,19 @@ void unkOverlap_lcao::cal_R_number() void unkOverlap_lcao::cal_orb_overlap() { // std::cout << "the cal_orb_overlap is start" << std::endl; - psi_psi.resize(GlobalV::NLOCAL); - psi_r_psi.resize(GlobalV::NLOCAL); - for (int iw = 0; iw < GlobalV::NLOCAL; iw++) + psi_psi.resize(PARAM.globalv.nlocal); + psi_r_psi.resize(PARAM.globalv.nlocal); + for (int iw = 0; iw < PARAM.globalv.nlocal; iw++) { - psi_psi[iw].resize(GlobalV::NLOCAL); - psi_r_psi[iw].resize(GlobalV::NLOCAL); + psi_psi[iw].resize(PARAM.globalv.nlocal); + psi_r_psi[iw].resize(PARAM.globalv.nlocal); } ModuleBase::Vector3 origin_point(0.0, 0.0, 0.0); - for (int iw1 = 0; iw1 < GlobalV::NLOCAL; iw1++) + for (int iw1 = 0; iw1 < PARAM.globalv.nlocal; iw1++) { - for (int iw2 = 0; iw2 < GlobalV::NLOCAL; iw2++) + for (int iw2 = 0; iw2 < PARAM.globalv.nlocal; iw2++) { // if ( !pv.in_this_processor(iw1,iw2) ) continue; @@ -501,9 +501,9 @@ void unkOverlap_lcao::prepare_midmatrix_pblas(const int ik_L, // ModuleBase::Vector3 dk = kv.kvec_c[ik_R] - kv.kvec_c[ik_L]; midmatrix = new std::complex[pv.nloc]; ModuleBase::GlobalFunc::ZEROS(midmatrix, pv.nloc); - for (int iw_row = 0; iw_row < GlobalV::NLOCAL; iw_row++) // global + for (int iw_row = 0; iw_row < PARAM.globalv.nlocal; iw_row++) // global { - for (int iw_col = 0; iw_col < GlobalV::NLOCAL; iw_col++) // global + for (int iw_col = 0; iw_col < PARAM.globalv.nlocal; iw_col++) // global { int ir = pv.global2local_row(iw_row); // local int ic = pv.global2local_col(iw_col); // local @@ -546,7 +546,7 @@ std::complex unkOverlap_lcao::det_berryphase(const int ik_L, char transa = 'C'; char transb = 'N'; int occBands = occ_bands; - int nlocal = GlobalV::NLOCAL; + int nlocal = PARAM.globalv.nlocal; std::complex alpha = {1.0, 0.0}, beta = {0.0, 0.0}; int one = 1; #ifdef __MPI diff --git a/source/module_io/winput.cpp b/source/module_io/winput.cpp index 4927a92668..1df64a3cb7 100644 --- a/source/module_io/winput.cpp +++ b/source/module_io/winput.cpp @@ -703,9 +703,9 @@ void winput::Check() // { // ModuleBase::WARNING_QUIT("winput::Check","Please check your bloch_end"); // } - // if(bloch_end > GlobalV::NBANDS) + // if(bloch_end > PARAM.inp.nbands) // { - // ModuleBase::WARNING_QUIT("winput::Check","Bloch_end > GlobalV::NBANDS, reset either of them"); + // ModuleBase::WARNING_QUIT("winput::Check","Bloch_end > PARAM.inp.nbands, reset either of them"); // } // } // }// end after_iter diff --git a/source/module_io/write_HS.hpp b/source/module_io/write_HS.hpp index ae4d2d880f..a328f746d0 100644 --- a/source/module_io/write_HS.hpp +++ b/source/module_io/write_HS.hpp @@ -33,9 +33,9 @@ void ModuleIO::save_HS_ccf(const int &iter, const int &Hnnz, const int *colptr_H FILE *g1 = fopen(ssh.str().c_str(),"wb"); FILE *g2 = fopen(sss.str().c_str(),"wb"); - fwrite(&GlobalV::NLOCAL,sizeof(int),1,g1); + fwrite(&PARAM.globalv.nlocal,sizeof(int),1,g1); fwrite(&Hnnz,sizeof(int),1,g1); - fwrite(&GlobalV::NLOCAL,sizeof(int),1,g2); + fwrite(&PARAM.globalv.nlocal,sizeof(int),1,g2); fwrite(&Hnnz,sizeof(int),1,g2); fclose(g1); @@ -48,10 +48,10 @@ void ModuleIO::save_HS_ccf(const int &iter, const int &Hnnz, const int *colptr_H std::ofstream g1(ssh.str().c_str()); std::ofstream g2(sss.str().c_str()); - g1 << GlobalV::NLOCAL << " " << Hnnz << std::endl; - g2 << GlobalV::NLOCAL << " " << Hnnz << std::endl; + g1 << PARAM.globalv.nlocal << " " << Hnnz << std::endl; + g2 << PARAM.globalv.nlocal << " " << Hnnz << std::endl; - for(int i=0; i(&step), sizeof(int)); - g1[ispin].write(reinterpret_cast(&GlobalV::NLOCAL), + g1[ispin].write(reinterpret_cast(&nlocal), sizeof(int)); g1[ispin].write(reinterpret_cast(&output_R_number), sizeof(int)); @@ -153,7 +154,7 @@ void ModuleIO::save_HSR_sparse(const int& istep, g2.open(sss.str().c_str(), std::ios::binary); } g2.write(reinterpret_cast(&step), sizeof(int)); - g2.write(reinterpret_cast(&GlobalV::NLOCAL), sizeof(int)); + g2.write(reinterpret_cast(&nlocal), sizeof(int)); g2.write(reinterpret_cast(&output_R_number), sizeof(int)); } else { for (int ispin = 0; ispin < spin_loop; ++ispin) { @@ -164,7 +165,7 @@ void ModuleIO::save_HSR_sparse(const int& istep, g1[ispin].open(ssh[ispin].str().c_str()); } g1[ispin] << "STEP: " << step << std::endl; - g1[ispin] << "Matrix Dimension of H(R): " << GlobalV::NLOCAL + g1[ispin] << "Matrix Dimension of H(R): " << PARAM.globalv.nlocal << std::endl; g1[ispin] << "Matrix number of H(R): " << output_R_number << std::endl; @@ -176,7 +177,7 @@ void ModuleIO::save_HSR_sparse(const int& istep, g2.open(sss.str().c_str()); } g2 << "STEP: " << step << std::endl; - g2 << "Matrix Dimension of S(R): " << GlobalV::NLOCAL << std::endl; + g2 << "Matrix Dimension of S(R): " << PARAM.globalv.nlocal << std::endl; g2 << "Matrix number of S(R): " << output_R_number << std::endl; } } @@ -238,7 +239,7 @@ void ModuleIO::save_HSR_sparse(const int& istep, // { // g1[ispin] << std::endl; // g1[ispin] << std::endl; - // for (int index = 0; index < GlobalV::NLOCAL+1; + // for (int index = 0; index < PARAM.globalv.nlocal+1; // ++index) // { // g1[ispin] << 0 << " "; @@ -279,7 +280,7 @@ void ModuleIO::save_HSR_sparse(const int& istep, // { // g2 << std::endl; // g2 << std::endl; - // for (int index = 0; index < GlobalV::NLOCAL+1; ++index) + // for (int index = 0; index < PARAM.globalv.nlocal+1; ++index) // { // g2 << 0 << " "; // } @@ -453,6 +454,7 @@ void ModuleIO::save_dH_sparse(const int& istep, if (GlobalV::DRANK == 0) { if (binary) { + int nlocal = PARAM.globalv.nlocal; for (int ispin = 0; ispin < spin_loop; ++ispin) { if (PARAM.inp.calculation == "md" && PARAM.inp.out_app_flag && step) { @@ -472,19 +474,19 @@ void ModuleIO::save_dH_sparse(const int& istep, } g1x[ispin].write(reinterpret_cast(&step), sizeof(int)); - g1x[ispin].write(reinterpret_cast(&GlobalV::NLOCAL), + g1x[ispin].write(reinterpret_cast(&nlocal), sizeof(int)); g1x[ispin].write(reinterpret_cast(&output_R_number), sizeof(int)); g1y[ispin].write(reinterpret_cast(&step), sizeof(int)); - g1y[ispin].write(reinterpret_cast(&GlobalV::NLOCAL), + g1y[ispin].write(reinterpret_cast(&nlocal), sizeof(int)); g1y[ispin].write(reinterpret_cast(&output_R_number), sizeof(int)); g1z[ispin].write(reinterpret_cast(&step), sizeof(int)); - g1z[ispin].write(reinterpret_cast(&GlobalV::NLOCAL), + g1z[ispin].write(reinterpret_cast(&nlocal), sizeof(int)); g1z[ispin].write(reinterpret_cast(&output_R_number), sizeof(int)); @@ -503,19 +505,19 @@ void ModuleIO::save_dH_sparse(const int& istep, } g1x[ispin] << "STEP: " << step << std::endl; - g1x[ispin] << "Matrix Dimension of dHx(R): " << GlobalV::NLOCAL + g1x[ispin] << "Matrix Dimension of dHx(R): " << PARAM.globalv.nlocal << std::endl; g1x[ispin] << "Matrix number of dHx(R): " << output_R_number << std::endl; g1y[ispin] << "STEP: " << step << std::endl; - g1y[ispin] << "Matrix Dimension of dHy(R): " << GlobalV::NLOCAL + g1y[ispin] << "Matrix Dimension of dHy(R): " << PARAM.globalv.nlocal << std::endl; g1y[ispin] << "Matrix number of dHy(R): " << output_R_number << std::endl; g1z[ispin] << "STEP: " << step << std::endl; - g1z[ispin] << "Matrix Dimension of dHz(R): " << GlobalV::NLOCAL + g1z[ispin] << "Matrix Dimension of dHz(R): " << PARAM.globalv.nlocal << std::endl; g1z[ispin] << "Matrix number of dHz(R): " << output_R_number << std::endl; @@ -714,6 +716,7 @@ void ModuleIO::save_sparse( std::ofstream ofs; if (!reduce || GlobalV::DRANK == 0) { if (binary) { + int nlocal = PARAM.globalv.nlocal; if (PARAM.inp.calculation == "md" && PARAM.inp.out_app_flag && istep) { ofs.open(sss.str().c_str(), std::ios::binary | std::ios::app); @@ -721,7 +724,7 @@ void ModuleIO::save_sparse( ofs.open(sss.str().c_str(), std::ios::binary); } ofs.write(reinterpret_cast(0), sizeof(int)); - ofs.write(reinterpret_cast(&GlobalV::NLOCAL), sizeof(int)); + ofs.write(reinterpret_cast(&nlocal), sizeof(int)); ofs.write(reinterpret_cast(&output_R_number), sizeof(int)); } else { if (PARAM.inp.calculation == "md" && PARAM.inp.out_app_flag @@ -731,7 +734,7 @@ void ModuleIO::save_sparse( ofs.open(sss.str().c_str()); } ofs << "STEP: " << std::max(istep, 0) << std::endl; - ofs << "Matrix Dimension of " + label + "(R): " << GlobalV::NLOCAL + ofs << "Matrix Dimension of " + label + "(R): " << PARAM.globalv.nlocal << std::endl; ofs << "Matrix number of " + label + "(R): " << output_R_number << std::endl; diff --git a/source/module_io/write_dos_lcao.cpp b/source/module_io/write_dos_lcao.cpp index cc7a1ec487..dcdfc211f0 100644 --- a/source/module_io/write_dos_lcao.cpp +++ b/source/module_io/write_dos_lcao.cpp @@ -53,7 +53,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, double emin = ekb(0, 0); for (int ik = 0; ik < kv.get_nks(); ++ik) { - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) + for (int ib = 0; ib < PARAM.inp.nbands; ++ib) { emax = std::max(emax, ekb(ik, ib)); emin = std::min(emin, ekb(ik, ib)); @@ -94,7 +94,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, const int npoints = static_cast(std::floor((emax - emin) / de_ev)); - int NUM = GlobalV::NLOCAL * npoints; + int NUM = PARAM.globalv.nlocal * npoints; const int np = npoints; ModuleBase::matrix* pdosk = new ModuleBase::matrix[nspin0]; @@ -102,19 +102,19 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, for (int is = 0; is < nspin0; ++is) { - pdosk[is].create(GlobalV::NLOCAL, np, true); + pdosk[is].create(PARAM.globalv.nlocal, np, true); } ModuleBase::matrix* pdos = new ModuleBase::matrix[nspin0]; for (int is = 0; is < nspin0; ++is) { - pdos[is].create(GlobalV::NLOCAL, np, true); + pdos[is].create(PARAM.globalv.nlocal, np, true); } double a = bcoeff; double c = 2 * 3.141592653; double b = sqrt(c) * a; - std::complex* waveg = new std::complex[GlobalV::NLOCAL]; + std::complex* waveg = new std::complex[PARAM.globalv.nlocal]; double* Gauss = new double[np]; @@ -127,9 +127,9 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, psi->fix_k(is); const double* ppsi = psi->get_pointer(); - for (int i = 0; i < GlobalV::NBANDS; ++i) + for (int i = 0; i < PARAM.inp.nbands; ++i) { - ModuleBase::GlobalFunc::ZEROS(waveg, GlobalV::NLOCAL); + ModuleBase::GlobalFunc::ZEROS(waveg, PARAM.globalv.nlocal); ModuleBase::GlobalFunc::ZEROS(Gauss, np); for (int n = 0; n < npoints; ++n) @@ -149,8 +149,8 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, #ifdef __MPI const char T_char = 'T'; pdgemv_(&T_char, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, &one_float, sk, &one_int, @@ -169,7 +169,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, &one_int); #endif - for (int j = 0; j < GlobalV::NLOCAL; ++j) + for (int j = 0; j < PARAM.globalv.nlocal; ++j) { if (pv.in_this_processor(j, i)) @@ -204,7 +204,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, { double y = 0.0; double en = emin + n * de_ev; - for (int i = 0; i < GlobalV::NLOCAL; i++) + for (int i = 0; i < PARAM.globalv.nlocal; i++) { y += pdos[0](i, n); } @@ -219,7 +219,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, double y = 0.0; double z = 0.0; double en = emin + n * de_ev; - for (int i = 0; i < GlobalV::NLOCAL; i++) + for (int i = 0; i < PARAM.globalv.nlocal; i++) { y += pdos[0](i, n); z += pdos[1](i, n); @@ -241,9 +241,9 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, out << "" << std::endl; out << "" << PARAM.inp.nspin << "" << std::endl; if (PARAM.inp.nspin == 4) { - out << "" << std::setw(2) << GlobalV::NLOCAL / 2 << "" << std::endl; + out << "" << std::setw(2) << PARAM.globalv.nlocal / 2 << "" << std::endl; } else { - out << "" << std::setw(2) << GlobalV::NLOCAL << "" << std::endl; + out << "" << std::setw(2) << PARAM.globalv.nlocal << "" << std::endl; } out << "" << std::endl; @@ -332,7 +332,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi* psi, kv.get_nkstot(), kv.wk, kv.isk, - GlobalV::NBANDS, + PARAM.inp.nbands, ekb, wg); } @@ -364,7 +364,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, double emin = ekb(0, 0); for (int ik = 0; ik < kv.get_nks(); ++ik) { - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) + for (int ib = 0; ib < PARAM.inp.nbands; ++ib) { emax = std::max(emax, ekb(ik, ib)); emin = std::min(emin, ekb(ik, ib)); @@ -406,7 +406,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, const int npoints = static_cast(std::floor((emax - emin) / de_ev)); - int NUM = GlobalV::NLOCAL * npoints; + int NUM = PARAM.globalv.nlocal * npoints; const int np = npoints; @@ -416,21 +416,21 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, for (int is = 0; is < nspin0; ++is) { - pdosk[is].create(GlobalV::NLOCAL, np, true); + pdosk[is].create(PARAM.globalv.nlocal, np, true); } ModuleBase::matrix* pdos = new ModuleBase::matrix[nspin0]; for (int is = 0; is < nspin0; ++is) { - pdos[is].create(GlobalV::NLOCAL, np, true); + pdos[is].create(PARAM.globalv.nlocal, np, true); } double a = bcoeff; double c = 2 * 3.141592653; double b = sqrt(c) * a; - std::complex* waveg = new std::complex[GlobalV::NLOCAL]; + std::complex* waveg = new std::complex[PARAM.globalv.nlocal]; double* Gauss = new double[np](); @@ -466,10 +466,10 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, p_dwfc[index] = conj(p_dwfc[index]); } - for (int i = 0; i < GlobalV::NBANDS; ++i) + for (int i = 0; i < PARAM.inp.nbands; ++i) { - ModuleBase::GlobalFunc::ZEROS(waveg, GlobalV::NLOCAL); + ModuleBase::GlobalFunc::ZEROS(waveg, PARAM.globalv.nlocal); ModuleBase::GlobalFunc::ZEROS(Gauss, np); for (int n = 0; n < npoints; ++n) @@ -490,8 +490,8 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, #ifdef __MPI pzgemv_(&T_char, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, &one_float[0], sk, &one_int, @@ -510,7 +510,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, &one_int); #endif - for (int j = 0; j < GlobalV::NLOCAL; ++j) + for (int j = 0; j < PARAM.globalv.nlocal; ++j) { if (pv.in_this_processor(j, i)) @@ -551,7 +551,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, { double y = 0.0; double en = emin + n * de_ev; - for (int i = 0; i < GlobalV::NLOCAL; i++) + for (int i = 0; i < PARAM.globalv.nlocal; i++) { y += pdos[0](i, n); } @@ -566,7 +566,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, double y = 0.0; double z = 0.0; double en = emin + n * de_ev; - for (int i = 0; i < GlobalV::NLOCAL; i++) + for (int i = 0; i < PARAM.globalv.nlocal; i++) { y += pdos[0](i, n); z += pdos[1](i, n); @@ -589,11 +589,11 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, out << "" << PARAM.inp.nspin << "" << std::endl; if (PARAM.inp.nspin == 4) { - out << "" << std::setw(2) << GlobalV::NLOCAL / 2 << "" << std::endl; + out << "" << std::setw(2) << PARAM.globalv.nlocal / 2 << "" << std::endl; } else { - out << "" << std::setw(2) << GlobalV::NLOCAL << "" << std::endl; + out << "" << std::setw(2) << PARAM.globalv.nlocal << "" << std::endl; } out << "" << std::endl; @@ -681,7 +681,7 @@ void ModuleIO::write_dos_lcao(const psi::Psi>* psi, kv.get_nkstot(), kv.wk, kv.isk, - GlobalV::NBANDS, + PARAM.inp.nbands, ekb, wg); } diff --git a/source/module_io/write_dos_pw.cpp b/source/module_io/write_dos_pw.cpp index d6e07d20ed..302c21e16f 100644 --- a/source/module_io/write_dos_pw.cpp +++ b/source/module_io/write_dos_pw.cpp @@ -22,7 +22,7 @@ void ModuleIO::write_dos_pw(const ModuleBase::matrix& ekb, double emin = ekb(0, 0); for (int ik = 0; ik < kv.get_nks(); ++ik) { - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) + for (int ib = 0; ib < PARAM.inp.nbands; ++ib) { emax = std::max(emax, ekb(ik, ib)); emin = std::min(emin, ekb(ik, ib)); @@ -78,7 +78,7 @@ void ModuleIO::write_dos_pw(const ModuleBase::matrix& ekb, kv.get_nkstot(), kv.wk, kv.isk, - GlobalV::NBANDS, + PARAM.inp.nbands, ekb, wg); } diff --git a/source/module_io/write_istate_info.cpp b/source/module_io/write_istate_info.cpp index 5fa53e813e..f69af91116 100644 --- a/source/module_io/write_istate_info.cpp +++ b/source/module_io/write_istate_info.cpp @@ -41,7 +41,7 @@ void ModuleIO::write_istate_info(const ModuleBase::matrix &ekb,const ModuleBase: << std::setw(25) << "Kpoint = " << ik_global << std::setw(25) << "(" << kv.kvec_d[ik].x << " " << kv.kvec_d[ik].y << " " << kv.kvec_d[ik].z << ")" << std::endl; - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { ofsi2.precision(16); ofsi2 << std::setw(6) << ib + 1 << std::setw(25) @@ -67,7 +67,7 @@ void ModuleIO::write_istate_info(const ModuleBase::matrix &ekb,const ModuleBase: << std::setw(25) << "(" << kv.kvec_d[ik].x << " " << kv.kvec_d[ik].y << " " << kv.kvec_d[ik].z << ")" << std::endl; - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { ofsi2 << std::setw(6) << ib + 1 << std::setw(25) << ekb(ik, ib) * ModuleBase::Ry_to_eV << std::setw(25) << wg(ik, ib) diff --git a/source/module_io/write_proj_band_lcao.cpp b/source/module_io/write_proj_band_lcao.cpp index c308bc0992..ccd7a0d4b0 100644 --- a/source/module_io/write_proj_band_lcao.cpp +++ b/source/module_io/write_proj_band_lcao.cpp @@ -39,9 +39,9 @@ void ModuleIO::write_proj_band_lcao( ModuleBase::ComplexMatrix weightk; ModuleBase::matrix weight; - int NUM = GlobalV::NLOCAL * GlobalV::NBANDS * nspin0; - weightk.create(nspin0, GlobalV::NBANDS * GlobalV::NLOCAL, true); - weight.create(nspin0, GlobalV::NBANDS * GlobalV::NLOCAL, true); + int NUM = PARAM.globalv.nlocal * PARAM.inp.nbands * nspin0; + weightk.create(nspin0, PARAM.inp.nbands * PARAM.globalv.nlocal, true); + weight.create(nspin0, PARAM.inp.nbands * PARAM.globalv.nlocal, true); for (int is = 0; is < nspin0; is++) @@ -51,7 +51,7 @@ void ModuleIO::write_proj_band_lcao( Mulk[0].create(pv.ncol, pv.nrow); psi->fix_k(is); - for (int i = 0; i < GlobalV::NBANDS; ++i) + for (int i = 0; i < PARAM.inp.nbands; ++i) { const int NB = i + 1; @@ -60,8 +60,8 @@ void ModuleIO::write_proj_band_lcao( #ifdef __MPI const char T_char = 'T'; pdgemv_(&T_char, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, &one_float, sk, &one_int, @@ -79,14 +79,14 @@ void ModuleIO::write_proj_band_lcao( pv.desc, &one_int); #endif - for (int j = 0; j < GlobalV::NLOCAL; ++j) + for (int j = 0; j < PARAM.globalv.nlocal; ++j) { if (pv.in_this_processor(j, i)) { const int ir = pv.global2local_row(j); const int ic = pv.global2local_col(i); - weightk(is, i * GlobalV::NLOCAL + j) = Mulk[0](ic, ir) * psi[0](ic, ir); + weightk(is, i * PARAM.globalv.nlocal + j) = Mulk[0](ic, ir) * psi[0](ic, ir); } } } // ib @@ -104,12 +104,12 @@ void ModuleIO::write_proj_band_lcao( out << "" << std::endl; out << "" << PARAM.inp.nspin << "" << std::endl; if (PARAM.inp.nspin == 4) - out << "" << std::setw(2) << GlobalV::NLOCAL / 2 << "" << std::endl; + out << "" << std::setw(2) << PARAM.globalv.nlocal / 2 << "" << std::endl; else - out << "" << std::setw(2) << GlobalV::NLOCAL << "" << std::endl; - out << "" + out << "" << std::setw(2) << PARAM.globalv.nlocal << "" << std::endl; + out << "" << std::endl; - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) out << " " << (pelec->ekb(is * nks, ib)) * ModuleBase::Ry_to_eV; out << std::endl; out << "" << std::endl; @@ -137,16 +137,16 @@ void ModuleIO::write_proj_band_lcao( out << std::setw(2) << "z=\"" << std::setw(40) << N1 + 1 << "\"" << std::endl; out << ">" << std::endl; out << "" << std::endl; - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) - out << std::setw(13) << weight(is, ib * GlobalV::NLOCAL + w); + out << std::setw(13) << weight(is, ib * PARAM.globalv.nlocal + w); else if (PARAM.inp.nspin == 4) { int w0 = w - s0; out << std::setw(13) - << weight(is, ib * GlobalV::NLOCAL + s0 + 2 * w0) - + weight(is, ib * GlobalV::NLOCAL + s0 + 2 * w0 + 1); + << weight(is, ib * PARAM.globalv.nlocal + s0 + 2 * w0) + + weight(is, ib * PARAM.globalv.nlocal + s0 + 2 * w0 + 1); } } out << std::endl; @@ -192,9 +192,9 @@ void ModuleIO::write_proj_band_lcao( ModuleBase::ComplexMatrix weightk; ModuleBase::matrix weight; - int NUM = GlobalV::NLOCAL * GlobalV::NBANDS * kv.get_nks(); - weightk.create(kv.get_nks(), GlobalV::NBANDS * GlobalV::NLOCAL, true); - weight.create(kv.get_nks(), GlobalV::NBANDS * GlobalV::NLOCAL, true); + int NUM = PARAM.globalv.nlocal * PARAM.inp.nbands * kv.get_nks(); + weightk.create(kv.get_nks(), PARAM.inp.nbands * PARAM.globalv.nlocal, true); + weight.create(kv.get_nks(), PARAM.inp.nbands * PARAM.globalv.nlocal, true); for (int is = 0; is < nspin0; is++) { @@ -228,7 +228,7 @@ void ModuleIO::write_proj_band_lcao( p_dwfc[index] = conj(p_dwfc[index]); } - for (int i = 0; i < GlobalV::NBANDS; ++i) + for (int i = 0; i < PARAM.inp.nbands; ++i) { const int NB = i + 1; @@ -238,8 +238,8 @@ void ModuleIO::write_proj_band_lcao( const char T_char = 'T'; #ifdef __MPI pzgemv_(&T_char, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, + &PARAM.globalv.nlocal, + &PARAM.globalv.nlocal, &one_float[0], sk, &one_int, @@ -257,7 +257,7 @@ void ModuleIO::write_proj_band_lcao( pv.desc, &one_int); #endif - for (int j = 0; j < GlobalV::NLOCAL; ++j) + for (int j = 0; j < PARAM.globalv.nlocal; ++j) { if (pv.in_this_processor(j, i)) @@ -266,7 +266,7 @@ void ModuleIO::write_proj_band_lcao( const int ir = pv.global2local_row(j); const int ic = pv.global2local_col(i); - weightk(ik, i * GlobalV::NLOCAL + j) = Mulk[0](ic, ir) * psi[0](ic, ir); + weightk(ik, i * PARAM.globalv.nlocal + j) = Mulk[0](ic, ir) * psi[0](ic, ir); } } @@ -289,19 +289,19 @@ void ModuleIO::write_proj_band_lcao( out << "" << PARAM.inp.nspin << "" << std::endl; if (PARAM.inp.nspin == 4) { - out << "" << std::setw(2) << GlobalV::NLOCAL / 2 << "" << std::endl; + out << "" << std::setw(2) << PARAM.globalv.nlocal / 2 << "" << std::endl; } else { - out << "" << std::setw(2) << GlobalV::NLOCAL << "" << std::endl; + out << "" << std::setw(2) << PARAM.globalv.nlocal << "" << std::endl; } - out << "" + out << "" << std::endl; for (int ik = 0; ik < nks; ik++) { - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) out << " " << (pelec->ekb(ik + is * nks, ib)) * ModuleBase::Ry_to_eV; out << std::endl; } @@ -332,22 +332,22 @@ void ModuleIO::write_proj_band_lcao( out << "" << std::endl; for (int ik = 0; ik < nks; ik++) { - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { if (PARAM.inp.nspin == 1) { - out << std::setw(13) << weight(ik, ib * GlobalV::NLOCAL + w); + out << std::setw(13) << weight(ik, ib * PARAM.globalv.nlocal + w); } else if (PARAM.inp.nspin == 2) { - out << std::setw(13) << weight(ik + nks * is, ib * GlobalV::NLOCAL + w); + out << std::setw(13) << weight(ik + nks * is, ib * PARAM.globalv.nlocal + w); } else if (PARAM.inp.nspin == 4) { int w0 = w - s0; out << std::setw(13) - << weight(ik, ib * GlobalV::NLOCAL + s0 + 2 * w0) - + weight(ik, ib * GlobalV::NLOCAL + s0 + 2 * w0 + 1); + << weight(ik, ib * PARAM.globalv.nlocal + s0 + 2 * w0) + + weight(ik, ib * PARAM.globalv.nlocal + s0 + 2 * w0 + 1); } } out << std::endl; diff --git a/source/module_io/write_wfc_pw.cpp b/source/module_io/write_wfc_pw.cpp index f0ac033ec2..dc11342994 100644 --- a/source/module_io/write_wfc_pw.cpp +++ b/source/module_io/write_wfc_pw.cpp @@ -101,7 +101,7 @@ void ModuleIO::write_wfc_pw(const std::string& fn, ofs2 << std::setw(10) << ikstot + 1 << std::setw(10) << nkstot << std::setw(10) << kv.kvec_c[ik].x << std::setw(10) << kv.kvec_c[ik].y << std::setw(10) << kv.kvec_c[ik].z << std::setw(10) << kv.wk[ik] << std::setw(10) << ikngtot - << std::setw(10) << GlobalV::NBANDS << std::setw(10) << PARAM.inp.ecutwfc + << std::setw(10) << PARAM.inp.nbands << std::setw(10) << PARAM.inp.ecutwfc << std::setw(10) << wfcpw->lat0 << std::setw(10) << wfcpw->tpiba << std::endl; ofs2 << "\n" << std::endl; ofs2 << std::setw(10) << wfcpw->G.e11 << std::setw(10) << wfcpw->G.e12 << std::setw(10) @@ -136,7 +136,7 @@ void ModuleIO::write_wfc_pw(const std::string& fn, if (id == 0) { wfs2 << int(72) << ikstot + 1 << nkstot << kv.kvec_c[ik].x << kv.kvec_c[ik].y - << kv.kvec_c[ik].z << kv.wk[ik] << ikngtot << GlobalV::NBANDS << PARAM.inp.ecutwfc + << kv.kvec_c[ik].z << kv.wk[ik] << ikngtot << PARAM.inp.nbands << PARAM.inp.ecutwfc << wfcpw->lat0 << wfcpw->tpiba << 72; // 4 int + 7 double is 72B wfs2 << 72 << wfcpw->G.e11 << wfcpw->G.e12 << wfcpw->G.e13 << wfcpw->G.e21 << wfcpw->G.e22 << wfcpw->G.e23 << wfcpw->G.e31 << wfcpw->G.e32 << wfcpw->G.e33 @@ -167,7 +167,7 @@ void ModuleIO::write_wfc_pw(const std::string& fn, } } // end id #endif - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { #ifdef __MPI for (int id = 0; id < GlobalV::NPROC_IN_POOL; id++) diff --git a/source/module_lr/esolver_lrtd_lcao.cpp b/source/module_lr/esolver_lrtd_lcao.cpp index 5bc9674aae..4c87eadb40 100644 --- a/source/module_lr/esolver_lrtd_lcao.cpp +++ b/source/module_lr/esolver_lrtd_lcao.cpp @@ -90,12 +90,12 @@ void LR::ESolver_LR::set_dimension() if (nspin == 2) { std::cout << "** Assuming the spin-up and spin-down states are degenerate. **" << std::endl; } this->nstates = input.lr_nstates; - this->nbasis = GlobalV::NLOCAL; + this->nbasis = PARAM.globalv.nlocal; // calculate the number of occupied and unoccupied states // which determines the basis size of the excited states this->nocc_max = LR_Util::cal_nocc(LR_Util::cal_nelec(ucell)); this->nocc = std::max(1, std::min(input.nocc, this->nocc_max)); - this->nvirt = GlobalV::NBANDS - this->nocc_max; //nbands-nocc + this->nvirt = PARAM.inp.nbands - this->nocc_max; //nbands-nocc if (input.nvirt > this->nvirt) { GlobalV::ofs_warning << "ESolver_LR: input nvirt is too large to cover by nbands, set nvirt = nbands - nocc = " << this->nvirt << std::endl; } else if (input.nvirt > 0) { this->nvirt = input.nvirt; @@ -166,7 +166,7 @@ LR::ESolver_LR::ESolver_LR(ModuleESolver::ESolver_KS_LCAO&& ks_sol this->eig_ks = std::move(ks_sol.pelec->ekb); }; #ifdef __MPI - if (this->nbands == GlobalV::NBANDS) { move_gs(); } + if (this->nbands == PARAM.inp.nbands) { move_gs(); } else // copy the part of ground state info according to paraC_ { this->psi_ks = new psi::Psi(this->kv.get_nks(), this->paraC_.get_col_size(), this->paraC_.get_row_size()); diff --git a/source/module_lr/hsolver_lrtd.cpp b/source/module_lr/hsolver_lrtd.cpp index 0e954a2cd9..5f76edd7a4 100644 --- a/source/module_lr/hsolver_lrtd.cpp +++ b/source/module_lr/hsolver_lrtd.cpp @@ -96,7 +96,7 @@ namespace LR }; auto spsi_func = [pHamilt](const T* psi_in, T* spsi_out, const int nrow, const int npw, const int nbands){ - // sPsi determines S=I or not by GlobalV::use_uspp inside + // sPsi determines S=I or not by PARAM.globalv.use_uspp inside pHamilt->sPsi(psi_in, spsi_out, nrow, npw, nbands); }; diff --git a/source/module_parameter/input_parameter.h b/source/module_parameter/input_parameter.h index 57bcab403d..f5abc047d9 100644 --- a/source/module_parameter/input_parameter.h +++ b/source/module_parameter/input_parameter.h @@ -68,7 +68,7 @@ struct Input_para std::vector kspacing = {0.0, 0.0, 0.0}; ///< kspacing for k-point generation double min_dist_coef = 0.2; ///< allowed minimum distance between two atoms - std::string device = "cpu"; + std::string device = "auto"; std::string precision = "double"; // ============== #Parameters (2.Electronic structure) =========================== diff --git a/source/module_parameter/system_parameter.h b/source/module_parameter/system_parameter.h index 4d25adabde..c160a663d8 100644 --- a/source/module_parameter/system_parameter.h +++ b/source/module_parameter/system_parameter.h @@ -19,8 +19,9 @@ struct System_para // ------------ parameters not defined in INPUT file ------------- // ------------ but decided by INPUT parameters ------------- // --------------------------------------------------------------- + int nlocal = 0; ///< total number of local basis. bool two_fermi = false; ///< true if "nupdown" is set - + bool use_uspp = false; ///< true if "uspp" is set bool dos_setemin = false; ///< true: "dos_emin_ev" is set bool dos_setemax = false; ///< true: "dos_emax_ev" is set @@ -48,7 +49,6 @@ struct System_para bool domag = false; /// 1 : calculate the magnetism with x, y, z component bool domag_z = false; /// 1 : constrain the magnetism to z axis - std::string device_flag = "cpu"; ///< device flag, "cpu" or "gpu" bool double_grid = false; ///< true if "ndx,ndy,ndz" is larger than "nx,ny,nz" double uramping = -10.0 / 13.6; /// U-Ramping method (Ry) std::vector hubbard_u = {}; ///< Hubbard Coulomb interaction parameter U (Ry) diff --git a/source/module_psi/psi_initializer.cpp b/source/module_psi/psi_initializer.cpp index 22a64104d7..ef09d98a89 100644 --- a/source/module_psi/psi_initializer.cpp +++ b/source/module_psi/psi_initializer.cpp @@ -16,7 +16,7 @@ psi::Psi>* psi_initializer::allocate(const bool { ModuleBase::timer::tick("psi_initializer", "allocate"); /* - WARNING: when basis_type = "pw", the variable GlobalV::NLOCAL will also be set, in this case, it is set to + WARNING: when basis_type = "pw", the variable PARAM.globalv.nlocal will also be set, in this case, it is set to 9 = 1 + 3 + 5, which is the maximal number of orbitals spd, I don't think it is reasonable The way of calculating this->p_ucell_->natomwfc is, for each atom, read pswfc and for s, it is 1, for p, it is 3 , then multiplied by the number of atoms, and then add them together. @@ -24,20 +24,20 @@ psi::Psi>* psi_initializer::allocate(const bool int nbands_actual = 0; if(this->method_ == "random") { - nbands_actual = GlobalV::NBANDS; + nbands_actual = PARAM.inp.nbands; this->nbands_complem_ = 0; } else { if(this->method_.substr(0, 6) == "atomic") { - nbands_actual = std::max(this->p_ucell_->natomwfc, GlobalV::NBANDS); + nbands_actual = std::max(this->p_ucell_->natomwfc, PARAM.inp.nbands); this->nbands_complem_ = nbands_actual - this->p_ucell_->natomwfc; } else if(this->method_.substr(0, 3) == "nao") { /* - previously GlobalV::NLOCAL is used here, however it is wrong. GlobalV::NLOCAL is fixed to 9*nat. + previously PARAM.globalv.nlocal is used here, however it is wrong. PARAM.globalv.nlocal is fixed to 9*nat. */ int nbands_local = 0; for(int it = 0; it < this->p_ucell_->ntype; it++) @@ -58,7 +58,7 @@ psi::Psi>* psi_initializer::allocate(const bool */ } } - nbands_actual = std::max(nbands_local, GlobalV::NBANDS); + nbands_actual = std::max(nbands_local, PARAM.inp.nbands); this->nbands_complem_ = nbands_actual - nbands_local; } } @@ -70,10 +70,10 @@ psi::Psi>* psi_initializer::allocate(const bool if(!only_psig) { psi_out = new psi::Psi>(nks_psi, - GlobalV::NBANDS, // because no matter what, the wavefunction finally needed has GlobalV::NBANDS bands + PARAM.inp.nbands, // because no matter what, the wavefunction finally needed has PARAM.inp.nbands bands nbasis_actual, this->pw_wfc_->npwk); - double memory_cost_psi = nks_psi * GlobalV::NBANDS * this->pw_wfc_->npwk_max * PARAM.globalv.npol* + double memory_cost_psi = nks_psi * PARAM.inp.nbands * this->pw_wfc_->npwk_max * PARAM.globalv.npol* sizeof(std::complex); #ifdef __MPI // get the correct memory cost for psi by all-reduce sum @@ -100,11 +100,11 @@ psi::Psi>* psi_initializer::allocate(const bool GlobalV::ofs_running << "Allocate memory for psi and psig done.\n" << "Print detailed information of dimension of psi and psig:\n" - << "psi: (" << nks_psi << ", " << GlobalV::NBANDS << ", " << nbasis_actual << ")\n" + << "psi: (" << nks_psi << ", " << PARAM.inp.nbands << ", " << nbasis_actual << ")\n" << "psig: (" << nks_psig << ", " << nbands_actual << ", " << nbasis_actual << ")\n" << "nks (psi) = " << nks_psi << "\n" << "nks (psig) = " << nks_psig << "\n" - << "GlobalV::NBANDS = " << GlobalV::NBANDS << "\n" + << "PARAM.inp.nbands = " << PARAM.inp.nbands << "\n" << "nbands_actual = " << nbands_actual << "\n" << "nbands_complem = " << this->nbands_complem_ << "\n" << "nbasis_actual = " << nbasis_actual << "\n" diff --git a/source/module_psi/test/psi_initializer_unit_test.cpp b/source/module_psi/test/psi_initializer_unit_test.cpp index 989d1f045a..bc0941e121 100644 --- a/source/module_psi/test/psi_initializer_unit_test.cpp +++ b/source/module_psi/test/psi_initializer_unit_test.cpp @@ -115,7 +115,7 @@ class PsiIntializerUnitTest : public ::testing::Test { this->p_parakpts = new Parallel_Kpoints(); #endif // mock - GlobalV::NBANDS = 1; + PARAM.input.nbands = 1; PARAM.input.nspin = 1; PARAM.input.orbital_dir = "./support/"; PARAM.input.pseudo_dir = "./support/"; diff --git a/source/module_ri/RPA_LRI.hpp b/source/module_ri/RPA_LRI.hpp index d60bc87f1d..df1602d696 100644 --- a/source/module_ri/RPA_LRI.hpp +++ b/source/module_ri/RPA_LRI.hpp @@ -164,10 +164,10 @@ void RPA_LRI::out_eigen_vector(const Parallel_Orbitals& parav, const p std::vector is_wfc_ib_iw(npsin_tmp); for (int is = 0; is < npsin_tmp; is++) { - is_wfc_ib_iw[is].create(GlobalV::NBANDS, GlobalV::NLOCAL); - for (int ib_global = 0; ib_global < GlobalV::NBANDS; ++ib_global) + is_wfc_ib_iw[is].create(PARAM.inp.nbands, PARAM.globalv.nlocal); + for (int ib_global = 0; ib_global < PARAM.inp.nbands; ++ib_global) { - std::vector> wfc_iks(GlobalV::NLOCAL, zero); + std::vector> wfc_iks(PARAM.globalv.nlocal, zero); const int ib_local = parav.global2local_col(ib_global); @@ -181,18 +181,18 @@ void RPA_LRI::out_eigen_vector(const Parallel_Orbitals& parav, const p std::vector> tmp = wfc_iks; #ifdef __MPI - MPI_Allreduce(&tmp[0], &wfc_iks[0], GlobalV::NLOCAL, MPI_DOUBLE_COMPLEX, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(&tmp[0], &wfc_iks[0], PARAM.globalv.nlocal, MPI_DOUBLE_COMPLEX, MPI_SUM, MPI_COMM_WORLD); #endif - for (int iw = 0; iw < GlobalV::NLOCAL; iw++) + for (int iw = 0; iw < PARAM.globalv.nlocal; iw++) { is_wfc_ib_iw[is](ib_global, iw) = wfc_iks[iw]; } } // ib } // is ofs << ik + 1 << std::endl; - for (int iw = 0; iw < GlobalV::NLOCAL; iw++) + for (int iw = 0; iw < PARAM.globalv.nlocal; iw++) { - for (int ib = 0; ib < GlobalV::NBANDS; ib++) + for (int ib = 0; ib < PARAM.inp.nbands; ib++) { for (int is = 0; is < npsin_tmp; is++) { @@ -259,8 +259,8 @@ void RPA_LRI::out_bands(const elecstate::ElecState* pelec) ofs.open(ss.str().c_str(), std::ios::out); ofs << nks_tot << std::endl; ofs << PARAM.inp.nspin << std::endl; - ofs << GlobalV::NBANDS << std::endl; - ofs << GlobalV::NLOCAL << std::endl; + ofs << PARAM.inp.nbands << std::endl; + ofs << PARAM.globalv.nlocal << std::endl; ofs << (pelec->eferm.ef / 2.0) << std::endl; for (int ik = 0; ik != nks_tot; ik++) @@ -268,7 +268,7 @@ void RPA_LRI::out_bands(const elecstate::ElecState* pelec) for (int is = 0; is != nspin_tmp; is++) { ofs << std::setw(6) << ik + 1 << std::setw(6) << is + 1 << std::endl; - for (int ib = 0; ib != GlobalV::NBANDS; ib++) + for (int ib = 0; ib != PARAM.inp.nbands; ib++) { ofs << std::setw(5) << ib + 1 << " " << std::setw(8) << pelec->wg(ik + is * nks_tot, ib) * nks_tot << std::setw(18) << std::fixed << std::setprecision(8) << pelec->ekb(ik + is * nks_tot, ib) / 2.0 diff --git a/source/module_ri/exx_lip.cpp b/source/module_ri/exx_lip.cpp index e3a6016e58..b62792310c 100644 --- a/source/module_ri/exx_lip.cpp +++ b/source/module_ri/exx_lip.cpp @@ -30,17 +30,17 @@ void Exx_Lip::cal_exx() //t_phi_cal += my_time(t); judge_singularity(ik); - for (int iw_l = 0; iw_l < GlobalV::NLOCAL; ++iw_l) { - for (int iw_r = 0; iw_r < GlobalV::NLOCAL; ++iw_r) { - sum1[iw_l * GlobalV::NLOCAL + iw_r] = T(0.0, 0.0); + for (int iw_l = 0; iw_l < PARAM.globalv.nlocal; ++iw_l) { + for (int iw_r = 0; iw_r < PARAM.globalv.nlocal; ++iw_r) { + sum1[iw_l * PARAM.globalv.nlocal + iw_r] = T(0.0, 0.0); } } if (Conv_Coulomb_Pot_K::Ccp_Type::Ccp == info.ccp_type || Conv_Coulomb_Pot_K::Ccp_Type::Hf == info.ccp_type) { sum2_factor = 0.0; if (gzero_rank_in_pool == GlobalV::RANK_IN_POOL) { - for (int iw_l = 0; iw_l < GlobalV::NLOCAL; ++iw_l) { - for (int iw_r = 0; iw_r < GlobalV::NLOCAL; ++iw_r) { + for (int iw_l = 0; iw_l < PARAM.globalv.nlocal; ++iw_l) { + for (int iw_r = 0; iw_r < PARAM.globalv.nlocal; ++iw_r) { sum3[iw_l][iw_r] = T(0.0, 0.0); } } @@ -54,7 +54,7 @@ void Exx_Lip::cal_exx() (iq_tmp % (q_pack->kv_ptr->get_nks() / PARAM.inp.nspin) + (q_pack->kv_ptr->get_nks() / PARAM.inp.nspin)); qkg2_exp(ik, iq); //t_qkg2_exp += my_time(t); - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) + for (int ib = 0; ib < PARAM.inp.nbands; ++ib) { b_cal(ik, iq, ib); //t_b_cal += my_time(t); @@ -80,9 +80,9 @@ void Exx_Lip::cal_exx() { std::ofstream ofs("Hexxk_" + ModuleBase::GlobalFunc::TO_STRING(istep++) + "_" + ModuleBase::GlobalFunc::TO_STRING(ik) + "_" + ModuleBase::GlobalFunc::TO_STRING(GlobalV::MY_RANK)); - for (int i = 0; i != GlobalV::NLOCAL; ++i) + for (int i = 0; i != PARAM.globalv.nlocal; ++i) { - for (int j = 0; j != GlobalV::NLOCAL; ++j) { + for (int j = 0; j != PARAM.globalv.nlocal; ++j) { ofs << exx_matrix[ik][i][j] << "\t"; } ofs << std::endl; @@ -102,15 +102,15 @@ void Exx_Lip::cal_exx() phi_cal(k_pack, ik); judge_singularity(ik); - for( int iw_l=0; iw_l(0.0,0.0); + for( int iw_l=0; iw_l(0.0,0.0); if( Exx_Info::Hybrid_Type::HF==info.hybrid_type || Exx_Info::Hybrid_Type::PBE0==info.hybrid_type || Exx_Info::Hybrid_Type::SCAN0==info.hybrid_type ) { sum2_factor = 0.0; if(gzero_rank_in_pool==GlobalV::RANK_IN_POOL) - for( int iw_l=0; iw_l(0.0,0.0); } @@ -118,7 +118,7 @@ void Exx_Lip::cal_exx() { int iq = (ik<(k_pack->kv_ptr->get_nks()/PARAM.inp.nspin)) ? (iq_tmp%(q_pack->kv_ptr->get_nks()/PARAM.inp.nspin)) : (iq_tmp%(q_pack->kv_ptr->get_nks()/PARAM.inp.nspin)+(q_pack->kv_ptr->get_nks()/PARAM.inp.nspin)); qkg2_exp(ik, iq); - for( int ib=0; ib::Exx_Lip( #ifdef __MPI MPI_Allreduce(&gzero_judge, &gzero_rank_in_pool, 1, MPI_INT, MPI_MAX, POOL_WORLD); #endif - k_pack->wf_wg.create(k_pack->kv_ptr->get_nks(),GlobalV::NBANDS); + k_pack->wf_wg.create(k_pack->kv_ptr->get_nks(),PARAM.inp.nbands); - k_pack->hvec_array = new psi::Psi(k_pack->kv_ptr->get_nks(), GlobalV::NBANDS, GlobalV::NLOCAL); + k_pack->hvec_array = new psi::Psi(k_pack->kv_ptr->get_nks(), PARAM.inp.nbands, PARAM.globalv.nlocal); // k_pack->hvec_array = new ModuleBase::ComplexMatrix[k_pack->kv_ptr->get_nks()]; // for( int ik=0; ikkv_ptr->get_nks(); ++ik) // { - // k_pack->hvec_array[ik].create(GlobalV::NLOCAL,GlobalV::NBANDS); + // k_pack->hvec_array[ik].create(PARAM.globalv.nlocal,PARAM.inp.nbands); // } // if (PARAM.inp.init_chg=="atomic") @@ -184,36 +184,36 @@ Exx_Lip::Exx_Lip( // read_q_pack(symm, wfc_basis, sf); // } - phi.resize(GlobalV::NLOCAL); - for (int iw = 0; iw < GlobalV::NLOCAL; ++iw) { phi[iw].resize(rho_basis->nrxx); } + phi.resize(PARAM.globalv.nlocal); + for (int iw = 0; iw < PARAM.globalv.nlocal; ++iw) { phi[iw].resize(rho_basis->nrxx); } psi.resize(q_pack->kv_ptr->get_nks()); for (int iq = 0; iq < q_pack->kv_ptr->get_nks(); ++iq) { - psi[iq].resize(GlobalV::NBANDS); - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) { psi[iq][ib].resize(rho_basis->nrxx); } + psi[iq].resize(PARAM.inp.nbands); + for (int ib = 0; ib < PARAM.inp.nbands; ++ib) { psi[iq][ib].resize(rho_basis->nrxx); } } recip_qkg2.resize(rho_basis->npw); - b.resize(GlobalV::NLOCAL * rho_basis->npw); + b.resize(PARAM.globalv.nlocal * rho_basis->npw); - sum1.resize(GlobalV::NLOCAL * GlobalV::NLOCAL); + sum1.resize(PARAM.globalv.nlocal * PARAM.globalv.nlocal); if (Conv_Coulomb_Pot_K::Ccp_Type::Ccp == info.ccp_type || Conv_Coulomb_Pot_K::Ccp_Type::Hf == info.ccp_type) { if (gzero_rank_in_pool == GlobalV::RANK_IN_POOL) { - b0.resize(GlobalV::NLOCAL); - sum3.resize(GlobalV::NLOCAL); - for (int iw_l = 0; iw_l < GlobalV::NLOCAL; ++iw_l) { sum3[iw_l].resize(GlobalV::NLOCAL); } + b0.resize(PARAM.globalv.nlocal); + sum3.resize(PARAM.globalv.nlocal); + for (int iw_l = 0; iw_l < PARAM.globalv.nlocal; ++iw_l) { sum3[iw_l].resize(PARAM.globalv.nlocal); } } } exx_matrix.resize(k_pack->kv_ptr->get_nks()); for (int ik = 0; ik < k_pack->kv_ptr->get_nks(); ++ik) { - exx_matrix[ik].resize(GlobalV::NLOCAL); - for (int iw_l = 0; iw_l < GlobalV::NLOCAL; ++iw_l) { exx_matrix[ik][iw_l].resize(GlobalV::NLOCAL); } + exx_matrix[ik].resize(PARAM.globalv.nlocal); + for (int iw_l = 0; iw_l < PARAM.globalv.nlocal; ++iw_l) { exx_matrix[ik][iw_l].resize(PARAM.globalv.nlocal); } } } catch (const std::bad_alloc& ex) @@ -248,13 +248,13 @@ void Exx_Lip::wf_wg_cal() ModuleBase::TITLE("Exx_Lip", "wf_wg_cal"); if (PARAM.inp.nspin == 1) { for (int ik = 0; ik < k_pack->kv_ptr->get_nks(); ++ik) { - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) { + for (int ib = 0; ib < PARAM.inp.nbands; ++ib) { k_pack->wf_wg(ik, ib) = k_pack->pelec->wg(ik, ib) / 2; } } } else if (PARAM.inp.nspin == 2) { for (int ik = 0; ik < k_pack->kv_ptr->get_nks(); ++ik) { - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) { + for (int ib = 0; ib < PARAM.inp.nbands; ++ib) { k_pack->wf_wg(ik, ib) = k_pack->pelec->wg(ik, ib); } } @@ -265,7 +265,7 @@ template void Exx_Lip::phi_cal(k_package* kq_pack, int ikq) { T* porter = new T[wfc_basis->nrxx]; - for (int iw = 0; iw < GlobalV::NLOCAL; ++iw) + for (int iw = 0; iw < PARAM.globalv.nlocal; ++iw) { // wfc_basis->recip2real(&kq_pack->wf_ptr->wanf2[ikq](iw,0), porter, ikq); wfc_basis->recip2real(&(kq_pack->wf_ptr->get_psig().lock()->operator()(ikq, iw, 0)), porter, ikq); @@ -297,7 +297,7 @@ void Exx_Lip::psi_cal() T* porter = new T[wfc_basis->nrxx]; for (int iq = 0; iq < q_pack->kv_ptr->get_nks(); ++iq) { - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) + for (int ib = 0; ib < PARAM.inp.nbands; ++ib) { wfc_basis->recip2real(&(q_pack->kspw_psi_ptr->operator()(iq, ib, 0)), porter, iq); @@ -326,10 +326,10 @@ void Exx_Lip::psi_cal() for (int iq = 0; iq < q_pack->kv_ptr->get_nks(); ++iq) { phi_cal(q_pack, iq); - for (int ib = 0; ib < GlobalV::NBANDS; ++ib) + for (int ib = 0; ib < PARAM.inp.nbands; ++ib) { ModuleBase::GlobalFunc::ZEROS(psi[iq][ib].data(), rho_basis->nrxx); - for (int iw = 0; iw < GlobalV::NLOCAL; ++iw) + for (int iw = 0; iw < PARAM.globalv.nlocal; ++iw) { for (int ir = 0; ir < rho_basis->nrxx; ++ir) { @@ -416,7 +416,7 @@ void Exx_Lip::b_cal(int ik, int iq, int ib) T* const porter = new T[rho_basis->nrxx]; - for(size_t iw=0; iw< GlobalV::NLOCAL; ++iw) + for(size_t iw=0; iw< PARAM.globalv.nlocal; ++iw) { auto& phi_w = phi[iw]; for( size_t ir=0; irnrxx; ++ir) @@ -443,8 +443,8 @@ template void Exx_Lip::sum3_cal(int iq, int ib) { if (gzero_rank_in_pool == GlobalV::RANK_IN_POOL) { - for (int iw_l = 0; iw_l < GlobalV::NLOCAL; ++iw_l) { - for (int iw_r = 0; iw_r < GlobalV::NLOCAL; ++iw_r) { + for (int iw_l = 0; iw_l < PARAM.globalv.nlocal; ++iw_l) { + for (int iw_r = 0; iw_r < PARAM.globalv.nlocal; ++iw_r) { sum3[iw_l][iw_r] += b0[iw_l] * conj(b0[iw_r]) * (Real)q_pack->wf_wg(iq, ib); } } @@ -457,13 +457,13 @@ void Exx_Lip::b_sum(int iq, int ib) // Peize Lin change 2019-04-14 // sum1[iw_l,iw_r] += \sum_{ig} b[iw_l,ig] * conj(b[iw_r,ig]) * q_pack->wf_wg(iq,ib) LapackConnector::herk( 'U','N', - GlobalV::NLOCAL, rho_basis->npw, + PARAM.globalv.nlocal, rho_basis->npw, (Real)q_pack->wf_wg(iq, ib), b.data(), rho_basis->npw, - 1.0, sum1.data(), GlobalV::NLOCAL); + 1.0, sum1.data(), PARAM.globalv.nlocal); // cblas_zherk( CblasRowMajor, CblasUpper, CblasNoTrans, -// GlobalV::NLOCAL, rho_basis->npw, +// PARAM.globalv.nlocal, rho_basis->npw, // q_pack->wf_wg(iq,ib), static_cast(b), rho_basis->npw, -// 1.0, static_cast(sum1), GlobalV::NLOCAL); +// 1.0, static_cast(sum1), PARAM.globalv.nlocal); } template @@ -477,17 +477,17 @@ void Exx_Lip::sum_all(int ik) MPI_Reduce(&sum2_factor, &sum2_factor_g, 1, MPI_DOUBLE, MPI_SUM, gzero_rank_in_pool, POOL_WORLD); } #endif - for (size_t iw_l = 1; iw_l < GlobalV::NLOCAL; ++iw_l) { + for (size_t iw_l = 1; iw_l < PARAM.globalv.nlocal; ++iw_l) { for (size_t iw_r = 0; iw_r < iw_l; ++iw_r) { - sum1[iw_l * GlobalV::NLOCAL + iw_r] = conj(sum1[iw_r * GlobalV::NLOCAL + iw_l]); // Peize Lin add conj 2019-04-14 + sum1[iw_l * PARAM.globalv.nlocal + iw_r] = conj(sum1[iw_r * PARAM.globalv.nlocal + iw_l]); // Peize Lin add conj 2019-04-14 } } - for (int iw_l = 0; iw_l < GlobalV::NLOCAL; ++iw_l) + for (int iw_l = 0; iw_l < PARAM.globalv.nlocal; ++iw_l) { - for( int iw_r=0; iw_r::exx_energy_cal() for( int ik=0; ikkv_ptr->get_nks(); ++ik) { - for( int iw_l=0; iw_lhvec_array)(ik, ib, iw_l)) * (*k_pack->hvec_array)(ik, ib, iw_r)).real() * k_pack->wf_wg(ik, ib); } @@ -533,9 +533,9 @@ void Exx_Lip::exx_energy_cal() for( int ik=0; ikkv_ptr->get_nks(); ++ik) { ofs<<"ik:\t"<::exx_energy_cal() for( int ik=0; ikkv_ptr->get_nks(); ++ik) { ofs<<"ik:\t"<hvec_array)(ik, ib, iw_l)) * (*k_pack->hvec_array)(ik, ib, iw_r) * k_pack->wf_wg(ik, ib); ofs<::write_q_pack() const std::ofstream ofs_wf_wg(ss_wf_wg.str().c_str()); for( int iq = 0; iq < q_pack->kv_ptr->get_nks(); ++iq) { - for( int ib=0; ibwf_wg(iq,ib)<<"\t"; } @@ -611,9 +611,9 @@ void Exx_Lip::write_q_pack() const std::ofstream ofs_hvec(ss_hvec.str().c_str()); for( int iq=0; iqkv_ptr->get_nks(); ++iq) { - for( int iw=0; iwhvec_array)(iq, ib, iw).real() << " " << (*q_pack->hvec_array)(iq, ib, iw).imag() << " "; } @@ -659,7 +659,7 @@ void Exx_Lip::write_q_pack() const // // q_pack->wf_ptr); // } // #endif -// q_pack->wf_wg.create(q_pack->kv_ptr->get_nks(),GlobalV::NBANDS); +// q_pack->wf_wg.create(q_pack->kv_ptr->get_nks(),PARAM.inp.nbands); // if(!GlobalV::RANK_IN_POOL) // { // std::stringstream ss_wf_wg; @@ -667,7 +667,7 @@ void Exx_Lip::write_q_pack() const // std::ifstream ifs_wf_wg(ss_wf_wg.str().c_str()); // for( int iq = 0; iq < q_pack->kv_ptr->get_nks(); ++iq) // { -// for( int ib=0; ib>q_pack->wf_wg(iq,ib); // } @@ -675,13 +675,13 @@ void Exx_Lip::write_q_pack() const // ifs_wf_wg.close(); // } // #ifdef __MPI -// MPI_Bcast( q_pack->wf_wg.c, q_pack->kv_ptr->get_nks()*GlobalV::NBANDS, MPI_DOUBLE, 0, POOL_WORLD); +// MPI_Bcast( q_pack->wf_wg.c, q_pack->kv_ptr->get_nks()*PARAM.inp.nbands, MPI_DOUBLE, 0, POOL_WORLD); // #endif // q_pack->hvec_array = new ModuleBase::ComplexMatrix [q_pack->kv_ptr->get_nks()]; // for( int iq=0; iqkv_ptr->get_nks(); ++iq) // { -// q_pack->hvec_array[iq].create(GlobalV::NLOCAL,GlobalV::NBANDS); +// q_pack->hvec_array[iq].create(PARAM.globalv.nlocal,PARAM.inp.nbands); // } // if(!GlobalV::RANK_IN_POOL) // { @@ -690,9 +690,9 @@ void Exx_Lip::write_q_pack() const // std::ifstream ifs_hvec(ss_hvec.str().c_str()); // for( int iq=0; iqkv_ptr->get_nks(); ++iq) // { -// for( int iw=0; iw>a>>b; @@ -705,7 +705,7 @@ void Exx_Lip::write_q_pack() const // #ifdef __MPI // for( int iq=0; iqkv_ptr->get_nks(); ++iq) // { -// MPI_Bcast( q_pack->hvec_array[iq].c, GlobalV::NLOCAL*GlobalV::NBANDS, MPI_DOUBLE_COMPLEX, 0, POOL_WORLD); +// MPI_Bcast( q_pack->hvec_array[iq].c, PARAM.globalv.nlocal*PARAM.inp.nbands, MPI_DOUBLE_COMPLEX, 0, POOL_WORLD); // } // #endif diff --git a/source/module_ri/module_exx_symmetry/symmetry_rotation.cpp b/source/module_ri/module_exx_symmetry/symmetry_rotation.cpp index ab9c7b9756..cc01099c3a 100644 --- a/source/module_ri/module_exx_symmetry/symmetry_rotation.cpp +++ b/source/module_ri/module_exx_symmetry/symmetry_rotation.cpp @@ -420,7 +420,7 @@ namespace ModuleSymmetry const char notrans = 'N'; std::complex alpha(1.0, 0.0); const std::complex beta(0.0, 0.0); - const int nbasis = GlobalV::NLOCAL; + const int nbasis = PARAM.globalv.nlocal; const int i1 = 1; if (TRS_conj) {