Skip to content

Commit 1a279a2

Browse files
authored
Merge pull request #131 from dyzheng/develop
Merge deepmodeling/develop -> abacusmodeling/develop branch
2 parents a1c2172 + 8b81643 commit 1a279a2

File tree

8 files changed

+899
-54
lines changed

8 files changed

+899
-54
lines changed

source/module_base/global_function.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void TEST_LEVEL(const std::string &name)
150150
return;
151151
}
152152

153-
bool SCAN_BEGIN(std::ifstream &ifs, const std::string &TargetName, const bool restart)
153+
bool SCAN_BEGIN(std::ifstream &ifs, const std::string &TargetName, const bool restart, const bool ifwarn)
154154
{
155155
std::string SearchName;
156156
bool find = false;
@@ -169,18 +169,18 @@ bool SCAN_BEGIN(std::ifstream &ifs, const std::string &TargetName, const bool re
169169
break;
170170
}
171171
}
172-
if (!find)
172+
if (!find && ifwarn)
173173
{
174174
GlobalV::ofs_warning << " In SCAN_BEGIN, can't find: " << TargetName << " block." << std::endl;
175175
}
176176
return find;
177177
}
178178

179-
void SCAN_END(std::ifstream &ifs, const std::string &TargetName)
179+
void SCAN_END(std::ifstream &ifs, const std::string &TargetName, const bool ifwarn)
180180
{
181181
std::string SearchName;
182182
ifs >> SearchName;
183-
if (SearchName != TargetName)
183+
if (SearchName != TargetName && ifwarn)
184184
{
185185
GlobalV::ofs_warning << " In SCAN_END, can't find: " << TargetName << " block." << std::endl;
186186
}

source/module_base/global_function.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,13 @@ static void READ_VALUE(std::ifstream &ifs, T &v)
153153
return;
154154
}
155155

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

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

162164
template<class T>
163165
static inline void DCOPY( const T &a, T &b, const int &dim)

source/module_cell/read_pp_upf201.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ int Pseudopot_upf::read_pseudo_upf201(std::ifstream &ifs)
126126
ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_MESH>");
127127
}
128128

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

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

225-
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_DIJ"))
225+
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_DIJ", true, false))
226226
{
227227
ModuleBase::GlobalFunc::READ_VALUE(ifs, word); // type size columns
228228
this->read_pseudo_upf201_dij(ifs);
@@ -287,7 +287,7 @@ int Pseudopot_upf::read_pseudo_upf201(std::ifstream &ifs)
287287
//--------------------------------------
288288
//- PP_RHOATOM -
289289
//--------------------------------------
290-
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_RHOATOM"))
290+
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_RHOATOM", true, false))
291291
{
292292
ModuleBase::GlobalFunc::READ_VALUE(ifs, word); // type size columns
293293
this->read_pseudo_upf201_rhoatom(ifs);
@@ -301,7 +301,7 @@ int Pseudopot_upf::read_pseudo_upf201(std::ifstream &ifs)
301301
//--------------------------------------
302302
//- PP_SPIN_ORB -
303303
//--------------------------------------
304-
ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_SPIN_ORB>");
304+
ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_SPIN_ORB>", true, false);
305305
//added by zhengdy-soc
306306
delete[] this->jchi;
307307
delete[] this->jjj;
@@ -378,13 +378,13 @@ int Pseudopot_upf::read_pseudo_upf201(std::ifstream &ifs)
378378
break;
379379
}
380380
}
381-
ModuleBase::GlobalFunc::SCAN_END(ifs, "</PP_SPIN_ORB>");
381+
ModuleBase::GlobalFunc::SCAN_END(ifs, "</PP_SPIN_ORB>", false);
382382
if (mesh%2 == 0)
383383
{
384384
mesh -= 1;
385385
}
386386

387-
ModuleBase::GlobalFunc::SCAN_END(ifs, "</UPF>");
387+
ModuleBase::GlobalFunc::SCAN_END(ifs, "</UPF>", false);
388388
delete []name;
389389
delete []val;
390390

source/module_hsolver/test/data-H

Lines changed: 832 additions & 26 deletions
Large diffs are not rendered by default.

