Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions source/module_base/global_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void TEST_LEVEL(const std::string &name)
return;
}

bool SCAN_BEGIN(std::ifstream &ifs, const std::string &TargetName, const bool restart)
bool SCAN_BEGIN(std::ifstream &ifs, const std::string &TargetName, const bool restart, const bool ifwarn)
{
std::string SearchName;
bool find = false;
Expand All @@ -169,18 +169,18 @@ bool SCAN_BEGIN(std::ifstream &ifs, const std::string &TargetName, const bool re
break;
}
}
if (!find)
if (!find && ifwarn)
{
GlobalV::ofs_warning << " In SCAN_BEGIN, can't find: " << TargetName << " block." << std::endl;
}
return find;
}

void SCAN_END(std::ifstream &ifs, const std::string &TargetName)
void SCAN_END(std::ifstream &ifs, const std::string &TargetName, const bool ifwarn)
{
std::string SearchName;
ifs >> SearchName;
if (SearchName != TargetName)
if (SearchName != TargetName && ifwarn)
{
GlobalV::ofs_warning << " In SCAN_END, can't find: " << TargetName << " block." << std::endl;
}
Expand Down
6 changes: 4 additions & 2 deletions source/module_base/global_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ static void READ_VALUE(std::ifstream &ifs, T &v)
return;
}

bool SCAN_BEGIN(std::ifstream &ifs, const std::string &TargetName, const bool restart=1);
bool SCAN_BEGIN(std::ifstream &ifs, const std::string &TargetName, const bool restart=1, const bool ifwarn=true);
// ifwarn: whether to call GlobalV::ofs_warning when the TargetName is not found, used to avoid invalid warning.
// Mohan warning : the last term can't be written as const bool &restart,
// I don't know why.

void SCAN_END(std::ifstream &ifs, const std::string &TargetName);
void SCAN_END(std::ifstream &ifs, const std::string &TargetName, const bool ifwarn=true);
// ifwarn: whether to call GlobalV::ofs_warning when the TargetName is not found, used to avoid invalid warning.

template<class T>
static inline void DCOPY( const T &a, T &b, const int &dim)
Expand Down
14 changes: 7 additions & 7 deletions source/module_cell/read_pp_upf201.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ int Pseudopot_upf::read_pseudo_upf201(std::ifstream &ifs)
ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_MESH>");
}

if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_R"))
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_R", true, false))
{
ModuleBase::GlobalFunc::READ_VALUE(ifs, word); // type size columns
this->read_pseudo_upf201_r(ifs);
Expand All @@ -137,7 +137,7 @@ int Pseudopot_upf::read_pseudo_upf201(std::ifstream &ifs)
}
ModuleBase::GlobalFunc::SCAN_END(ifs, "</PP_R>");

if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_RAB"))
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_RAB", true, false))
{
ModuleBase::GlobalFunc::READ_VALUE(ifs, word); // type size columns
this->read_pseudo_upf201_rab(ifs);
Expand Down Expand Up @@ -222,7 +222,7 @@ int Pseudopot_upf::read_pseudo_upf201(std::ifstream &ifs)
ifs >> word; //number of beta
}

if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_DIJ"))
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_DIJ", true, false))
{
ModuleBase::GlobalFunc::READ_VALUE(ifs, word); // type size columns
this->read_pseudo_upf201_dij(ifs);
Expand Down Expand Up @@ -287,7 +287,7 @@ int Pseudopot_upf::read_pseudo_upf201(std::ifstream &ifs)
//--------------------------------------
//- PP_RHOATOM -
//--------------------------------------
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_RHOATOM"))
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_RHOATOM", true, false))
{
ModuleBase::GlobalFunc::READ_VALUE(ifs, word); // type size columns
this->read_pseudo_upf201_rhoatom(ifs);
Expand All @@ -301,7 +301,7 @@ int Pseudopot_upf::read_pseudo_upf201(std::ifstream &ifs)
//--------------------------------------
//- PP_SPIN_ORB -
//--------------------------------------
ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_SPIN_ORB>");
ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_SPIN_ORB>", true, false);
//added by zhengdy-soc
delete[] this->jchi;
delete[] this->jjj;
Expand Down Expand Up @@ -378,13 +378,13 @@ int Pseudopot_upf::read_pseudo_upf201(std::ifstream &ifs)
break;
}
}
ModuleBase::GlobalFunc::SCAN_END(ifs, "</PP_SPIN_ORB>");
ModuleBase::GlobalFunc::SCAN_END(ifs, "</PP_SPIN_ORB>", false);
if (mesh%2 == 0)
{
mesh -= 1;
}

