Skip to content

Commit

Permalink
#1328: tests: Initialize MPI only once
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Mar 16, 2021
1 parent c71725a commit b5bd803
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions tests/unit/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,11 @@ std::unique_ptr<MPISingletonMultiTest> mpi_singleton = nullptr;
int test_argc = 0;
char** test_argv = nullptr;

}}} // end namespace vt::tests::unit

bool should_init_MPI(int& argc, char** argv) {
if (argc < 2) {
return false;
void init_MPI_if_needed(int& argc, char** argv) {
if (argc < 2 or (mpi_singleton != nullptr)) {
return;
}


// Extra flag (--MPI_TEST or --NO_MPI_TEST) is added as the last argument
std::string test_arg = argv[argc - 1];
assert(
Expand All @@ -75,19 +72,20 @@ bool should_init_MPI(int& argc, char** argv) {
// 'Remove' the argument so we don't pass it further to vt
--argc;

return test_arg == "--MPI_TEST";
if (test_arg == "--MPI_TEST") {
mpi_singleton = std::make_unique<MPISingletonMultiTest>(argc, argv);
}
}

}}} // end namespace vt::tests::unit

int main(int argc, char **argv) {

/**
* Initalize MPI (if needed) before GTEST so we can check for number of ranks
* during GTEST code generation.
*/
if (should_init_MPI(argc, argv)) {
vt::tests::unit::mpi_singleton =
std::make_unique<vt::tests::unit::MPISingletonMultiTest>(argc, argv);
}
vt::tests::unit::init_MPI_if_needed(argc, argv);

::testing::InitGoogleTest(&argc, argv);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ inline bool isOversubscribed() {
*/
#define SET_NUM_NODES_CONSTRAINT(req_num_nodes) \
{ \
auto const num_nodes = theContext()->getNumNodes(); \
auto const num_nodes = theContext()->getNumNodes(); \
if (num_nodes != req_num_nodes) { \
GTEST_SKIP() << fmt::format( \
"Skipping the run on {} nodes. This test should run only on {} " \
Expand Down

0 comments on commit b5bd803

Please sign in to comment.