11#include " tool_quit.h"
2+ #include < cstdlib>
23#ifdef __MPI
34#include " mpi.h"
45#endif
@@ -18,6 +19,22 @@ namespace
1819{
1920std::string g_quit_out_dir;
2021std::string g_quit_calculation;
22+
23+ [[noreturn]] void quit_impl (const int ret, const bool print_timer)
24+ {
25+ #ifdef __NORMAL
26+ (void )print_timer;
27+ #else
28+ if (print_timer)
29+ {
30+ ModuleBase::timer::finish (GlobalV::ofs_running, GlobalV::MY_RANK == 0 , false );
31+ std::cout << " See output information in : " << g_quit_out_dir << std::endl;
32+ }
33+ ModuleBase::Global_File::close_all_log (GlobalV::MY_RANK );
34+ #endif
35+
36+ std::exit (ret);
37+ }
2138}
2239
2340void set_quit_out_dir (const std::string& dir)
@@ -64,43 +81,21 @@ void QUIT()
6481
6582void QUIT (int ret)
6683{
67-
68- #ifdef __NORMAL
69- #else
70- ModuleBase::timer::finish (GlobalV::ofs_running , !GlobalV::MY_RANK , false );
71- ModuleBase::Global_File::close_all_log (GlobalV::MY_RANK );
72- std::cout<<" See output information in : " <<g_quit_out_dir<<std::endl;
73- #endif
74-
75- exit (ret);
84+ quit_impl (ret, true );
7685}
7786
7887
7988void WARNING_QUIT (const std::string &file,const std::string &description)
8089{
81- WARNING_QUIT (file, description, 1 );
82-
83- #ifdef __MPI /* if it is MPI run, finalize first, then exit */
84- std::cout << " Detecting if MPI has been initialized..." << std::endl;
85- int is_initialized = 0 ;
86- MPI_Initialized (&is_initialized);
87- if (is_initialized) {
88- std::cout << " Terminating ABACUS with multiprocessing environment." << std::endl;
89- MPI_Finalize ();
90- }
91- else {
92- std::cout << " MPI has not been initialized. Quit normally." << std::endl;
93- }
94- /* but seems this is the only correct way to terminate the MPI */
95- #endif
90+ WARNING_QUIT (file, description, 1 );
9691}
9792
9893void WARNING_QUIT (const std::string &file,const std::string &description,int ret)
9994{
10095#ifdef __NORMAL
10196
10297 std::cout << " ---------------------------------------------------------" << std::endl;
103- std::cout << " !NOTICE! " << std::endl;
98+ std::cout << " !ERROR! " << std::endl;
10499 std::cout << " ---------------------------------------------------------" << std::endl;
105100 std::cout << " For detailed manual of ABACUS, please see the website" << std::endl;
106101 std::cout << " https://abacus.deepmodeling.com" << std::endl;
@@ -110,7 +105,7 @@ void WARNING_QUIT(const std::string &file,const std::string &description,int ret
110105#else
111106 std::cout << " " << std::endl;
112107 std::cout << " ---------------------------------------------------------" << std::endl;
113- std::cout << " !NOTICE! " << std::endl;
108+ std::cout << " !ERROR! " << std::endl;
114109 std::cout << " ---------------------------------------------------------" << std::endl;
115110 std::cout << " " << std::endl;
116111 std::cout << " " << description << std::endl;
@@ -121,12 +116,12 @@ void WARNING_QUIT(const std::string &file,const std::string &description,int ret
121116 std::cout << " For any questions, propose issues on the website" << std::endl;
122117 std::cout << " https://github.com/deepmodeling/abacus-develop/issues" << std::endl;
123118 std::cout << " ---------------------------------------------------------" << std::endl;
124- std::cout << " !NOTICE! " << std::endl;
119+ std::cout << " !ERROR! " << std::endl;
125120 std::cout << " ---------------------------------------------------------" << std::endl;
126121
127122
128123 GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
129- GlobalV::ofs_running << " !NOTICE! " << std::endl;
124+ GlobalV::ofs_running << " !ERROR! " << std::endl;
130125 GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
131126 GlobalV::ofs_running << std::endl;
132127 GlobalV::ofs_running << " " << description << std::endl;
@@ -137,15 +132,15 @@ void WARNING_QUIT(const std::string &file,const std::string &description,int ret
137132 GlobalV::ofs_running << " For any questions, propose issues on the website" << std::endl;
138133 GlobalV::ofs_running << " https://github.com/deepmodeling/abacus-develop/issues" << std::endl;
139134 GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
140- GlobalV::ofs_running << " NOTICE " << std::endl;
135+ GlobalV::ofs_running << " !ERROR! " << std::endl;
141136 GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
142137
143138 WARNING (file,description);
144139 GlobalV::ofs_running<<" Check in file : " <<g_quit_out_dir<<" warning.log" <<std::endl;
145140
146141#endif
147142
148- QUIT (ret);
143+ quit_impl (ret, false );
149144}
150145
151146// Check and print warning information for all cores.
0 commit comments