ModuleBase::GlobalFunc::SCAN_END(ifs, "</UPF>");
ModuleBase::GlobalFunc::SCAN_END(ifs, "</UPF>", false);
delete []name;
delete []val;

Expand Down
858 changes: 832 additions & 26 deletions source/module_hsolver/test/data-H

Large diffs are not rendered by default.

24 changes: 16 additions & 8 deletions source/module_hsolver/test/diago_cg_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Class Diago_CG is an approach for eigenvalue problems
* This unittest test the function Diago_CG::diag()
* with different examples.
* - the Hermite matrices (npw=50,100,200) produced using random numbers and with sparsity of 0%, 60%, 80%
* - the Hermite matrices (npw=500,1000) produced using random numbers and with sparsity of 0%, 60%, 80%
* - the Hamiltonian matrix read from "data-H", produced by using out_hs in INPUT of a LCAO calculation
* - a 2x2 Hermite matrix for learning and checking
*
Expand Down Expand Up @@ -57,8 +57,6 @@ class DiagoCGPrepare
: nband(nband), npw(npw), sparsity(sparsity), reorder(reorder), eps(eps), maxiter(maxiter),
threshold(threshold)
{
hsolver::DiagoIterAssist::PW_DIAG_NMAX = maxiter;
hsolver::DiagoIterAssist::PW_DIAG_THR = eps;
}

int nband, npw, sparsity, maxiter, notconv;
Expand Down Expand Up @@ -128,6 +126,10 @@ TEST_P(DiagoCGTest, RandomHamilt)
DiagoCGPrepare dcp = GetParam();
//std::cout << "npw=" << dcp.npw << ", nband=" << dcp.nband << ", sparsity="
// << dcp.sparsity << ", eps=" << dcp.eps << std::endl;
hsolver::DiagoIterAssist::PW_DIAG_NMAX = dcp.maxiter;
hsolver::DiagoIterAssist::PW_DIAG_THR = dcp.eps;
//std::cout<<"maxiter "<<hsolver::DiagoIterAssist::PW_DIAG_NMAX<<std::endl;
//std::cout<<"eps "<<hsolver::DiagoIterAssist::PW_DIAG_THR<<std::endl;
HPsi hpsi(dcp.nband, dcp.npw, dcp.sparsity);
DIAGOTEST::hmatrix = hpsi.hamilt();

Expand All @@ -140,10 +142,12 @@ INSTANTIATE_TEST_SUITE_P(VerifyCG,
DiagoCGTest,
::testing::Values(
// nband, npw, sparsity, reorder, eps, maxiter, threshold
DiagoCGPrepare(10, 50, 0, true, 1e-5, 50, 1e-3),
DiagoCGPrepare(20, 50, 6, true, 1e-5, 50, 1e-3),
DiagoCGPrepare(20, 100, 8, true, 1e-5, 50, 1e-3),
DiagoCGPrepare(40, 200, 8, true, 1e-5, 50, 1e-2)));
DiagoCGPrepare(10, 500, 0, true, 1e-5, 100, 1e-3),
DiagoCGPrepare(20, 500, 6, true, 1e-5, 300, 1e-3),
DiagoCGPrepare(20, 1000, 8, true, 1e-5, 300, 1e-3),
DiagoCGPrepare(40, 1000, 8, true, 1e-6, 300, 1e-3)));
// DiagoCGPrepare(40, 2000, 8, true, 1e-5, 500, 1e-2)));
// the last one is passed but time-consumming.

