diff -r 4c90fdff71a0 model/cooja-loader-factory.cc --- a/model/cooja-loader-factory.cc Mon Jul 16 13:56:16 2012 +0200 +++ b/model/cooja-loader-factory.cc Tue Jul 31 15:30:02 2012 +0200 @@ -3,6 +3,9 @@ #include "elf-cache.h" #include "elf-dependencies.h" #include "ns3/log.h" +#ifdef DCE_MPI +#include "ns3/mpi-interface.h" +#endif #include #include #include @@ -74,7 +77,11 @@ }; SharedModules::SharedModules () - : cache ("elf-cache", 0) +#ifdef DCE_MPI +: cache ("elf-cache", MpiInterface::GetSystemId ()) +#else +: cache ("elf-cache", 0) +#endif {} SharedModules::~SharedModules () diff -r 4c90fdff71a0 model/copy-loader-factory.cc --- a/model/copy-loader-factory.cc Mon Jul 16 13:56:16 2012 +0200 +++ b/model/copy-loader-factory.cc Tue Jul 31 15:30:02 2012 +0200 @@ -2,6 +2,7 @@ #include "elf-cache.h" #include "elf-dependencies.h" #include "ns3/log.h" +#include "ns3/mpi-interface.h" NS_LOG_COMPONENT_DEFINE ("CopyLoaderFactory"); @@ -175,7 +176,12 @@ uint32_t CopyLoaderFactory::AllocateUid (void) { +#ifdef DCE_MPI + // 2^16 processes maximum per different system id. + static uint32_t uid = MpiInterface::GetSystemId () * ( 1 << 16 ); +#else static uint32_t uid = 0; +#endif uid++; return uid; } diff -r 4c90fdff71a0 myscripts/dce-mpi-udp/dce-mpi-udp.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myscripts/dce-mpi-udp/dce-mpi-udp.cc Tue Jul 31 15:30:02 2012 +0200 @@ -0,0 +1,114 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + */ + +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/internet-module.h" +#include "ns3/point-to-point-module.h" +#include "ns3/applications-module.h" +#include "ns3/dce-module.h" +#include "ns3/mpi-interface.h" + +using namespace ns3; + +// Run Hint : $ mpirun -np 2 dce-mpi-udp + +int +main (int argc, char *argv[]) +{ + // Distributed simulation setup + MpiInterface::Enable (&argc, &argv); + GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::DistributedSimulatorImpl")); + + uint32_t systemId = MpiInterface::GetSystemId (); + uint32_t systemCount = MpiInterface::GetSize (); + + + // Check for valid distributed parameters. + // Must have 2 and only 2 Logical Processors (LPs) + + if (systemCount != 2) + { + std::cout << "This simulation requires 2 and only 2 logical processors." << std::endl; + return 1; + } + + //------------------------------------------------- + + + CommandLine cmd; + cmd.Parse (argc, argv); + + NodeContainer nodes; + Ptr node1 = CreateObject (0); // <------ for MPI, it goes to run in core_1 (process 1) + Ptr node2 = CreateObject (1); // <------ for MPI, " _2 2 + nodes.Add (node1); + nodes.Add (node2); + + InternetStackHelper stack; + stack.Install (nodes); + + PointToPointHelper pointToPoint; + pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("100Mbps")); + pointToPoint.SetChannelAttribute ("Delay", StringValue ("1ms")); + + NetDeviceContainer devices; + devices = pointToPoint.Install (nodes); + + Ipv4AddressHelper address; + address.SetBase ("10.1.1.0", "255.255.255.252"); + Ipv4InterfaceContainer interfaces = address.Assign (devices); + + // setup ip routes + Ipv4GlobalRoutingHelper::PopulateRoutingTables (); + + DceManagerHelper dceManager; + dceManager.Install (nodes); + + DceApplicationHelper dce; + ApplicationContainer apps; + + dce.SetStackSize (1<<20); + + if (0==systemId) + { + dce.SetBinary ("udp-server"); + dce.ResetArguments(); + apps = dce.Install (node1); + apps.Start (Seconds (4.0)); + } + + if (1==systemId) + { + dce.SetBinary ("udp-client"); + dce.ResetArguments(); + dce.AddArgument ("10.1.1.1"); + apps = dce.Install (node2); + apps.Start (Seconds (4.5)); + } + + + Simulator::Stop (Seconds(1050.0)); + Simulator::Run (); + Simulator::Destroy (); + + //------------------------------------------------- + + // Exit the MPI execution environment + MpiInterface::Disable (); + return 0; + +} diff -r 4c90fdff71a0 myscripts/dce-mpi-udp/wscript --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myscripts/dce-mpi-udp/wscript Tue Jul 31 15:30:02 2012 +0200 @@ -0,0 +1,15 @@ +## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- + +import ns3waf +import Options + +def configure(conf): + ns3waf.check_modules(conf, ['core', 'internet', 'point-to-point', 'mpi'], mandatory = True) + +def build(bld): + if bld.env['MPI']: + bld.build_a_script('dce', needed = ['core', 'internet', 'dce', 'point-to-point', 'mpi'], + target='bin/dce-mpi-udp', + source=['dce-mpi-udp.cc'], + ) + diff -r 4c90fdff71a0 myscripts/ping/dce-ping.cc --- a/myscripts/ping/dce-ping.cc Mon Jul 16 13:56:16 2012 +0200 +++ b/myscripts/ping/dce-ping.cc Tue Jul 31 15:30:02 2012 +0200 @@ -8,6 +8,10 @@ #include "ns3/constant-position-mobility-model.h" #include "misc-tools.h" +#ifdef DCE_MPI +#include "ns3/mpi-interface.h" +#endif + using namespace ns3; // =========================================================================== @@ -32,6 +36,17 @@ // =========================================================================== int main (int argc, char *argv[]) { + uint32_t systemId = 0; + uint32_t systemCount = 1; +#ifdef DCE_MPI + // Distributed simulation setup + MpiInterface::Enable (&argc, &argv); + GlobalValue::Bind ("SimulatorImplementationType", + StringValue ("ns3::DistributedSimulatorImpl")); + systemId = MpiInterface::GetSystemId (); + systemCount = MpiInterface::GetSize (); +#endif + std::string animFile = "NetAnim.xml"; bool useKernel = 0; CommandLine cmd; @@ -39,7 +54,10 @@ cmd.Parse (argc, argv); NodeContainer nodes; - nodes.Create (2); + Ptr node1 = CreateObject (0 % systemCount); // Create node1 with system id 0 + Ptr node2 = CreateObject (1 % systemCount); // Create node2 with system id 1 + nodes.Add (node1); + nodes.Add (node2); PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); @@ -81,27 +99,32 @@ dce.SetStackSize (1<<20); - // Launch ping on node 0 - dce.SetBinary ("ping"); - dce.ResetArguments(); - dce.ResetEnvironment(); - dce.AddArgument ("-c 10"); - dce.AddArgument ("-s 1000"); - dce.AddArgument ("10.1.1.2"); + if ( systemId == node1->GetSystemId () ) + { + // Launch ping on node 0 + dce.SetBinary ("ping"); + dce.ResetArguments(); + dce.ResetEnvironment(); + dce.AddArgument ("-c 10"); + dce.AddArgument ("-s 1000"); + dce.AddArgument ("10.1.1.2"); - apps = dce.Install (nodes.Get (0)); - apps.Start (Seconds (1.0)); + apps = dce.Install (node1); + apps.Start (Seconds (1.0)); + } + if ( systemId == node2->GetSystemId ()) + { + // Launch ping on node 1 + dce.SetBinary ("ping"); + dce.ResetArguments(); + dce.ResetEnvironment(); + dce.AddArgument ("-c 10"); + dce.AddArgument ("-s 1000"); + dce.AddArgument ("10.1.1.1"); - // Launch ping on node 1 - dce.SetBinary ("ping"); - dce.ResetArguments(); - dce.ResetEnvironment(); - dce.AddArgument ("-c 10"); - dce.AddArgument ("-s 1000"); - dce.AddArgument ("10.1.1.1"); - - apps = dce.Install (nodes.Get (1)); - apps.Start (Seconds (1.5)); + apps = dce.Install (node2); + apps.Start (Seconds (1.5)); + } setPos (nodes.Get (0), 1, 10, 0); setPos (nodes.Get (1), 50,10, 0); @@ -117,6 +140,9 @@ Simulator::Destroy (); anim.StopAnimation (); +#ifdef DCE_MPI + MpiInterface::Disable (); +#endif return 0; } diff -r 4c90fdff71a0 utils/clone_and_compile_ns3_dce.sh --- a/utils/clone_and_compile_ns3_dce.sh Mon Jul 16 13:56:16 2012 +0200 +++ b/utils/clone_and_compile_ns3_dce.sh Tue Jul 31 15:30:02 2012 +0200 @@ -2,6 +2,7 @@ # this script checkout NS3 and DCE sources, and build them. USE_KERNEL=NO USE_VDL=NO +USE_MPI=NO WAF_VDL= args=("$@") NB=$# @@ -15,6 +16,11 @@ then USE_VDL=YES fi + if [ ${args[${i}]} = '-m' ] + then + USE_MPI=YES + MPI_SWITCH=--enable-mpi + fi done for i in patch hg make $WGET tar do @@ -46,7 +52,7 @@ hg revert -a patch -p1 <../ns-3-dce/utils/packet-socket-upgrade-exp.patch patch -p1 <../ns-3-dce/utils/remove-default-simulator-asserts.patch -./waf configure --prefix=`pwd`/../build --enable-tests +./waf configure --prefix=`pwd`/../build --enable-tests $MPI_SWITCH ./waf ./waf install cd .. @@ -93,7 +99,7 @@ then WAF_KERNEL=--enable-kernel-stack=`pwd`/../ns-3-linux fi -./waf configure --prefix=`pwd`/../build --verbose $WAF_KERNEL $WAF_VDL +./waf configure --prefix=`pwd`/../build --verbose $WAF_KERNEL $WAF_VDL $MPI_SWITCH ./waf ./waf install export LD_LIBRARY_PATH=$SAVE_LDLP:`pwd`/build/lib:`pwd`/build/bin:`pwd`/../build/lib diff -r 4c90fdff71a0 wscript --- a/wscript Mon Jul 16 13:56:16 2012 +0200 +++ b/wscript Tue Jul 31 15:30:02 2012 +0200 @@ -18,7 +18,11 @@ help=('Enable the build of dce-runner.'), dest='enable_vdl_loader', action='store_true', default=False) - + opt.add_option('--enable-mpi', + help=('Enable MPI and distributed simulation support'), + dest='enable_mpi', action='store_true', + default=False) + def search_file(files): for f in files: if os.path.isfile (f): @@ -30,6 +34,7 @@ ns3waf.check_modules(conf, ['point-to-point', 'tap-bridge', 'netanim'], mandatory = False) ns3waf.check_modules(conf, ['wifi', 'point-to-point', 'csma', 'mobility'], mandatory = False) ns3waf.check_modules(conf, ['point-to-point-layout'], mandatory = False) + ns3waf.check_modules(conf, ['mpi'], mandatory = False) conf.check_tool('compiler_cc') conf.check(header_name='stdint.h', define_name='HAVE_STDINT_H', mandatory=False) conf.check(header_name='inttypes.h', define_name='HAVE_INTTYPES_H', mandatory=False) @@ -38,6 +43,10 @@ conf.check(header_name='sys/stat.h', define_name='HAVE_SYS_STAT_H', mandatory=False) conf.check(header_name='dirent.h', define_name='HAVE_DIRENT_H', mandatory=False) + if Options.options.enable_mpi: + conf.env.append_value ('DEFINES', 'DCE_MPI=1') + conf.env['MPI'] = '1' + conf.env.prepend_value('LINKFLAGS', '-Wl,--no-as-needed') conf.env.append_value('LINKFLAGS', '-pthread') conf.check (lib='dl', mandatory = True)