Skip to content

Commit

Permalink
Refatcor:Use PARAM instead of GlobalV::NBAND,NLocal (deepmodeling#5193)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
A-006 authored Oct 10, 2024
1 parent 72b1d7c commit 66c4e58
Show file tree
Hide file tree
Showing 140 changed files with 867 additions and 922 deletions.
30 changes: 1 addition & 29 deletions source/module_base/global_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,6 @@
#include <vector>
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
//----------------------------------------------------------
Expand All @@ -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
44 changes: 0 additions & 44 deletions source/module_base/global_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions source/module_base/module_device/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions source/module_base/module_device/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 10 additions & 11 deletions source/module_cell/cal_atoms_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<double> 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;
}
};
Expand Down
Loading

0 comments on commit 66c4e58

Please sign in to comment.