// check that the mock class HPsi work well
// in generating a Hermite matrix
Expand Down Expand Up @@ -194,6 +198,8 @@ TEST(DiagoCGTest, TwoByTwo)
hm(1, 1) = std::complex<double>{3.0, 0.0};
// nband, npw, sub, sparsity, reorder, eps, maxiter, threshold
DiagoCGPrepare dcp(nband, dim, 0, true, 1e-4, 50, 1e-10);
hsolver::DiagoIterAssist::PW_DIAG_NMAX = dcp.maxiter;
hsolver::DiagoIterAssist::PW_DIAG_THR = dcp.eps;
HPsi hpsi;
hpsi.create(nband, dim);
DIAGOTEST::hmatrix = hm;
Expand All @@ -212,7 +218,9 @@ TEST(DiagoCGTest, readH)
int dim = hm.nr;
int nband = 10; // not nband < dim, here dim = 26 in data-H
// nband, npw, sub, sparsity, reorder, eps, maxiter, threshold
DiagoCGPrepare dcp(nband, dim, 0, true, 1e-4, 50, 1e-3);
DiagoCGPrepare dcp(nband, dim, 0, true, 1e-4, 300, 1e-3);
hsolver::DiagoIterAssist::PW_DIAG_NMAX = dcp.maxiter;
hsolver::DiagoIterAssist::PW_DIAG_THR = dcp.eps;
HPsi hpsi;
hpsi.create(nband, dim);
DIAGOTEST::hmatrix = hpsi.hamilt();
Expand Down
31 changes: 26 additions & 5 deletions source/module_orbital/ORB_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void ORB_control::mpi_creat_cart(MPI_Comm* comm_2D,
#endif

#ifdef __MPI
void ORB_control::mat_2d(MPI_Comm vu,
int ORB_control::mat_2d(MPI_Comm vu,
const int &M_A,
const int &N_A,
const int &nb,
Expand Down Expand Up @@ -365,7 +365,14 @@ void ORB_control::mat_2d(MPI_Comm vu,
{
ofs_warning << " cpu 2D distribution : " << dim[0] << "*" << dim[1] << std::endl;
ofs_warning << " but, the number of row blocks is " << block << std::endl;
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no row blocks, try a smaller 'nb2d' parameter.");
if(nb>1)
{
return 1;
}
else
{
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no row blocks, try a smaller 'nb2d' parameter.");
}
}

// (2.1) row_b : how many blocks for this processor. (at least)
Expand Down Expand Up @@ -428,7 +435,14 @@ void ORB_control::mat_2d(MPI_Comm vu,
{
ofs_warning << " cpu 2D distribution : " << dim[0] << "*" << dim[1] << std::endl;
ofs_warning << " but, the number of column blocks is " << block << std::endl;
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no column blocks.");
if(nb>1)
{
return 1;
}
else
{
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no column blocks.");
}
}

LM.col_b=block/dim[1];
Expand Down Expand Up @@ -485,7 +499,14 @@ void ORB_control::mat_2d(MPI_Comm vu,
{
ofs_warning << " cpu 2D distribution : " << dim[0] << "*" << dim[1] << std::endl;
ofs_warning << " but, the number of bands-row-block is " << block << std::endl;
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no bands-row-blocks.");
if(nb>1)
{
return 1;
}
else
{
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no bands-row-blocks.");
}
}
int col_b_bands = block / dim[1];
if (coord[1] < block % dim[1])
Expand All @@ -510,7 +531,7 @@ void ORB_control::mat_2d(MPI_Comm vu,
}
pv->nloc_wfc = pv->ncol_bands * LM.row_num;

return;
return 0;
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion source/module_orbital/ORB_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class ORB_control
void mpi_creat_cart(MPI_Comm* comm_2D,
int prow, int pcol, std::ofstream& ofs_running);

void mat_2d(MPI_Comm vu,
int mat_2d(MPI_Comm vu,
const int& M_A, const int& N_A,
const int& NB, LocalMatrix& loc_A,
std::ofstream& ofs_running,
Expand Down
10 changes: 9 additions & 1 deletion source/module_orbital/parallel_orbitals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,16 @@ void ORB_control::divide_HS_2d
this->mpi_creat_cart(&pv->comm_2D,pv->dim0,pv->dim1, ofs_running);

// call mat_2d
this->mat_2d(pv->comm_2D, nlocal, nbands, pv->nb,
int try_nb = this->mat_2d(pv->comm_2D, nlocal, nbands, pv->nb,
pv->MatrixInfo, ofs_running, ofs_warning);
if(try_nb==1)
{
ofs_running<<" parameter nb2d is too large: nb2d = "<<pv->nb<<std::endl;
ofs_running<<" reset nb2d to value 1, this set would make the program keep working but maybe get slower during diagonalization."<<std::endl;
pv->nb = 1;
try_nb = this->mat_2d(pv->comm_2D, nlocal, nbands, pv->nb,
pv->MatrixInfo, ofs_running, ofs_warning);
}

// mohan add 2010-06-29
pv->nrow = pv->MatrixInfo.row_num;
Expand Down