Unverified Commit 8728d7cb authored by Scott Cyphers's avatar Scott Cyphers Committed by GitHub

Migrate from #2884 (#2897)

parent 11a9f464
...@@ -33,17 +33,19 @@ namespace ngraph ...@@ -33,17 +33,19 @@ namespace ngraph
MLSLDistributedInterface(const std::string& name = "MLSL") MLSLDistributedInterface(const std::string& name = "MLSL")
: m_name(name) : m_name(name)
{ {
if (!MLSL::Environment::GetEnv().IsInitialized()) if (!MLSL::Environment::GetEnv().IsInitialized() && !m_initialized_mlsl)
{ {
MLSL::Environment::GetEnv().Init(nullptr, nullptr); MLSL::Environment::GetEnv().Init(nullptr, nullptr);
m_initialized_mlsl = true;
} }
} }
~MLSLDistributedInterface() override ~MLSLDistributedInterface() override
{ {
if (MLSL::Environment::GetEnv().IsInitialized()) if (MLSL::Environment::GetEnv().IsInitialized() && m_initialized_mlsl)
{ {
MLSL::Environment::GetEnv().Finalize(); MLSL::Environment::GetEnv().Finalize();
m_initialized_mlsl = false;
} }
} }
...@@ -107,6 +109,7 @@ namespace ngraph ...@@ -107,6 +109,7 @@ namespace ngraph
protected: protected:
std::string m_name{"MLSL"}; std::string m_name{"MLSL"};
bool m_initialized_mlsl = false;
}; };
} }
} }
......
...@@ -37,20 +37,21 @@ namespace ngraph ...@@ -37,20 +37,21 @@ namespace ngraph
{ {
int flag = 0; int flag = 0;
MPI_Initialized(&flag); MPI_Initialized(&flag);
if (!flag) if (!flag && !m_initialized_mpi)
{ {
MPI_Init(NULL, NULL); MPI_Init(NULL, NULL);
m_initialized_mpi = true;
} }
} }
~OpenMPIDistributedInterface() override ~OpenMPIDistributedInterface() override
{ {
int flag = 0; int is_mpi_finalized = 0;
MPI_Initialized(&flag); MPI_Finalized(&is_mpi_finalized);
if (!is_mpi_finalized && m_initialized_mpi)
if (flag)
{ {
MPI_Finalize(); MPI_Finalize();
m_initialized_mpi = false;
} }
} }
...@@ -108,6 +109,7 @@ namespace ngraph ...@@ -108,6 +109,7 @@ namespace ngraph
protected: protected:
std::string m_name; std::string m_name;
bool m_initialized_mpi = false;
}; };
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment