Bug 1087 Call MPI_Finalize to exit MPI environment
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -239,6 +239,8 @@ main (int argc, char *argv[])
|
||||
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
// Exit the MPI execution environment
|
||||
MpiInterface::Disable ();
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user