Skip to content

Commit a1707bb

Browse files
committed
Add multithread quit function
1 parent bbf41aa commit a1707bb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

source/module_base/tool_quit.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "tool_quit.h"
22
#ifdef __MPI
33
#include "mpi.h"
4+
#include "module_base/parallel_global.h"
5+
#include "module_base/parallel_comm.h"
46
#endif
57

68
#ifdef __NORMAL
@@ -55,6 +57,20 @@ void QUIT(int ret)
5557
std::cout<<" See output information in : "<<PARAM.globalv.global_out_dir<<std::endl;
5658
#endif
5759

60+
#ifdef _OPENMP // merge all threads of one process into one thread
61+
if (omp_in_parallel())
62+
{
63+
omp_set_num_threads(1);
64+
std::cout << "Terminating ABACUS with multithreading environment." << std::endl;
65+
}
66+
assert(!omp_in_parallel()); /* avoid the case that death thread calls fork() */
67+
#endif
68+
69+
#ifdef __MPI /* if it is MPI run, finalize first, then exit */
70+
std::cout << "Terminating ABACUS with multiprocessing environment." << std::endl;
71+
Parallel_Global::finalize_mpi();
72+
/* but seems this is the only correct way to terminate the MPI */
73+
#endif
5874
exit(ret);
5975
}
6076

0 commit comments

Comments
 (0)