Skip to content

Commit 85aa162

Browse files
authored
Merge pull request #1187 from Qianruipku/hotfix
Fix: Scan error when MPI_threads larger than nz
2 parents ec6b8ae + 40ba632 commit 85aa162

File tree

8 files changed

+52
-36
lines changed

8 files changed

+52
-36
lines changed

source/module_base/tool_quit.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,41 @@ void WARNING_QUIT(const std::string &file,const std::string &description)
129129
}
130130

131131

132-
//Input judgement and communicate , if any judgement is true, do WARNING_QUIT
133-
void CHECK_WARNING_QUIT(bool error_in, const std::string &file,const std::string &description)
132+
//Check and print warning information for all cores.
133+
//Maybe in the future warning.log should be replaced by error.log.
134+
void CHECK_WARNING_QUIT(const bool error_in, const std::string &file,const std::string &description)
134135
{
135-
int error = (int)error_in;
136136
#ifdef __NORMAL
137137
// only for UT, do nothing here
138138
#else
139-
#ifdef __MPI
140-
int error_max = error;
141-
MPI_Reduce(&error, &error_max, 1, MPI_INT, MPI_MAX, 0, MPI_COMM_WORLD);
142-
MPI_Bcast(&error_max, 1, MPI_INT, 0, MPI_COMM_WORLD);
143-
error = error_max;
144-
#endif
145-
#endif
146-
if(error)
139+
if(error_in)
147140
{
148-
WARNING_QUIT(file, description);
141+
//All cores will print inforamtion
142+
std::cout.clear();
143+
if(!GlobalV::ofs_running.is_open())
144+
{
145+
std::string logfile = GlobalV::global_out_dir + "running_" + GlobalV::CALCULATION + ".log";
146+
GlobalV::ofs_running.open( logfile.c_str(), std::ios::app );
147+
}
148+
if(!GlobalV::ofs_warning.is_open())
149+
{
150+
std::string warningfile = GlobalV::global_out_dir + "warning.log";
151+
GlobalV::ofs_warning.open( warningfile.c_str(), std::ios::app );
152+
}
153+
154+
//print error information
155+
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
156+
std::cout << " ERROR! " << description << std::endl;
157+
std::cout << " CHECK IN FILE : " << GlobalV::global_out_dir << "warning.log" << std::endl;
158+
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
159+
GlobalV::ofs_running << " ERROR! CHECK IN FILE : " << GlobalV::global_out_dir << "warning.log" << std::endl;
160+
GlobalV::ofs_warning << std::endl;
161+
GlobalV::ofs_warning << " ERROR! " << file << ", core " << GlobalV::MY_RANK+1 << ": " << description << std::endl;
162+
GlobalV::ofs_warning << std::endl;
163+
exit(0);
149164
}
165+
#endif
166+
return;
150167
}
151168

152169
}

source/module_base/tool_quit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void WARNING_QUIT(const std::string &file, const std::string &description);
4949
* @param file The file where warning happens
5050
* @param description The warning information
5151
*/
52-
void CHECK_WARNING_QUIT(bool error, const std::string &file,const std::string &description);
52+
void CHECK_WARNING_QUIT(const bool error, const std::string &file,const std::string &description);
5353

5454
} // namespace ModuleBase
5555

source/module_hamilt/ks_pw/meta_pw.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ void Meta<OperatorPW>::act
6565
}
6666

6767
wfcpw->recip2real(porter, porter, ik);
68-
69-
const double* pvk = &(this->vk[0](current_spin, 0));
70-
for (int ir = 0; ir < this->vk->nc; ir++)
68+
if(this->vk->nc != 0)
7169
{
72-
porter[ir] *= pvk[ir];
70+
const double* pvk = &(this->vk[0](current_spin, 0));
71+
for (int ir = 0; ir < this->vk->nc; ir++)
72+
{
73+
porter[ir] *= pvk[ir];
74+
}
7375
}
7476
wfcpw->real2recip(porter, porter, ik);
7577

source/module_pw/pw_basis.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ void PW_Basis::getstartgr()
9494
///
9595
void PW_Basis::collect_local_pw()
9696
{
97-
delete[] this->gg; this->gg = new double[this->npw];
98-
delete[] this->gdirect; this->gdirect = new ModuleBase::Vector3<double>[this->npw];
99-
delete[] this->gcar; this->gcar = new ModuleBase::Vector3<double>[this->npw];
97+
if(this->npw <= 0) return;
98+
delete[] this->gg; this->gg = new double[this->npw];
99+
delete[] this->gdirect; this->gdirect = new ModuleBase::Vector3<double>[this->npw];
100+
delete[] this->gcar; this->gcar = new ModuleBase::Vector3<double>[this->npw];
100101

101102
ModuleBase::Vector3<double> f;
102103
for(int ig = 0 ; ig < this-> npw ; ++ig)
@@ -128,6 +129,7 @@ void PW_Basis::collect_local_pw()
128129
///
129130
void PW_Basis::collect_uniqgg()
130131
{
132+
if(this->npw <= 0) return;
131133
delete[] this->ig2igg; this->ig2igg = new int [this->npw];
132134
int *sortindex = new int [this->npw];
133135
double *tmpgg = new double [this->npw];

source/module_pw/pw_basis_k.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ void PW_Basis_K::setupIndGk()
6969
//count npwk
7070
this->npwk_max = 0;
7171
delete[] this->npwk; this->npwk = new int [this->nks];
72-
//minimun npw, only for check
73-
int npwk_min = this->npw;
7472
for (int ik = 0; ik < this->nks; ik++)
7573
{
7674
int ng = 0;
@@ -83,22 +81,16 @@ void PW_Basis_K::setupIndGk()
8381
}
8482
}
8583
this->npwk[ik] = ng;
86-
if(ng == 0)
87-
{
88-
std::cout<<"Some proc has no plane waves. You can reduce the number of proc to avoid waste!"<<std::endl;
89-
}
84+
ModuleBase::CHECK_WARNING_QUIT((ng == 0), "pw_basis_k.cpp", "Current core has no plane waves! Please reduce the cores.");
9085
if ( this->npwk_max < ng)
9186
{
9287
this->npwk_max = ng;
9388
}
94-
if ( npwk_min > ng)
95-
{
96-
npwk_min = ng;
97-
}
9889
}
99-
ModuleBase::CHECK_WARNING_QUIT((npwk_min==0), "PW_Basis_K::setupIndGk", "some cores have no plane waves!");
90+
10091

10192
//get igl2isz_k and igl2ig_k
93+
if(this->npwk_max <= 0) return;
10294
delete[] igl2isz_k; this->igl2isz_k = new int [this->nks * this->npwk_max];
10395
delete[] igl2ig_k; this->igl2ig_k = new int [this->nks * this->npwk_max];
10496
for (int ik = 0; ik < this->nks; ik++)
@@ -140,6 +132,7 @@ void PW_Basis_K::setuptransform()
140132

141133
void PW_Basis_K::collect_local_pw()
142134
{
135+
if(this->npwk_max <= 0) return;
143136
delete[] gk2;
144137
delete[] gcar;
145138
this->gk2 = new double[this->npwk_max * this->nks];

source/module_pw/pw_distributeg.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ void PW_Basis::distribute_g()
2525
{
2626
ModuleBase::WARNING_QUIT("divide", "No such division type.");
2727
}
28+
ModuleBase::CHECK_WARNING_QUIT((this->npw == 0), "pw_distributeg.cpp", "Current core has no plane waves! Please reduce the cores.");
2829
ModuleBase::timer::tick(this->classname, "distributeg");
2930
return;
3031
}

tests/integrate/101_PW_15_lowz/INPUT

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ nbands 6
77
symmetry 1
88
pseudo_dir ../tools/PP_ORB/
99
pseudo_type upf201
10+
dft_functional scan
1011

1112
#Parameters (2.Iteration)
1213
ecutwfc 20
1314
scf_thr 1e-9
14-
scf_nmax 1
15+
scf_nmax 2
1516

1617

1718
#Parameters (3.Basis)
1819
basis_type pw
1920

2021
#Parameters (4.Smearing)
2122
smearing_method gauss
22-
smearing_sigma 0.002
23+
smearing_sigma 0.002
2324

2425
#Parameters (5.Mixing)
2526
mixing_type pulay
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
etotref -1.407077993281502
2-
etotperatomref -0.7035389966
3-
totaltimeref 0.15155
1+
etotref -0.03063241935806423
2+
etotperatomref -0.0153162097
3+
totaltimeref

0 commit comments

Comments
 (0)