Skip to content

Commit 0fe4035

Browse files
committed
Add Finalize function in WARNING QUIT
1 parent 8c397d9 commit 0fe4035

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
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
@@ -62,6 +64,20 @@ void QUIT(int ret)
6264
void WARNING_QUIT(const std::string &file,const std::string &description)
6365
{
6466
WARNING_QUIT(file, description, 1);
67+
68+
#ifdef __MPI /* if it is MPI run, finalize first, then exit */
69+
std::cout << "Detecting if MPI has been initialized..."
70+
int is_initialized;
71+
MPI_Initialized(&is_initialized);
72+
if (is_initialized) {
73+
std::cout << "Terminating ABACUS with multiprocessing environment." << std::endl;
74+
Parallel_Global::finalize_mpi();
75+
}
76+
else{
77+
std::cout << "MPI has not been initialized. Quit normally."
78+
}
79+
/* but seems this is the only correct way to terminate the MPI */
80+
#endif
6581
}
6682

6783
void WARNING_QUIT(const std::string &file,const std::string &description,int ret)

source/module_basis/module_pw/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ AddTest(
55
SOURCES ../../../module_base/matrix.cpp ../../../module_base/complexmatrix.cpp ../../../module_base/matrix3.cpp ../../../module_base/tool_quit.cpp
66
../../../module_base/mymath.cpp ../../../module_base/timer.cpp ../../../module_base/memory.cpp ../../../module_base/blas_connector.cpp
77
../../../module_base/libm/branred.cpp ../../../module_base/libm/sincos.cpp
8-
# ../../../module_psi/kernels/psi_memory_op.cpp
8+
../../../module_base/parallel_global.cpp ../../../module_base/parallel_comm.cpp
99
../../../module_base/module_device/memory_op.cpp
1010
depend_mock.cpp pw_test.cpp test1-1-1.cpp test1-1-2.cpp test1-2.cpp test1-3.cpp test1-4.cpp test1-5.cpp
1111
test2-1-1.cpp test2-1-2.cpp test2-2.cpp test2-3.cpp

source/module_basis/module_pw/test/depend_mock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace GlobalV
88
std::ofstream ofs_running;
99
}
1010
#ifdef __MPI
11-
MPI_Comm POOL_WORLD;
11+
//MPI_Comm POOL_WORLD;
1212
namespace Parallel_Reduce
1313
{
1414
template<typename T> void reduce_all(T& object) { return; };

0 commit comments

Comments
 (0)