@@ -46,26 +46,28 @@ void QUIT()
4646 QUIT (0 );
4747}
4848
49- void QUIT (const int ret )
49+ void QUIT (const int exitcode )
5050{
5151#ifdef __NORMAL /* what is this??? */
5252#else
5353 ModuleBase::timer::finish (GlobalV::ofs_running , !GlobalV::MY_RANK);
5454 ModuleBase::Global_File::close_all_log (GlobalV::MY_RANK);
5555 std::cout<<" See output information in : " <<PARAM.globalv .global_out_dir <<std::endl;
5656#endif
57- #ifdef _OPENMP /* avoid the case that death thread calls fork() */
57+ #ifdef _OPENMP // merge all threads of one process into one thread
5858 if (omp_in_parallel ())
5959 {
6060 omp_set_num_threads (1 );
61- std::cout << " Threads merged in function ModuleBase::QUIT " << std::endl;
61+ std::cout << " Terminating ABACUS with multithreading environment. " << std::endl;
6262 }
63+ assert (!omp_in_parallel ()); /* avoid the case that death thread calls fork() */
6364#endif
6465#ifdef __MPI /* if it is MPI run, finalize first, then exit */
65- Parallel_Global::finalize_mpi ();
66+ std::cout << " Terminating ABACUS with multiprocessing environment." << std::endl;
67+ Parallel_Global::finalize_mpi ();
6668 /* but seems this is the only correct way to terminate the MPI */
6769#endif
68- exit (ret );
70+ exit (exitcode );
6971}
7072
7173void WARNING_QUIT (const std::string &file, const std::string &description)
@@ -74,44 +76,37 @@ void WARNING_QUIT(const std::string &file, const std::string &description)
7476 /* really? we return with 0? it is something like "we exit the program normally" */
7577}
7678
77- void WARNING_QUIT (const std::string &file, const std::string &description, int ret )
79+ void WARNING_QUIT (const std::string &file, const std::string &description, int exitcode )
7880{
81+ const std::string banner = " "
82+ " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n "
83+ " NOTICE \n "
84+ " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n " ;
7985#ifdef __NORMAL /* what is this??? */
80- std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
81- std::cout << " NOTICE " << std::endl;
82- std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
86+ std::cout << banner << std::endl;
8387#else
84- std::cout << " " << std::endl;
85- std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
86- std::cout << " NOTICE " << std::endl;
87- std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
88- std::cout << " " << std::endl;
89- std::cout << " " << description << std::endl;
90- std::cout << " CHECK IN FILE : " << PARAM.globalv .global_out_dir << " warning.log" << std::endl;
91- std::cout << " " << std::endl;
92- std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
93- std::cout << " NOTICE " << std::endl;
94- std::cout << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
95-
96-
97- GlobalV::ofs_running << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
98- GlobalV::ofs_running << " NOTICE " << std::endl;
99- GlobalV::ofs_running << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
100- GlobalV::ofs_running << std::endl;
101- GlobalV::ofs_running << " " << description << std::endl;
102- GlobalV::ofs_running << " CHECK IN FILE : " << PARAM.globalv .global_out_dir << " warning.log" << std::endl;
103- GlobalV::ofs_running << std::endl;
104- GlobalV::ofs_running << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
105- GlobalV::ofs_running << " NOTICE " << std::endl;
106- GlobalV::ofs_running << " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
107-
88+ std::cout << banner.size () << std::endl;
89+ const int max_width = banner.size () / 3 - 1 ; // minus 1 because of the "\n"
90+ // wrap the description
91+ std::string wrapped_desc = " " ;
92+ std::string::size_type pos = 0 ;
93+ while (pos < description.size ())
94+ {
95+ wrapped_desc += " " ;
96+ wrapped_desc += description.substr (pos, max_width - 2 );
97+ // because the leading whitespace and tailing "\n"
98+ wrapped_desc += " \n " ;
99+ pos += max_width - 2 ;
100+ }
101+ const std::string warnmsg = " \n "
102+ " " + wrapped_desc + " \n "
103+ " CHECK IN FILE : " + PARAM.globalv .global_out_dir + " warning.log\n\n " ;
104+ std::cout << " \n " << banner << warnmsg << banner << std::endl;
105+ GlobalV::ofs_running << " \n " << banner << warnmsg << banner << std::endl;
108106 WARNING (file,description);
109107 GlobalV::ofs_running<<" Check in file : " <<PARAM.globalv .global_out_dir <<" warning.log" <<std::endl;
110108#endif
111- #ifdef __MPI
112- std::cout << " Terminating multiprocessing environment..." << std::endl;
113- #endif
114- QUIT (ret);
109+ QUIT (exitcode);
115110}
116111
117112// Check and print warning information for all cores.
0 commit comments