forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_quit.cpp
More file actions
169 lines (143 loc) · 5.71 KB
/
tool_quit.cpp
File metadata and controls
169 lines (143 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include "tool_quit.h"
#ifdef __MPI
#include "mpi.h"
#endif
#ifdef __NORMAL
#else
#include "global_variable.h"
#include "global_file.h"
#include "timer.h"
#include "memory.h"
#endif
namespace ModuleBase
{
//==========================================================
// GLOBAL FUNCTION :
// NAME : WARNING( write information into GlobalV::ofs_warning)
// NAME : QUIT( exit the running program)
// NAME : WARNING_QUIT( write information into
// GlobalV::ofs_warning , and then quit)
//==========================================================
void WARNING(const std::string &file,const std::string &description)
{
#ifdef __NORMAL
#else
if (GlobalV::MY_RANK==0)
{
// std::cout << "\n "<<file<<" Warning : "<<description<<std::endl;
GlobalV::ofs_warning << " " << file <<" warning : "<< description<<std::endl;
}
#endif
return;
}
void QUIT(void)
{
#ifdef __NORMAL
#else
ModuleBase::timer::finish(GlobalV::ofs_running , !GlobalV::MY_RANK);
ModuleBase::Global_File::close_all_log(GlobalV::MY_RANK);
if (GlobalV::MY_RANK==0)
{
ModuleBase::Memory::print_all( GlobalV::ofs_running ) ;
}
std::cout<<" See output information in : "<<GlobalV::global_out_dir<<std::endl;
#endif
exit(0);
}
void WARNING_QUIT(const std::string &file,const std::string &description)
{
#ifdef __NORMAL
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
std::cout << " NOTICE " << std::endl;
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
#else
//std::cout<<" ----------- SOMETHING TO WARN YOU ! -------" << std::endl;
// 41: red background
// 42: green background
// 31: red
// 32: greem
// 33: yellow
// 34: blue
// 35: zi
// 36: qing
// 37: white
if(GlobalV::COLOUR)
{
//printf( "\e[32m%s\e[0m\n", " -------------- SOMETHING TO WARN YOU ! ------------");
//printf( " \e[32m%s\e[0m\n", description.c_str());
//printf( " \e[32m%s\e[0m", "CHECK IN FILE : ");
//printf( "\e[32m%s\e[0m", GlobalV::global_out_dir.c_str());
//printf( "\e[32m%s\e[0m\n", "warning.log");
//printf( "\e[32m%s\e[0m\n", " ---------------------------------------------------");
printf( "[32m%s[0m\n", " -------------- SOMETHING TO WARN YOU ! ------------");
printf( " [32m%s[0m\n", description.c_str());
printf( " [32m%s[0m", "CHECK IN FILE : ");
printf( "[32m%s[0m", GlobalV::global_out_dir.c_str());
printf( "[32m%s[0m\n", "warning.log");
printf( "[32m%s[0m\n", " ---------------------------------------------------");
}
else
{
std::cout << " " << std::endl;
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
std::cout << " NOTICE " << std::endl;
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
std::cout << " " << std::endl;
std::cout << " " << description << std::endl;
std::cout << " CHECK IN FILE : " << GlobalV::global_out_dir << "warning.log" << std::endl;
std::cout << " " << std::endl;
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
std::cout << " NOTICE " << std::endl;
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
GlobalV::ofs_running << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
GlobalV::ofs_running << " NOTICE " << std::endl;
GlobalV::ofs_running << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
GlobalV::ofs_running << std::endl;
GlobalV::ofs_running << " " << description << std::endl;
GlobalV::ofs_running << " CHECK IN FILE : " << GlobalV::global_out_dir << "warning.log" << std::endl;
GlobalV::ofs_running << std::endl;
GlobalV::ofs_running << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
GlobalV::ofs_running << " NOTICE " << std::endl;
GlobalV::ofs_running << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
}
WARNING(file,description);
GlobalV::ofs_running<<" Check in file : "<<GlobalV::global_out_dir<<"warning.log"<<std::endl;
#endif
QUIT();
}
//Check and print warning information for all cores.
//Maybe in the future warning.log should be replaced by error.log.
void CHECK_WARNING_QUIT(const bool error_in, const std::string &file,const std::string &description)
{
#ifdef __NORMAL
// only for UT, do nothing here
#else
if(error_in)
{
//All cores will print inforamtion
std::cout.clear();
if(!GlobalV::ofs_running.is_open())
{
std::string logfile = GlobalV::global_out_dir + "running_" + GlobalV::CALCULATION + ".log";
GlobalV::ofs_running.open( logfile.c_str(), std::ios::app );
}
if(!GlobalV::ofs_warning.is_open())
{
std::string warningfile = GlobalV::global_out_dir + "warning.log";
GlobalV::ofs_warning.open( warningfile.c_str(), std::ios::app );
}
//print error information
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
std::cout << " ERROR! " << description << std::endl;
std::cout << " CHECK IN FILE : " << GlobalV::global_out_dir << "warning.log" << std::endl;
std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
GlobalV::ofs_running << " ERROR! CHECK IN FILE : " << GlobalV::global_out_dir << "warning.log" << std::endl;
GlobalV::ofs_warning << std::endl;
GlobalV::ofs_warning << " ERROR! " << file << ", core " << GlobalV::MY_RANK+1 << ": " << description << std::endl;
GlobalV::ofs_warning << std::endl;
exit(0);
}
#endif
return;
}
}