source/module_hsolver/test/diago_cg_test.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Class Diago_CG is an approach for eigenvalue problems
2222
* This unittest test the function Diago_CG::diag()
2323
* with different examples.
24-
* - the Hermite matrices (npw=50,100,200) produced using random numbers and with sparsity of 0%, 60%, 80%
24+
* - the Hermite matrices (npw=500,1000) produced using random numbers and with sparsity of 0%, 60%, 80%
2525
* - the Hamiltonian matrix read from "data-H", produced by using out_hs in INPUT of a LCAO calculation
2626
* - a 2x2 Hermite matrix for learning and checking
2727
*
@@ -57,8 +57,6 @@ class DiagoCGPrepare
5757
: nband(nband), npw(npw), sparsity(sparsity), reorder(reorder), eps(eps), maxiter(maxiter),
5858
threshold(threshold)
5959
{
60-
hsolver::DiagoIterAssist::PW_DIAG_NMAX = maxiter;
61-
hsolver::DiagoIterAssist::PW_DIAG_THR = eps;
6260
}
6361

6462
int nband, npw, sparsity, maxiter, notconv;
@@ -128,6 +126,10 @@ TEST_P(DiagoCGTest, RandomHamilt)
128126
DiagoCGPrepare dcp = GetParam();
129127
//std::cout << "npw=" << dcp.npw << ", nband=" << dcp.nband << ", sparsity="
130128
// << dcp.sparsity << ", eps=" << dcp.eps << std::endl;
129+
hsolver::DiagoIterAssist::PW_DIAG_NMAX = dcp.maxiter;
130+
hsolver::DiagoIterAssist::PW_DIAG_THR = dcp.eps;
131+
//std::cout<<"maxiter "<<hsolver::DiagoIterAssist::PW_DIAG_NMAX<<std::endl;
132+
//std::cout<<"eps "<<hsolver::DiagoIterAssist::PW_DIAG_THR<<std::endl;
131133
HPsi hpsi(dcp.nband, dcp.npw, dcp.sparsity);
132134
DIAGOTEST::hmatrix = hpsi.hamilt();
133135

@@ -140,10 +142,12 @@ INSTANTIATE_TEST_SUITE_P(VerifyCG,
140142
DiagoCGTest,
141143
::testing::Values(
142144
// nband, npw, sparsity, reorder, eps, maxiter, threshold
143-
DiagoCGPrepare(10, 50, 0, true, 1e-5, 50, 1e-3),
144-
DiagoCGPrepare(20, 50, 6, true, 1e-5, 50, 1e-3),
145-
DiagoCGPrepare(20, 100, 8, true, 1e-5, 50, 1e-3),
146-
DiagoCGPrepare(40, 200, 8, true, 1e-5, 50, 1e-2)));
145+
DiagoCGPrepare(10, 500, 0, true, 1e-5, 100, 1e-3),
146+
DiagoCGPrepare(20, 500, 6, true, 1e-5, 300, 1e-3),
147+
DiagoCGPrepare(20, 1000, 8, true, 1e-5, 300, 1e-3),
148+
DiagoCGPrepare(40, 1000, 8, true, 1e-6, 300, 1e-3)));
149+
// DiagoCGPrepare(40, 2000, 8, true, 1e-5, 500, 1e-2)));
150+
// the last one is passed but time-consumming.
147151

148152
// check that the mock class HPsi work well
149153
// in generating a Hermite matrix
@@ -194,6 +198,8 @@ TEST(DiagoCGTest, TwoByTwo)
194198
hm(1, 1) = std::complex<double>{3.0, 0.0};
195199
// nband, npw, sub, sparsity, reorder, eps, maxiter, threshold
196200
DiagoCGPrepare dcp(nband, dim, 0, true, 1e-4, 50, 1e-10);
201+
hsolver::DiagoIterAssist::PW_DIAG_NMAX = dcp.maxiter;
202+
hsolver::DiagoIterAssist::PW_DIAG_THR = dcp.eps;
197203
HPsi hpsi;
198204
hpsi.create(nband, dim);
199205
DIAGOTEST::hmatrix = hm;
@@ -212,7 +218,9 @@ TEST(DiagoCGTest, readH)
212218
int dim = hm.nr;
213219
int nband = 10; // not nband < dim, here dim = 26 in data-H
214220
// nband, npw, sub, sparsity, reorder, eps, maxiter, threshold
215-
DiagoCGPrepare dcp(nband, dim, 0, true, 1e-4, 50, 1e-3);
221+
DiagoCGPrepare dcp(nband, dim, 0, true, 1e-4, 300, 1e-3);
222+
hsolver::DiagoIterAssist::PW_DIAG_NMAX = dcp.maxiter;
223+
hsolver::DiagoIterAssist::PW_DIAG_THR = dcp.eps;
216224
HPsi hpsi;
217225
hpsi.create(nband, dim);
218226
DIAGOTEST::hmatrix = hpsi.hamilt();

source/module_orbital/ORB_control.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void ORB_control::mpi_creat_cart(MPI_Comm* comm_2D,
325325
#endif
326326

327327
#ifdef __MPI
328-
void ORB_control::mat_2d(MPI_Comm vu,
328+
int ORB_control::mat_2d(MPI_Comm vu,
329329
const int &M_A,
330330
const int &N_A,
331331
const int &nb,
@@ -365,7 +365,14 @@ void ORB_control::mat_2d(MPI_Comm vu,
365365
{
366366
ofs_warning << " cpu 2D distribution : " << dim[0] << "*" << dim[1] << std::endl;
367367
ofs_warning << " but, the number of row blocks is " << block << std::endl;
368-
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no row blocks, try a smaller 'nb2d' parameter.");
368+
if(nb>1)
369+
{
370+
return 1;
371+
}
372+
else
373+
{
374+
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no row blocks, try a smaller 'nb2d' parameter.");
375+
}
369376
}
370377

371378
// (2.1) row_b : how many blocks for this processor. (at least)
@@ -428,7 +435,14 @@ void ORB_control::mat_2d(MPI_Comm vu,
428435
{
429436
ofs_warning << " cpu 2D distribution : " << dim[0] << "*" << dim[1] << std::endl;
430437
ofs_warning << " but, the number of column blocks is " << block << std::endl;
431-
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no column blocks.");
438+
if(nb>1)
439+
{
440+
return 1;
441+
}
442+
else
443+
{
444+
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no column blocks.");
445+
}
432446
}
433447

434448
LM.col_b=block/dim[1];
@@ -485,7 +499,14 @@ void ORB_control::mat_2d(MPI_Comm vu,
485499
{
486500
ofs_warning << " cpu 2D distribution : " << dim[0] << "*" << dim[1] << std::endl;
487501
ofs_warning << " but, the number of bands-row-block is " << block << std::endl;
488-
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no bands-row-blocks.");
502+
if(nb>1)
503+
{
504+
return 1;
505+
}
506+
else
507+
{
508+
ModuleBase::WARNING_QUIT("ORB_control::mat_2d","some processor has no bands-row-blocks.");
509+
}
489510
}
490511
int col_b_bands = block / dim[1];
491512
if (coord[1] < block % dim[1])
@@ -510,7 +531,7 @@ void ORB_control::mat_2d(MPI_Comm vu,
510531
}
511532
pv->nloc_wfc = pv->ncol_bands * LM.row_num;
512533

513-
return;
534+
return 0;
514535
}
515536
#endif
516537

source/module_orbital/ORB_control.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class ORB_control
115115
void mpi_creat_cart(MPI_Comm* comm_2D,
116116
int prow, int pcol, std::ofstream& ofs_running);
117117

118-
void mat_2d(MPI_Comm vu,
118+
int mat_2d(MPI_Comm vu,
119119
const int& M_A, const int& N_A,
120120
const int& NB, LocalMatrix& loc_A,
121121
std::ofstream& ofs_running,

source/module_orbital/parallel_orbitals.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,16 @@ void ORB_control::divide_HS_2d
235235
this->mpi_creat_cart(&pv->comm_2D,pv->dim0,pv->dim1, ofs_running);
236236

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

241249
// mohan add 2010-06-29
242250
pv->nrow = pv->MatrixInfo.row_num;

0 commit comments

Comments
 (0)