Bug 1087 Call MPI_Finalize to exit MPI environment

This commit is contained in:
John Abraham
2011-05-13 16:31:25 -07:00
parent c72b06f934
commit c2aab68b3f
5 changed files with 34 additions and 2 deletions

View File

@@ -601,7 +601,8 @@ main (int argc, char *argv[])
TIMER_NOW (t2);
cout << "Simulator finished." << endl;
Simulator::Destroy ();
// Exit the MPI execution environment
MpiInterface::Disable ();
double d1 = TIMER_DIFF (t1, t0), d2 = TIMER_DIFF (t2, t1);
cout << "-----" << endl << "Runtime Stats:" << endl;
cout << "Simulator init time: " << d1 << endl;

View File

@@ -245,6 +245,8 @@ main (int argc, char *argv[])
Simulator::Stop (Seconds (5));
Simulator::Run ();
Simulator::Destroy ();
// Exit the MPI execution environment
MpiInterface::Disable ();
return 0;
#else
NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in");

View File

@@ -239,6 +239,8 @@ main (int argc, char *argv[])
Simulator::Run ();
Simulator::Destroy ();
// Exit the MPI execution environment
MpiInterface::Disable ();
return 0;
#else

View File

@@ -284,4 +284,26 @@ MpiInterface::TestSendComplete ()
#endif
}
void
MpiInterface::Disable ()
{
#ifdef NS3_MPI
int flag = 0 ;
MPI_Initialized (&flag);
if (flag)
{
MPI_Finalize ();
m_enabled = false;
m_initialized = false;
}
else
{
NS_FATAL_ERROR ("Cannot disable MPI environment without Initializing it first");
}
#else
NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in");
#endif
}
} // namespace ns3

View File

@@ -97,7 +97,12 @@ public:
* Sets up MPI interface
*/
static void Enable (int* pargc, char*** pargv);
/**
* Terminates the MPI environment by calling MPI_Finalize
* This function must be called after Destroy ()
* It also resets m_initialized, m_enabled
*/
static void Disable ();
/**
* \param p packet to send
* \param rxTime received time at destination node