Skip to content

Commit d5bfeaf

Browse files
committed
rewrite check_warning_quit
1 parent ec6b8ae commit d5bfeaf

File tree

5 files changed

+41
-27
lines changed

5 files changed

+41
-27
lines changed

source/module_base/tool_quit.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "global_file.h"
1212
#include "timer.h"
1313
#include "memory.h"
14+
#include "input.h"
1415
#endif
1516

1617
namespace ModuleBase
@@ -129,24 +130,41 @@ void WARNING_QUIT(const std::string &file,const std::string &description)
129130
}
130131

131132

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)
133+
//Check and print warning information for all cores.
134+
//Maybe in the future warning.log should be replaced by error.log.
135+
void CHECK_WARNING_QUIT(const bool error_in, const std::string &file,const std::string &description)
134136
{
135-
int error = (int)error_in;
136137
#ifdef __NORMAL
137138
// only for UT, do nothing here
138139
#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)
140+
if(error_in)
147141
{
148-
WARNING_QUIT(file, description);
142+
//All cores will print inforamtion
143+
std::cout.clear();
144+
if(!GlobalV::ofs_running.is_open())
145+
{
146+
string logfile = GlobalV::global_out_dir + "running_" + GlobalV::CALCULATION + ".log";
147+
GlobalV::ofs_running.open( logfile.c_str(), std::ios::app );
148+
}
149+
if(!GlobalV::ofs_warning.is_open())
150+
{
151+
string warningfile = GlobalV::global_out_dir + "warning.log";
152+
GlobalV::ofs_warning.open( warningfile.c_str(), std::ios::app );
153+
}
154+
155+
//print error information
156+
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
157+
std::cout << " ERROR! " << description << std::endl;
158+
std::cout << " CHECK IN FILE : " << GlobalV::global_out_dir << "warning.log" << std::endl;
159+
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
160+
GlobalV::ofs_running << " ERROR! CHECK IN FILE : " << GlobalV::global_out_dir << "warning.log" << std::endl;
161+
GlobalV::ofs_warning << std::endl;
162+
GlobalV::ofs_warning << " ERROR! " << file << ", core " << GlobalV::MY_RANK+1 << ": " << description << std::endl;
163+
GlobalV::ofs_warning << std::endl;
164+
exit(0);
149165
}
166+
#endif
167+
return;
150168
}
151169

152170
}

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_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
}

0 commit comments

Comments
 (0)