-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: add MPI_Finalize in QUIT function #5505
Conversation
Those unittests failed in a weird way. I need more time to understand what happened. PS. What I have done in function QUIT is adding lines: #ifdef __MPI
MPI_Finalize();
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Your comments in the codes would be more helpful if they are submitted as new issues.
@jinzx10 helps me find it is the math_libs will link with MPI. The line |
here I paste a minimal work example: #ifdef __MPI
#include <mpi.h>
#endif
#include <iostream>
#include <gtest/gtest.h>
void foo(const int signal)
{
if (signal == 0)
{
std::cout << "Normal exit" << std::endl;
}
else
{
std::cout << "Abnormal exit with signal " << signal << std::endl;
#ifdef __MPI // MPI_Finalize() is called in the case of abnormal exit?
// MPI_Finalize();
#endif
exit(signal);
}
}
TEST(hw, test1)
{
// capture stdout
testing::internal::CaptureStdout();
foo(0);
const std::string out = testing::internal::GetCapturedStdout();
EXPECT_EQ(out, "Normal exit\n");
int irank = 0;
#ifdef __MPI
MPI_Comm_rank(MPI_COMM_WORLD, &irank);
#endif
if (irank == 0)
{
std::cout << "Captured stdout: " << out << std::endl;
}
}
TEST(hw, test2)
{
testing::internal::CaptureStdout();
EXPECT_EXIT(foo(1), ::testing::ExitedWithCode(1), "");
const std::string out = testing::internal::GetCapturedStdout();
EXPECT_EQ(out, "Abnormal exit with signal 1\n");
int irank = 0;
#ifdef __MPI
MPI_Comm_rank(MPI_COMM_WORLD, &irank);
#endif
if (irank == 0)
{
std::cout << "Captured stdout: " << out << std::endl;
}
}
int main(int argc, char **argv)
{
#ifdef __MPI
MPI_Init(&argc, &argv);
#endif
::testing::InitGoogleTest(&argc, argv);
// ::testing::FLAGS_gtest_death_test_style = "threadsafe";
const int result = RUN_ALL_TESTS();
#ifdef __MPI
MPI_Finalize();
#endif
return result;
} with following CMakeLists.txt
|
the unittest of (for instance) the charge_mixing failed because:
|
Reminder
Linked Issue
Fix #5486
Unit Tests and/or Case Tests for my changes
What's changed?
Any changes of core modules? (ignore if not applicable)