2010-03-08 21:07:31 -05:00
|
|
|
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
|
|
|
/*
|
2013-12-06 14:57:33 -05:00
|
|
|
* Copyright 2013. Lawrence Livermore National Security, LLC.
|
|
|
|
|
*
|
2010-03-08 21:07:31 -05:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
|
* published by the Free Software Foundation;
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
2013-12-06 14:57:33 -05:00
|
|
|
* Author: Steven Smith <smith84@llnl.gov>
|
2020-08-28 14:13:11 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \file
|
|
|
|
|
* \ingroup mpi
|
|
|
|
|
* Implementation of class ns3::MpiInterface.
|
2010-03-08 21:07:31 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "mpi-interface.h"
|
|
|
|
|
|
2013-12-06 14:57:33 -05:00
|
|
|
#include <ns3/global-value.h>
|
|
|
|
|
#include <ns3/string.h>
|
|
|
|
|
#include <ns3/log.h>
|
2010-03-08 21:07:31 -05:00
|
|
|
|
2013-12-06 14:57:33 -05:00
|
|
|
#include "null-message-mpi-interface.h"
|
|
|
|
|
#include "granted-time-window-mpi-interface.h"
|
2010-03-08 21:07:31 -05:00
|
|
|
|
2013-12-06 14:57:33 -05:00
|
|
|
namespace ns3 {
|
2010-03-08 21:07:31 -05:00
|
|
|
|
2014-09-26 15:51:00 -07:00
|
|
|
NS_LOG_COMPONENT_DEFINE ("MpiInterface");
|
|
|
|
|
|
2013-12-06 14:57:33 -05:00
|
|
|
ParallelCommunicationInterface* MpiInterface::g_parallelCommunicationInterface = 0;
|
2010-03-08 21:07:31 -05:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MpiInterface::Destroy ()
|
|
|
|
|
{
|
2013-12-06 14:57:33 -05:00
|
|
|
NS_ASSERT (g_parallelCommunicationInterface);
|
|
|
|
|
g_parallelCommunicationInterface->Destroy ();
|
2010-03-08 21:07:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
|
MpiInterface::GetSystemId ()
|
|
|
|
|
{
|
2013-12-06 14:57:33 -05:00
|
|
|
if ( g_parallelCommunicationInterface )
|
|
|
|
|
return g_parallelCommunicationInterface->GetSystemId ();
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
2010-03-08 21:07:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
|
MpiInterface::GetSize ()
|
|
|
|
|
{
|
2013-12-06 14:57:33 -05:00
|
|
|
if ( g_parallelCommunicationInterface )
|
|
|
|
|
return g_parallelCommunicationInterface->GetSize ();
|
|
|
|
|
else
|
|
|
|
|
return 1;
|
2010-03-08 21:07:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
MpiInterface::IsEnabled ()
|
|
|
|
|
{
|
2013-12-06 14:57:33 -05:00
|
|
|
if (g_parallelCommunicationInterface)
|
2010-03-08 21:07:31 -05:00
|
|
|
{
|
2013-12-06 14:57:33 -05:00
|
|
|
return g_parallelCommunicationInterface->IsEnabled ();
|
2010-03-08 21:07:31 -05:00
|
|
|
}
|
2013-12-06 14:57:33 -05:00
|
|
|
else
|
2010-03-08 21:07:31 -05:00
|
|
|
{
|
2013-12-06 14:57:33 -05:00
|
|
|
return false;
|
2010-03-08 21:07:31 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2020-08-28 14:13:11 -07:00
|
|
|
MpiInterface::SetParallelSimulatorImpl (void)
|
2010-03-08 21:07:31 -05:00
|
|
|
{
|
2013-12-06 14:57:33 -05:00
|
|
|
StringValue simulationTypeValue;
|
|
|
|
|
bool useDefault = true;
|
2010-03-08 21:07:31 -05:00
|
|
|
|
2013-12-06 14:57:33 -05:00
|
|
|
if (GlobalValue::GetValueByNameFailSafe ("SimulatorImplementationType", simulationTypeValue))
|
2010-03-08 21:07:31 -05:00
|
|
|
{
|
2013-12-06 14:57:33 -05:00
|
|
|
std::string simulationType = simulationTypeValue.Get ();
|
2010-03-08 21:07:31 -05:00
|
|
|
|
2013-12-06 14:57:33 -05:00
|
|
|
// Set communication interface based on the simulation type being used.
|
|
|
|
|
// Defaults to synchronous.
|
|
|
|
|
if (simulationType.compare ("ns3::NullMessageSimulatorImpl") == 0)
|
2010-03-08 21:07:31 -05:00
|
|
|
{
|
2013-12-06 14:57:33 -05:00
|
|
|
g_parallelCommunicationInterface = new NullMessageMpiInterface ();
|
|
|
|
|
useDefault = false;
|
2010-03-08 21:07:31 -05:00
|
|
|
}
|
2022-10-25 17:10:23 +08:00
|
|
|
else if (simulationType.compare ("ns3::DistributedSimulatorImpl") == 0 || simulationType.compare("ns3::HybridSimulatorImpl") == 0)
|
2010-03-08 21:07:31 -05:00
|
|
|
{
|
2013-12-06 14:57:33 -05:00
|
|
|
g_parallelCommunicationInterface = new GrantedTimeWindowMpiInterface ();
|
|
|
|
|
useDefault = false;
|
2010-03-08 21:07:31 -05:00
|
|
|
}
|
2013-12-06 14:57:33 -05:00
|
|
|
}
|
2010-03-08 21:07:31 -05:00
|
|
|
|
2013-12-06 14:57:33 -05:00
|
|
|
// User did not specify a valid parallel simulator; use the default.
|
|
|
|
|
if (useDefault)
|
|
|
|
|
{
|
|
|
|
|
g_parallelCommunicationInterface = new GrantedTimeWindowMpiInterface ();
|
|
|
|
|
GlobalValue::Bind ("SimulatorImplementationType",
|
|
|
|
|
StringValue ("ns3::DistributedSimulatorImpl"));
|
|
|
|
|
NS_LOG_WARN ("SimulatorImplementationType was set to non-parallel simulator; setting type to ns3::DistributedSimulatorImp");
|
2010-03-08 21:07:31 -05:00
|
|
|
}
|
2020-08-28 14:13:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MpiInterface::Enable (int* pargc, char*** pargv)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
SetParallelSimulatorImpl ();
|
2013-12-06 14:57:33 -05:00
|
|
|
|
|
|
|
|
g_parallelCommunicationInterface->Enable (pargc, pargv);
|
2010-03-08 21:07:31 -05:00
|
|
|
}
|
|
|
|
|
|
2020-08-28 14:13:11 -07:00
|
|
|
void
|
|
|
|
|
MpiInterface::Enable (MPI_Comm communicator)
|
|
|
|
|
{
|
|
|
|
|
SetParallelSimulatorImpl ();
|
|
|
|
|
g_parallelCommunicationInterface->Enable (communicator);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-08 21:07:31 -05:00
|
|
|
void
|
2013-12-06 14:57:33 -05:00
|
|
|
MpiInterface::SendPacket (Ptr<Packet> p, const Time& rxTime, uint32_t node, uint32_t dev)
|
2010-03-08 21:07:31 -05:00
|
|
|
{
|
2013-12-06 14:57:33 -05:00
|
|
|
NS_ASSERT (g_parallelCommunicationInterface);
|
|
|
|
|
g_parallelCommunicationInterface->SendPacket (p, rxTime, node, dev);
|
2010-03-08 21:07:31 -05:00
|
|
|
}
|
|
|
|
|
|
2020-08-28 14:13:11 -07:00
|
|
|
MPI_Comm
|
|
|
|
|
MpiInterface::GetCommunicator()
|
|
|
|
|
{
|
|
|
|
|
NS_ASSERT (g_parallelCommunicationInterface);
|
|
|
|
|
return g_parallelCommunicationInterface->GetCommunicator ();
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 14:57:33 -05:00
|
|
|
|
|
|
|
|
void
|
2011-05-13 16:31:25 -07:00
|
|
|
MpiInterface::Disable ()
|
|
|
|
|
{
|
2013-12-06 14:57:33 -05:00
|
|
|
NS_ASSERT (g_parallelCommunicationInterface);
|
|
|
|
|
g_parallelCommunicationInterface->Disable ();
|
|
|
|
|
delete g_parallelCommunicationInterface;
|
|
|
|
|
g_parallelCommunicationInterface = 0;
|
2011-05-13 16:31:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-03-08 21:07:31 -05:00
|
|
|
} // namespace ns3
|