Skip to content

Commit 8fc7c42

Browse files
authored
Fix: add MPI_Finalize in QUIT function (#6160)
* Add Finalize function in WARNING QUIT * Fix compilation error * Nooo I haven't been writing codes for a long timeeeeee * Remove dependency test * Confirm removal * Remove useless Dependency
1 parent 415b12e commit 8fc7c42

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

source/module_base/tool_quit.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ void QUIT(int ret)
6262
void WARNING_QUIT(const std::string &file,const std::string &description)
6363
{
6464
WARNING_QUIT(file, description, 1);
65+
66+
#ifdef __MPI /* if it is MPI run, finalize first, then exit */
67+
std::cout << "Detecting if MPI has been initialized..." << std::endl;
68+
int is_initialized;
69+
MPI_Initialized(&is_initialized);
70+
if (is_initialized) {
71+
std::cout << "Terminating ABACUS with multiprocessing environment." << std::endl;
72+
MPI_Finalize();
73+
}
74+
else{
75+
std::cout << "MPI has not been initialized. Quit normally." << std::endl;
76+
}
77+
/* but seems this is the only correct way to terminate the MPI */
78+
#endif
6579
}
6680

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

0 commit comments

Comments
 (0)