Skip to content

Commit 60271ff

Browse files
kmichaelkallnes
andauthored
Detect unread MPI messages (#162)
Co-authored-by: Nesterov Alexander <[email protected]>
1 parent 987a6a5 commit 60271ff

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

tasks/mpi/runner.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,35 @@
33
#include <boost/mpi/communicator.hpp>
44
#include <boost/mpi/environment.hpp>
55

6+
class UnreadMessagesDetector : public ::testing::EmptyTestEventListener {
7+
public:
8+
UnreadMessagesDetector(boost::mpi::communicator world) : world_(std::move(world)) {}
9+
10+
void OnTestEnd(const ::testing::TestInfo& test_info) override {
11+
world_.barrier();
12+
if (const auto msg = world_.iprobe(boost::mpi::any_source, boost::mpi::any_tag)) {
13+
fprintf(
14+
stderr,
15+
"[ PROCESS %d ] [ FAILED ] %s.%s: MPI message queue has an unread message from process %d with tag %d\n",
16+
world_.rank(), test_info.test_suite_name(), test_info.name(), msg->source(), msg->tag());
17+
exit(2);
18+
}
19+
world_.barrier();
20+
}
21+
22+
private:
23+
boost::mpi::communicator world_;
24+
};
25+
626
int main(int argc, char** argv) {
727
boost::mpi::environment env(argc, argv);
828
boost::mpi::communicator world;
29+
930
::testing::InitGoogleTest(&argc, argv);
10-
::testing::TestEventListeners& listeners = ::testing::UnitTest::GetInstance()->listeners();
31+
auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
1132
if (world.rank() != 0) {
1233
delete listeners.Release(listeners.default_result_printer());
1334
}
35+
listeners.Append(new UnreadMessagesDetector(world));
1436
return RUN_ALL_TESTS();
1537
}

0 commit comments

Comments
 (0)