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,42 +105,44 @@ 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;
112+ std::cout << " " << std::endl;
117113 std::cout << " CHECK IN FILE : " << g_quit_out_dir << " warning.log" << std::endl;
118114 std::cout << " " << std::endl;
119115 std::cout << " For detailed manual of ABACUS, please see the website" << std::endl;
120116 std::cout << " https://abacus.deepmodeling.com" << std::endl;
121117 std::cout << " For any questions, propose issues on the website" << std::endl;
122118 std::cout << " https://github.com/deepmodeling/abacus-develop/issues" << std::endl;
123119 std::cout << " ---------------------------------------------------------" << std::endl;
124- std::cout << " !NOTICE! " << std::endl;
120+ std::cout << " !ERROR! " << std::endl;
125121 std::cout << " ---------------------------------------------------------" << std::endl;
126122
127123
128124 GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
129- GlobalV::ofs_running << " !NOTICE! " << std::endl;
125+ GlobalV::ofs_running << " !ERROR! " << std::endl;
130126 GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
131127 GlobalV::ofs_running << std::endl;
132128 GlobalV::ofs_running << " " << description << std::endl;
129+ GlobalV::ofs_running << std::endl;
133130 GlobalV::ofs_running << " CHECK IN FILE : " << g_quit_out_dir << " warning.log" << std::endl;
134131 GlobalV::ofs_running << std::endl;
135132 GlobalV::ofs_running << " For detailed manual of ABACUS, please see the website" << std::endl;
136133 GlobalV::ofs_running << " https://abacus.deepmodeling.com" << std::endl;
137134 GlobalV::ofs_running << " For any questions, propose issues on the website" << std::endl;
138135 GlobalV::ofs_running << " https://github.com/deepmodeling/abacus-develop/issues" << std::endl;
139136 GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
140- GlobalV::ofs_running << " NOTICE " << std::endl;
137+ GlobalV::ofs_running << " !ERROR! " << std::endl;
141138 GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
142139
143140 WARNING (file,description);
144141 GlobalV::ofs_running<<" Check in file : " <<g_quit_out_dir<<" warning.log" <<std::endl;
145142
146143#endif
147144
148- QUIT (ret);
145+ quit_impl (ret, false );
149146}
150147
151148// Check and print warning information for all cores.
0 commit comments